├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── ReactNative ├── RecyclerList │ └── RnRecyclerView.js ├── index.android.js └── package.json ├── Screenshot.png ├── app-debug.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── yf │ │ └── rnlist │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── yf │ │ │ └── rnlist │ │ │ ├── MainActivity.java │ │ │ ├── RnListPackage.java │ │ │ ├── RnRecyclerEventHelper.java │ │ │ ├── RnRecyclerView.java │ │ │ └── RnRecyclerViewManager.java │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── yf │ └── rnlist │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── rn-source.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | RnList -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RN-RecyclerView 2 | 实现了可以UI复用的react native listview,解决RN本身listview的性能问题, 可以下拉刷新,上拉加载更多。 3 | ##项目配置 4 | 请在项目中的ReactNative文件夹里面放入RN模块,即平时初始化项目生成的node_modules,然后在node_modules\react-native\ReactAndroid目录放入
5 | ReactNative的源码,这里使用的时0.31版本的源码,最后目录结构如下图 6 | ![image](https://github.com/iceskyblue/RN-RecyclerView/blob/master/rn-source.png) 7 | ##项目运行 8 | [可以直接下载app-debug.apk](https://github.com/iceskyblue/RN-RecyclerView/blob/master/app-debug.apk),在pc上配置好你的react环境,拷贝index.android.js 和文件夹RecyclerList到react环境,执行react-native start,然后打开apk
设置服务器地址。
9 | 示例程序见:ReactNative/index.android.js 10 | ##运行截图 11 | ![image](https://github.com/iceskyblue/RN-RecyclerView/blob/master/Screenshot.png) 12 | ##实现思路 13 | http://blog.csdn.net/skyblue126/article/details/52062654 14 | -------------------------------------------------------------------------------- /ReactNative/RecyclerList/RnRecyclerView.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import React, { Component } from 'react'; 4 | import { 5 | AppRegistry, 6 | AndroidToast, 7 | requireNativeComponent, 8 | View, 9 | PropTypes, 10 | Text, 11 | DeviceEventEmitter 12 | } from 'react-native'; 13 | var cloneReferencedElement = require('react-clone-referenced-element'); 14 | var StaticRenderer = require('StaticRenderer'); 15 | var StyleSheetPropType = require('StyleSheetPropType'); 16 | var ViewStylePropTypes = require('ViewStylePropTypes'); 17 | 18 | class RnRecyclerView extends React.Component{ 19 | constructor(props) { 20 | super(props); 21 | this._needViews = this._needViews.bind(this); 22 | this._endReached = this._endReached.bind(this); 23 | } 24 | 25 | componentDidMount(){ 26 | DeviceEventEmitter.addListener( 27 | 'need_views', 28 | this._needViews); 29 | DeviceEventEmitter.addListener( 30 | 'end_reached', 31 | this._endReached); 32 | } 33 | 34 | _needViews(e:Event){ 35 | if(this.props.needViews){ 36 | this.props.needViews(e); 37 | } 38 | } 39 | 40 | _endReached(e:Event){ 41 | if(this.props.endReached){ 42 | this.props.endReached(); 43 | } 44 | } 45 | 46 | shouldComponentUpdate(nextProps, nextState) { 47 | return false; 48 | } 49 | 50 | render(){ 51 | var children = []; 52 | 53 | //genar children 54 | if(this.props.renderTypeView){ 55 | var views = this.props.childViewCount; 56 | for(var ii=0; ii 61 | children.push(row); 62 | } 63 | } 64 | return cloneReferencedElement(, {}, children); 75 | } 76 | } 77 | 78 | RnRecyclerView.propTypes= { 79 | ...View.propTypes, 80 | needViews: React.PropTypes.func, 81 | endReached: React.PropTypes.func, 82 | renderTypeView: React.PropTypes.func.isRequired, 83 | emptyViewHeight: React.PropTypes.number, 84 | childViewCount: React.PropTypes.number, 85 | itemClickable: React.PropTypes.bool, 86 | viewTypesMap: React.PropTypes.object, 87 | style:StyleSheetPropType(ViewStylePropTypes) 88 | }; 89 | 90 | var NativeRnRecyclerView = requireNativeComponent('RnRecyclerView', RnRecyclerView, {nativeOnly: {onChange:true}}); 91 | module.exports = RnRecyclerView; 92 | -------------------------------------------------------------------------------- /ReactNative/index.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | */ 5 | 6 | import React, { Component } from 'react'; 7 | import { 8 | AppRegistry, 9 | StyleSheet, 10 | Text, 11 | View, 12 | Image, 13 | NativeModules, 14 | DeviceEventEmitter, 15 | RefreshControl, 16 | PixelRatio 17 | } from 'react-native'; 18 | 19 | var ReactNative = require('ReactNative'); 20 | import RnRecycleView from './RecyclerList/RnRecyclerView.js'; 21 | 22 | 23 | var dataSet = []; 24 | 25 | 26 | var rowMap={"0":[0],"1":[1]}; //view类型,一共两种,第0种类型对应第0个view,第一种类型对应第1个view 27 | 28 | 29 | class RecyclerList extends Component { 30 | constructor(props) { 31 | super(props); 32 | this.state = {isRefreshing:false}; 33 | this._itemClicked = this._itemClicked.bind(this); 34 | DeviceEventEmitter.addListener( 35 | 'item_clicked', 36 | this._itemClicked); 37 | this._onRefresh = this._onRefresh.bind(this); 38 | this._endReached = this._endReached.bind(this); 39 | 40 | } 41 | 42 | _itemClicked(e:Event){ 43 | alert("click:"+e.position); 44 | } 45 | 46 | _endReached(){ 47 | alert("endReached add 10 rows data"); 48 | var extData = []; 49 | 50 | for(ii=0; ii<10; ii++){ 51 | if(ii%2 === 0){ 52 | //使用0类型的view 53 | extData.push({'viewType':0, 'img':'http://facebook.github.io/react/img/logo_og.png', 'data':'ext data row'+ii}); 54 | }else{ 55 | //使用1类型的view, 其中data对应的TextView还支持html标签哦。 56 | extData.push({'viewType':1, 'img':'http://facebook.github.io/react/img/logo_og.png', 'data':"ext data row"+ii+""}); 57 | } 58 | 59 | } 60 | 61 | //给RecyclerView添加数据, 命令3表示添加数据 62 | NativeModules.UIManager.dispatchViewManagerCommand( ReactNative.findNodeHandle(this.refs.recycle), 3, extData); 63 | } 64 | 65 | _onRefresh(){ 66 | 67 | this.setState({isRefreshing: true}); 68 | 69 | setTimeout(function(){ 70 | isRefreshing = false; 71 | this.setState({isRefreshing: false}); 72 | }.bind(this), 3000); 73 | } 74 | 75 | componentDidMount(){ 76 | //构造数据 77 | for(ii=0; ii<100; ii++){ 78 | if(ii%2 === 0){ 79 | //使用0类型的view 80 | dataSet.push({'viewType':0, 'img':'http://facebook.github.io/react/img/logo_og.png', 'data':'row'+ii}); 81 | }else{ 82 | //使用1类型的view, 其中data对应的TextView还支持html标签哦。 83 | dataSet.push({'viewType':1, 'img':'http://facebook.github.io/react/img/logo_og.png', 'data':"row"+ii+""}); 84 | } 85 | 86 | } 87 | //设置数据给RecyclerView, 命令2表示设置数据 88 | NativeModules.UIManager.dispatchViewManagerCommand( ReactNative.findNodeHandle(this.refs.recycle), 2, dataSet); 89 | //同时滚动到第5行, 命令1表示滚动到某一行 90 | NativeModules.UIManager.dispatchViewManagerCommand( ReactNative.findNodeHandle(this.refs.recycle), 1, [5]); 91 | } 92 | 93 | 94 | _renderRow(index) { 95 | //创建type为0的view, 图片在左 96 | if(index == 0){ 97 | return ( 98 | 99 | 100 | 101 | 102 | aaaaaaaaaa 103 | 104 | 105 | ); 106 | }else if(index == 1){ 107 | //创建viewType为1的view, 图片在右 108 | return ( 109 | 110 | 111 | 112 | aaaaaaaaaa 113 | 114 | 115 | 116 | ); 117 | } 118 | 119 | 120 | } 121 | 122 | render(){ 123 | return ( 126 | 133 | 134 | ); 135 | } 136 | } 137 | 138 | 139 | 140 | AppRegistry.registerComponent('test', () => RecyclerList); 141 | -------------------------------------------------------------------------------- /ReactNative/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tt", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node node_modules/react-native/local-cli/cli.js start" 7 | }, 8 | "dependencies": { 9 | "react": "^15.1.0", 10 | "react-native": "^0.27.0" 11 | }, 12 | "description": "test", 13 | "main": "index.android.js", 14 | "author": "", 15 | "license": "ISC", 16 | "devDependencies": {} 17 | } 18 | -------------------------------------------------------------------------------- /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/Screenshot.png -------------------------------------------------------------------------------- /app-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/app-debug.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.example.yf.rnlist" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | ndk { 15 | abiFilters "armeabi" 16 | } 17 | splits{ 18 | abi{ 19 | reset() 20 | enable true 21 | universalApk false // If true, also generate a universal APK 22 | include "armeabi" 23 | } 24 | } 25 | } 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | } 33 | 34 | dependencies { 35 | compile fileTree(dir: 'libs', include: ['*.jar']) 36 | testCompile 'junit:junit:4.12' 37 | compile 'com.android.support:appcompat-v7:23.0.1' 38 | compile 'com.android.support:support-v4:23.0.1' 39 | compile project(':ReactNative') 40 | } 41 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\AndroidDEV\android-sdk-windows_r22/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/yf/rnlist/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.yf.rnlist; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yf/rnlist/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.yf.rnlist; 2 | 3 | import android.app.Application; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.ViewGroup; 7 | import android.widget.RelativeLayout; 8 | 9 | import com.facebook.react.LifecycleState; 10 | import com.facebook.react.ReactInstanceManager; 11 | import com.facebook.react.ReactRootView; 12 | import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; 13 | import com.facebook.react.shell.MainReactPackage; 14 | 15 | public class MainActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler { 16 | 17 | private ReactRootView mReactRootView; 18 | private ReactInstanceManager mReactInstanceManager; 19 | protected RnListPackage mPackage; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | mReactRootView = new ReactRootView(this); 26 | initRn(getApplication()); 27 | mReactRootView.startReactApplication(mReactInstanceManager, "test", null); 28 | RelativeLayout parent = (RelativeLayout)this.findViewById(R.id.root); 29 | parent.addView(mReactRootView, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 30 | } 31 | 32 | 33 | 34 | public void initRn(Application application){ 35 | mPackage = new RnListPackage(); 36 | mReactInstanceManager = ReactInstanceManager.builder() 37 | .setApplication(application) 38 | .setBundleAssetName("index.android.bundle") 39 | .setJSMainModuleName("index.android") 40 | .setUseDeveloperSupport(true) 41 | .addPackage(new MainReactPackage()) 42 | .addPackage(mPackage) 43 | .setInitialLifecycleState(LifecycleState.RESUMED) 44 | .build(); 45 | mReactInstanceManager.createReactContextInBackground(); 46 | } 47 | 48 | @Override 49 | public void invokeDefaultOnBackPressed() { 50 | super.onBackPressed(); 51 | } 52 | 53 | @Override 54 | protected void onPause() { 55 | super.onPause(); 56 | 57 | if (mReactInstanceManager != null) { 58 | mReactInstanceManager.onHostPause(); 59 | } 60 | } 61 | 62 | @Override 63 | protected void onResume() { 64 | super.onResume(); 65 | 66 | if (mReactInstanceManager != null) { 67 | mReactInstanceManager.onHostResume(this, this); 68 | } 69 | } 70 | 71 | 72 | @Override 73 | protected void onDestroy() { 74 | super.onDestroy(); 75 | if(null != mReactRootView){ 76 | mReactRootView.unmountReactApplication(); 77 | } 78 | 79 | if (mReactInstanceManager != null) { 80 | mReactInstanceManager.detachRootView(mReactRootView); 81 | mReactInstanceManager.onHostDestroy(); 82 | mReactInstanceManager.destroy(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yf/rnlist/RnListPackage.java: -------------------------------------------------------------------------------- 1 | package com.example.yf.rnlist; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | 6 | import com.facebook.react.ReactPackage; 7 | import com.facebook.react.bridge.JavaScriptModule; 8 | import com.facebook.react.bridge.NativeModule; 9 | import com.facebook.react.bridge.ReactApplicationContext; 10 | import com.facebook.react.uimanager.ViewManager; 11 | import java.util.Arrays; 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by yf on 2016/6/1. 17 | */ 18 | public class RnListPackage implements ReactPackage { 19 | 20 | private RowSelectListener mRowSelectLisener; 21 | @Override 22 | public List createNativeModules(ReactApplicationContext reactContext) { 23 | return Collections.emptyList(); 24 | } 25 | 26 | public void setRowSelectListener(RowSelectListener listener) { 27 | this.mRowSelectLisener = listener; 28 | } 29 | 30 | @Override 31 | public List> createJSModules() { 32 | return Collections.emptyList(); 33 | } 34 | 35 | @Override 36 | public List createViewManagers(ReactApplicationContext reactContext) { 37 | return Arrays.asList( 38 | new RnRecyclerViewManager() 39 | ); 40 | } 41 | 42 | public interface RowSelectListener { 43 | public void rowSelected(int rowId); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yf/rnlist/RnRecyclerEventHelper.java: -------------------------------------------------------------------------------- 1 | package com.example.yf.rnlist; 2 | 3 | import com.facebook.react.bridge.Arguments; 4 | import com.facebook.react.bridge.WritableMap; 5 | import com.facebook.react.modules.core.DeviceEventManagerModule; 6 | import com.facebook.react.uimanager.ThemedReactContext; 7 | 8 | /** 9 | * Created by yf on 2016/6/17. 10 | */ 11 | public class RnRecyclerEventHelper { 12 | 13 | private ThemedReactContext mCtx; 14 | 15 | public RnRecyclerEventHelper(ThemedReactContext ctx){ 16 | this.mCtx = ctx; 17 | } 18 | 19 | public void sendNeedViewEvent(int type){ 20 | WritableMap params = Arguments.createMap(); 21 | params.putInt("viewType", type); 22 | mCtx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 23 | .emit("need_views", params); 24 | } 25 | 26 | public void sendReachEndEvent(){ 27 | mCtx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 28 | .emit("end_reached", null); 29 | } 30 | 31 | public void sendItemClickEvent(int position){ 32 | WritableMap params = Arguments.createMap(); 33 | params.putInt("position", position); 34 | mCtx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 35 | .emit("item_clicked", params); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yf/rnlist/RnRecyclerView.java: -------------------------------------------------------------------------------- 1 | package com.example.yf.rnlist; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.view.ViewCompat; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.text.Html; 9 | import android.text.Spannable; 10 | import android.text.SpannableStringBuilder; 11 | import android.text.Spanned; 12 | import android.text.SpannedString; 13 | import android.util.AttributeSet; 14 | import android.util.SparseIntArray; 15 | import android.view.MotionEvent; 16 | import android.view.View; 17 | import android.view.ViewConfiguration; 18 | import android.view.ViewGroup; 19 | import android.view.ViewParent; 20 | import android.widget.ImageView; 21 | import android.widget.LinearLayout; 22 | 23 | import com.facebook.drawee.drawable.ScalingUtils; 24 | import com.facebook.react.bridge.JavaOnlyArray; 25 | import com.facebook.react.bridge.JavaOnlyMap; 26 | import com.facebook.react.bridge.ReadableArray; 27 | import com.facebook.react.bridge.ReadableMap; 28 | import com.facebook.react.bridge.ReadableMapKeySetIterator; 29 | import com.facebook.react.touch.OnInterceptTouchEventListener; 30 | import com.facebook.react.uimanager.MeasureSpecAssertions; 31 | import com.facebook.react.uimanager.ThemedReactContext; 32 | import com.facebook.react.uimanager.UIImplementation; 33 | import com.facebook.react.uimanager.UIManagerModule; 34 | import com.facebook.react.views.image.ReactImageManager; 35 | import com.facebook.react.views.image.ReactImageView; 36 | import com.facebook.react.views.imagehelper.ImageSource; 37 | import com.facebook.react.views.text.ReactTextView; 38 | import com.facebook.react.views.view.ReactViewGroup; 39 | 40 | import org.json.JSONArray; 41 | import org.json.JSONException; 42 | import org.json.JSONObject; 43 | 44 | import java.lang.reflect.Field; 45 | import java.lang.reflect.Method; 46 | import java.util.Enumeration; 47 | import java.util.Hashtable; 48 | import java.util.Iterator; 49 | import java.util.LinkedList; 50 | import java.util.List; 51 | import java.util.Vector; 52 | 53 | /** 54 | * Created by yf on 2016/6/15. 55 | */ 56 | public class RnRecyclerView extends RecyclerView { 57 | 58 | private Hashtable> mTypeOfViews; 59 | private JSONArray mData; 60 | private int mEmptyViewHeight = 20; 61 | private RnListAdapter mAdapter; 62 | private SparseIntArray mViewTypeMap; 63 | private boolean mItemClickable = false; 64 | private RnRecyclerEventHelper mEventHelper; 65 | private ThemedReactContext mRnContext; 66 | 67 | public RnRecyclerView(ThemedReactContext context) { 68 | super(context); 69 | init(context); 70 | 71 | } 72 | 73 | public RnRecyclerView(ThemedReactContext context, @Nullable AttributeSet attrs) { 74 | super(context, attrs); 75 | init(context); 76 | } 77 | 78 | public void setEmptyViewHeight(int height){ 79 | this.mEmptyViewHeight = height; 80 | } 81 | 82 | public RnRecyclerView(ThemedReactContext context, @Nullable AttributeSet attrs, int defStyle) { 83 | super(context, attrs, defStyle); 84 | init(context); 85 | } 86 | 87 | private void init(ThemedReactContext ctx){ 88 | this.mRnContext = ctx; 89 | this.mEventHelper = new RnRecyclerEventHelper(ctx); 90 | this.mTypeOfViews = new Hashtable>(); 91 | this.mData = new JSONArray(); 92 | this.mViewTypeMap = new SparseIntArray(); 93 | LinearLayoutManager llm = new LinearLayoutManager(ctx); 94 | llm.setRecycleChildrenOnDetach(true); 95 | setLayoutManager(llm); 96 | this.setHasFixedSize(true); 97 | this.mAdapter = new RnListAdapter(); 98 | this.setItemViewCacheSize(0); 99 | this.getRecycledViewPool().setMaxRecycledViews(0, 0); 100 | 101 | setAdapter(this.mAdapter); 102 | this.addOnScrollListener(new OnScrollListener() { 103 | @Override 104 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 105 | super.onScrollStateChanged(recyclerView, newState); 106 | } 107 | 108 | @Override 109 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 110 | super.onScrolled(recyclerView, dx, dy); 111 | if(!ViewCompat.canScrollVertically(recyclerView, 1)){ 112 | mEventHelper.sendReachEndEvent(); 113 | } 114 | } 115 | }); 116 | } 117 | 118 | public synchronized void addViewType(View v, int index){ 119 | if(null != v.getParent()){ 120 | return; 121 | } 122 | int type = mViewTypeMap.get(index, 0); 123 | Vector typeViews = this.mTypeOfViews.get(type); 124 | if(null == typeViews){ 125 | typeViews = new Vector<>(); 126 | this.mTypeOfViews.put(type, typeViews); 127 | } 128 | 129 | if(!typeViews.contains(v)){ 130 | typeViews.add(v); 131 | } 132 | } 133 | 134 | public synchronized void recyclerViewType(View v, int type){ 135 | Vector typeViews = this.mTypeOfViews.get(type); 136 | if(null != typeViews && (!typeViews.contains(v))) 137 | typeViews.add(v); 138 | } 139 | 140 | private ReactViewGroup cloneView(ReactViewGroup view, ThemedReactContext ctx){ 141 | ReactViewGroup root = new ReactViewGroup(ctx); 142 | root.measure(MeasureSpec.makeMeasureSpec(view.getMeasuredWidth(),MeasureSpec.EXACTLY), 143 | MeasureSpec.makeMeasureSpec(view.getMeasuredHeight(),MeasureSpec.EXACTLY)); 144 | root.setBackgroundColor(view.getBackgroundColor()); 145 | int childCount = view.getChildCount(); 146 | for(int i=0 ; i source = (List)imgSource.get(child); 198 | List copySource = new LinkedList<>(); 199 | String imageName = null; 200 | for(ImageSource item : source){ 201 | ImageSource newSource = new ImageSource(null, null); 202 | Field uriF = ImageSource.class.getDeclaredField("mUri"); 203 | Field sourceF = ImageSource.class.getDeclaredField("mSource"); 204 | Field sizeF = ImageSource.class.getDeclaredField("mSize"); 205 | Field resourceF = ImageSource.class.getDeclaredField("isResource"); 206 | uriF.setAccessible(true); 207 | sourceF.setAccessible(true); 208 | sizeF.setAccessible(true); 209 | resourceF.setAccessible(true); 210 | 211 | uriF.set(newSource, item.getUri()); 212 | sourceF.set(newSource, item.getSource()); 213 | sizeF.setDouble(newSource, item.getSize()); 214 | resourceF.setBoolean(newSource, item.isResource()); 215 | 216 | copySource.add(newSource); 217 | if(null == imageName){ 218 | imageName = item.getSource(); 219 | } 220 | } 221 | Field newSource = copyChild.getClass().getDeclaredField("mSources"); 222 | newSource.setAccessible(true); 223 | newSource.set(copyChild,copySource); 224 | Field dirty = copyChild.getClass().getDeclaredField("mIsDirty"); 225 | dirty.setAccessible(true); 226 | dirty.setBoolean(copyChild, true); 227 | if(null != imageName && copyDrawable(imageName) > 0){ 228 | copyChild.setScaleType(ImageView.ScaleType.FIT_XY); 229 | copyChild.setImageResource(copyDrawable(imageName)); 230 | 231 | }else{ 232 | copyChild.maybeUpdateView(); 233 | } 234 | 235 | } catch (Exception e) { 236 | e.printStackTrace(); 237 | } 238 | 239 | } 240 | } 241 | return root; 242 | } 243 | 244 | private int copyDrawable(String name){ 245 | int resId = getResources().getIdentifier(name, "drawable", getContext().getApplicationContext().getPackageName()); 246 | return resId; 247 | } 248 | 249 | public void setItemClickable(boolean clickable){ 250 | this.mItemClickable = clickable; 251 | } 252 | 253 | public boolean setData(String jsonData){ 254 | this.mData = new JSONArray(); 255 | 256 | boolean res = this.addData(jsonData); 257 | this.scrollPosition(0); 258 | return res; 259 | } 260 | 261 | public void setData(ReadableArray data){ 262 | if(null != data){ 263 | this.setData(data.toString()); 264 | } 265 | } 266 | 267 | public void addData(ReadableArray data){ 268 | if(null != data){ 269 | this.addData(data.toString()); 270 | } 271 | } 272 | 273 | 274 | public boolean addData(String jsonData){ 275 | boolean res = false; 276 | try { 277 | JSONArray data = new JSONArray(jsonData); 278 | int length = null==data ? 0 : data.length(); 279 | for(int i=0; i> em = mTypeOfViews.elements(); 323 | while(em.hasMoreElements()){ 324 | em.nextElement().clear(); 325 | } 326 | 327 | mTypeOfViews.clear(); 328 | } 329 | super.onDetachedFromWindow(); 330 | } 331 | 332 | public void setTypesMap(ReadableMap map){ 333 | ReadableMapKeySetIterator iter = map.keySetIterator(); 334 | while(iter.hasNextKey()){ 335 | String type = iter.nextKey(); 336 | int typeInt = 0; 337 | try{ 338 | typeInt = Integer.valueOf(type); 339 | this.getRecycledViewPool().setMaxRecycledViews(typeInt, 0); 340 | }catch (Exception e){ 341 | e.printStackTrace(); 342 | } 343 | ReadableArray indexs = map.getArray(type); 344 | for(int i=0; i { 357 | 358 | 359 | @Override 360 | public RnViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 361 | Vector views = mTypeOfViews.get(viewType); 362 | View v = null; 363 | if(views.size() == 0){ 364 | v = new EmptyView(getContext()); 365 | v.setMinimumHeight(mEmptyViewHeight); 366 | }else{ 367 | View child = null; 368 | if(views.size() > 1){ 369 | child = views.remove(0); 370 | }else{ 371 | child = cloneView((ReactViewGroup) views.get(0), mRnContext); 372 | } 373 | 374 | if(null == child.getLayoutParams()){ 375 | int measureH = child.getMeasuredHeight(); 376 | child.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, measureH)); 377 | } 378 | v = child; 379 | } 380 | 381 | RnViewHolder holder = new RnViewHolder(v, viewType, mItemClickable); 382 | if(null != holder.clickListener){ 383 | holder.clickListener.eventHelper = mEventHelper; 384 | } 385 | return holder; 386 | } 387 | 388 | @Override 389 | public void onBindViewHolder(RnViewHolder holder, int position) { 390 | if(holder.itemView instanceof EmptyView){ 391 | return; 392 | } 393 | 394 | if(null != holder.clickListener){ 395 | holder.clickListener.position = position; 396 | } 397 | 398 | View v = holder.itemView; 399 | ReactViewGroup rvg = (ReactViewGroup)v; 400 | rvg.invalidate(); 401 | try { 402 | JSONObject data = mData.getJSONObject(position); 403 | 404 | Iterator iter = data.keys(); 405 | while (iter.hasNext()){ 406 | String key = iter.next(); 407 | View child = v.findViewWithTag(key); 408 | if(key.startsWith("__")){ 409 | child = v.findViewWithTag(key.substring(2)); 410 | if(null != child){ 411 | int isVisible = data.optInt(key, View.VISIBLE); 412 | switch (isVisible){ 413 | case View.VISIBLE: 414 | child.setVisibility(View.VISIBLE); 415 | break; 416 | case View.GONE: 417 | child.setVisibility(View.GONE); 418 | break; 419 | case View.INVISIBLE: 420 | child.setVisibility(View.INVISIBLE); 421 | break; 422 | } 423 | 424 | } 425 | continue; 426 | } 427 | if(child instanceof ReactTextView){ 428 | ReactTextView txt = ((ReactTextView)child); 429 | String str = data.optString(key); 430 | Spanned newStr = null; 431 | if(str.indexOf("") >= 0){ 432 | newStr = Html.fromHtml(str); 433 | }else{ 434 | newStr = copySpanned(data.optString(key),(SpannedString)txt.getText()); 435 | } 436 | txt.setText(newStr); 437 | 438 | float w = txt.getPaint().measureText(newStr, 0, newStr.length()); 439 | updateRightBrotherLocation(child, (int)(w + 0.5f + child.getPaddingRight() + child.getPaddingLeft())); 440 | }else if(child instanceof ReactImageView){ 441 | JavaOnlyArray source = new JavaOnlyArray(); 442 | JavaOnlyMap map = new JavaOnlyMap(); 443 | map.putString("uri", data.optString(key)); 444 | source.pushMap(map); 445 | ((ReactImageView)child).setSource(source); 446 | ((ReactImageView)child).maybeUpdateView(); 447 | 448 | } 449 | } 450 | } catch (JSONException e) { 451 | e.printStackTrace(); 452 | } 453 | } 454 | 455 | private Spannable copySpanned(String dst, SpannedString src){ 456 | SpannableStringBuilder ss = new SpannableStringBuilder(dst); 457 | Object[] spanneds = src.getSpans(0, src.length(), Object.class); 458 | for(Object obj : spanneds){ 459 | ss.setSpan(obj, 0, dst.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); 460 | } 461 | 462 | return ss; 463 | } 464 | 465 | private void updateRightBrotherLocation(View view, int newWidth){ 466 | ViewParent parent = view.getParent(); 467 | if(null == parent){ 468 | return; 469 | } 470 | 471 | int offset = newWidth - view.getWidth(); 472 | boolean findBrother = false; 473 | ViewGroup vg = ((ViewGroup)parent); 474 | View brother = null; 475 | for(int i=0; i=view.getTop()&&child.getTop()view.getTop())){ 479 | brother = child; 480 | break; 481 | } 482 | if(view == child){ 483 | findBrother = true; 484 | } 485 | } 486 | 487 | if(null != brother){ 488 | brother.layout(brother.getLeft()+offset, brother.getTop(), brother.getRight()+offset, brother.getBottom()); 489 | view.layout(view.getLeft(), view.getTop(), view.getLeft()+newWidth, view.getBottom()); 490 | }else if(offset > 0){ 491 | view.layout(view.getLeft(), view.getTop(), view.getLeft()+newWidth, view.getBottom()); 492 | } 493 | 494 | } 495 | 496 | 497 | @Override 498 | public int getItemCount() { 499 | return null==mData? 0 : mData.length(); 500 | } 501 | 502 | @Override 503 | public int getItemViewType(int position) { 504 | int type = 0; 505 | try { 506 | JSONObject itemData = mData.getJSONObject(position); 507 | type = itemData.optInt("viewType"); 508 | } catch (JSONException e) { 509 | e.printStackTrace(); 510 | } 511 | 512 | return type; 513 | } 514 | 515 | @Override 516 | public void onViewRecycled(RnViewHolder holder) { 517 | super.onViewRecycled(holder); 518 | if(holder.itemView instanceof EmptyView){ 519 | return; 520 | } 521 | 522 | ((ViewGroup) holder.itemView).removeView(holder.itemView); 523 | 524 | recyclerViewType(holder.itemView, holder.viewType); 525 | 526 | } 527 | } 528 | 529 | 530 | private static class RnViewHolder extends ViewHolder{ 531 | public int viewType = -1; 532 | public boolean clickable; 533 | public OnItemTouchListener clickListener; 534 | public RnViewHolder(View itemView, int type, boolean clickable) { 535 | super(itemView); 536 | this.clickable = clickable; 537 | this.viewType = type; 538 | if(this.clickable && itemView instanceof ReactViewGroup){ 539 | clickListener = new OnItemTouchListener(); 540 | ((ReactViewGroup)itemView).setOnInterceptTouchEventListener(clickListener); 541 | } 542 | } 543 | } 544 | 545 | private static class EmptyView extends View{ 546 | public EmptyView(Context context) { 547 | super(context); 548 | } 549 | } 550 | 551 | private static class OnItemTouchListener implements OnInterceptTouchEventListener{ 552 | 553 | public int position = -1; 554 | public long pressDownTime; 555 | public RnRecyclerEventHelper eventHelper; 556 | @Override 557 | public boolean onInterceptTouchEvent(ViewGroup v, MotionEvent event) { 558 | switch(event.getAction()){ 559 | case MotionEvent.ACTION_DOWN: 560 | pressDownTime = event.getEventTime(); 561 | break; 562 | case MotionEvent.ACTION_UP: 563 | if(event.getEventTime() - pressDownTime <= ViewConfiguration.getTapTimeout()){ 564 | if(null != eventHelper){ 565 | eventHelper.sendItemClickEvent(position); 566 | } 567 | } 568 | break; 569 | } 570 | return false; 571 | } 572 | } 573 | } 574 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/yf/rnlist/RnRecyclerViewManager.java: -------------------------------------------------------------------------------- 1 | package com.example.yf.rnlist; 2 | 3 | import android.view.View; 4 | 5 | import com.facebook.react.bridge.ReadableArray; 6 | import com.facebook.react.bridge.ReadableMap; 7 | import com.facebook.react.uimanager.ThemedReactContext; 8 | import com.facebook.react.uimanager.ViewGroupManager; 9 | import com.facebook.react.uimanager.annotations.ReactProp; 10 | 11 | import javax.annotation.Nullable; 12 | 13 | /** 14 | * Created by yf on 2016/6/15. 15 | */ 16 | public class RnRecyclerViewManager extends 17 | ViewGroupManager { 18 | 19 | public static final String COMPNENT_NAME = "RnRecyclerView"; 20 | 21 | 22 | @Override 23 | public String getName() { 24 | return COMPNENT_NAME; 25 | } 26 | 27 | @Override 28 | protected RnRecyclerView createViewInstance(ThemedReactContext reactContext) { 29 | RnRecyclerView view = new RnRecyclerView(reactContext); 30 | return view; 31 | } 32 | 33 | @Override 34 | public void onDropViewInstance(RnRecyclerView view) { 35 | super.onDropViewInstance(view); 36 | } 37 | 38 | //index as the view type 39 | @Override 40 | public void addView(RnRecyclerView parent, View child, int index) { 41 | 42 | parent.addViewType(child, index); 43 | } 44 | 45 | 46 | @Override 47 | public View getChildAt(RnRecyclerView parent, int index) { 48 | return parent.getChildAt(index); 49 | } 50 | 51 | @Override 52 | public void removeViewAt(RnRecyclerView parent, int index) { 53 | parent.removeViewAt(index); 54 | } 55 | 56 | 57 | 58 | @ReactProp(name="emptyViewHeight") 59 | public void setEmptyViewHeight(RnRecyclerView parent, int height){ 60 | parent.setEmptyViewHeight(height); 61 | } 62 | 63 | @ReactProp(name="viewTypesMap") 64 | public void setViewTypesMap(RnRecyclerView parent, ReadableMap map){ 65 | parent.setTypesMap(map); 66 | } 67 | 68 | @ReactProp(name="itemClickable") 69 | public void setItemClickable(RnRecyclerView parent, boolean clickable){ 70 | parent.setItemClickable(clickable); 71 | } 72 | 73 | @Override 74 | public void receiveCommand(RnRecyclerView root, int commandId, @Nullable ReadableArray args) { 75 | if(commandId == 1 && args.size() > 0){ 76 | //scroll event 77 | root.scrollPosition(args.getInt(0)); 78 | }else if(commandId == 2){ 79 | //data change event 80 | root.setData(args); 81 | }else if(commandId == 3){ 82 | //add data 83 | root.addData(args); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RnList 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/yf/rnlist/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.yf.rnlist; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.0.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Fri Jul 29 14:23:14 CST 2016 16 | android.useDeprecatedNdk=true 17 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /rn-source.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceskyblue/RN-RecyclerView/0b1a70241f728442d53000e9447019cb83517a74/rn-source.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | include ':ReactNative' 3 | project(':ReactNative').projectDir = new File(rootProject.projectDir, './ReactNative/node_modules/react-native/ReactAndroid') 4 | --------------------------------------------------------------------------------