react-native-smart-image-loader
A smart asynchronous image downloader with cache for React Native apps. The library uses https://github.com/rs/SDWebImage for ios, and uses https://github.com/nostra13/Android-Universal-Image-Loader for android.
Preview
Installation
npm install react-native-smart-image-loader --save
Notice
It can only be used greater-than-equal react-native 0.4.0 for ios, if you want to use the package less-than react-native 0.4.0, use npm install react-native-smart-image-loader@untilRN0.40 --save
Installation (iOS)
-
Drag RCTImageLoader.xcodeproj to your project on Xcode.
-
Click on your main project file (the one that represents the .xcodeproj) select Build Phases and drag libRCTImageLoader.a from the Products folder inside the RCTImageLoader.xcodeproj.
-
Look for Header Search Paths and make sure it contains $(SRCROOT)/../../../react-native/React as recursive.
-
Dray ImageLoaderResources folder to your project. if you want change image, replace goods-placeholder.png, and you also can rename the image file
Installation (Android)
- In
android/settings.gradle
...
include ':react-native-smart-image-loader'
project(':react-native-smart-image-loader').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-smart-image-loader/android')
- In
android/app/build.gradle
...
dependencies {
...
// From node_modules
compile project(':react-native-smart-image-loader')
}
- in MainApplication.java
...
import com.reactnativecomponent.imageloader.RCTLoaderImageViewPackage; //import package
...
/**
* A list of packages used by the app. If the app uses additional views
* or modules besides the default ones, add more packages here.
*/
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RCTLoaderImageViewPackage() //register Module
);
}
...
Full Demo
Usage
Install the package from npm with npm install react-native-smart-image-loader --save
.
Then, require it from your app's JavaScript files with import ImageLoader from 'react-native-smart-image-loader'
.
let pageSize = 20let itemIndex = 0 // 构造 { superprops; this_dataSource = r1 !== r2 //sectionHeaderHasChanged: (s1, s2) => s1 !== s2, ; let dataList = thisstate = first: true dataList: dataList dataSource: this_dataSource this_refList = } { this_pullToRefreshListView } //Using ListView { return <PullToRefreshListView ref= this_pullToRefreshListView = component viewType=PullToRefreshListViewconstantsviewTypelistView contentContainerStyle=backgroundColor: 'yellow' style=marginTop: PlatformOS == 'ios' ? 64 : 56 initialListSize=100 enableEmptySections=true dataSource=thisstatedataSource pageSize=100 renderRow=this_renderRow //renderSeparator={(sectionID, rowID) => <View style={styles.separator} />} listItemProps=overflow: 'hidden' height: 150 renderHeader=this_renderHeader renderFooter=this_renderFooter onRefresh=this_onRefresh onLoadMore=this_onLoadMore autoLoadMore=true //onEndReachedThreshold={15} /> } { return <View style=flexDirection: 'row'> <ImageLoader style=width: 150 height: 150 options= rowID: rowID src: `http://o2o.doorto.cn/upload/yun-o2o/` placeholder: PlatformOS == 'ios' ? 'goods-placeholder' : 'goods_placeholder' /> <Text style=paddingHorizontal: 30 paddingVertical: 20 >rowID</Text> </View> } { let pullState pullDistancePercent = viewState let refresh_none refresh_idle will_refresh refreshing = PullToRefreshListViewconstantsviewState pullDistancePercent = Math } { let pullState pullDistancePercent = viewState let load_more_none load_more_idle will_load_more loading_more loaded_all = PullToRefreshListViewconstantsviewState pullDistancePercent = Math } { //console.log('outside _onRefresh start...') //simulate request data this } { //console.log('outside _onLoadMore start...') //simulate request data this } { return ActivityIndicator ? <ActivityIndicator style=marginRight: 10 animating=true color='#ff0000' size='small'/> : PlatformOS == 'android' ? <ProgressBarAndroid style=marginRight: 10 color='#ff0000' styleAttr='Small'/> : <ActivityIndicatorIOS style=marginRight: 10 animating=true color='#ff0000' size='small'/> } const styles = StyleSheet PullToRefreshListViewDemo
Props
Prop | Type | Optional | Default | Description |
---|---|---|---|---|
options | object | No | determines the options | |
options.src | number | No | determines the image uri | |
options.placeholder | number | Yes | determines the placeholder image uri | |
options.threadSize | number | Yes | 3 | determines the number of request thread(for android) |
options.fadeInDuration | number | Yes | 0 | determines the fadeIn animation duration(for android) |
options.rowID | string | Yes | determines the rowID for each listView's row, only used for test |