├── RNExample
├── .watchmanconfig
├── .gitattributes
├── index.js
├── .babelrc
├── app.json
├── android
│ ├── app
│ │ ├── src
│ │ │ └── main
│ │ │ │ ├── res
│ │ │ │ ├── values
│ │ │ │ │ ├── strings.xml
│ │ │ │ │ └── styles.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ └── mipmap-xxhdpi
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── rnexample
│ │ │ │ │ ├── MainActivity.java
│ │ │ │ │ └── MainApplication.java
│ │ │ │ └── AndroidManifest.xml
│ │ ├── BUCK
│ │ ├── proguard-rules.pro
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── keystores
│ │ ├── debug.keystore.properties
│ │ └── BUCK
│ ├── settings.gradle
│ ├── gradle.properties
│ ├── build.gradle
│ ├── gradlew.bat
│ └── gradlew
├── ios
│ ├── RNExample
│ │ ├── Images.xcassets
│ │ │ ├── Contents.json
│ │ │ └── AppIcon.appiconset
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.h
│ │ ├── main.m
│ │ ├── AppDelegate.m
│ │ ├── Info.plist
│ │ └── Base.lproj
│ │ │ └── LaunchScreen.xib
│ ├── RNExampleTests
│ │ ├── Info.plist
│ │ └── RNExampleTests.m
│ ├── RNExample-tvOSTests
│ │ └── Info.plist
│ ├── RNExample-tvOS
│ │ └── Info.plist
│ └── RNExample.xcodeproj
│ │ └── xcshareddata
│ │ └── xcschemes
│ │ ├── RNExample.xcscheme
│ │ └── RNExample-tvOS.xcscheme
├── .buckconfig
├── __tests__
│ └── App.js
├── .vscode
│ └── launch.json
├── src
│ ├── App.js
│ ├── RowTemplate.js
│ └── ListExample.js
├── package.json
├── .gitignore
└── .flowconfig
├── lib
├── android
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── src
│ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── sudoplz
│ │ │ └── rnsynchronouslistmanager
│ │ │ ├── Sync
│ │ │ ├── Instructions
│ │ │ │ ├── Instruction.java
│ │ │ │ ├── SetViewInstruction.java
│ │ │ │ └── CreateViewInstruction.java
│ │ │ ├── SyncRegistry.java
│ │ │ └── Recipe.java
│ │ │ ├── Utils
│ │ │ ├── FrameUtils.java
│ │ │ ├── SPGlobals.java
│ │ │ ├── WritableAdvancedMap.java
│ │ │ └── WritableAdvancedArray.java
│ │ │ ├── SynchronousListPackage.java
│ │ │ ├── SynchronousListModule.java
│ │ │ ├── SynchronousListManager.java
│ │ │ └── Views
│ │ │ ├── List
│ │ │ ├── SPAdapter.java
│ │ │ └── SPRecyclerView.java
│ │ │ └── SyncRootView.java
│ ├── build.gradle
│ ├── gradlew.bat
│ └── gradlew
├── ios
│ ├── RCTSynchronousListManager
│ │ ├── Sync
│ │ │ ├── RCCSyncRootView.h
│ │ │ ├── RCCSyncRegistry.h
│ │ │ ├── RCCSyncRegistry.m
│ │ │ └── RCCSyncRootView.m
│ │ ├── RCTSynchronousListManager.h
│ │ ├── Bind
│ │ │ ├── NoLoopBinder.h
│ │ │ ├── RepeatEdgeBinder.h
│ │ │ ├── RepeatEmptyBinder.h
│ │ │ ├── ScrollViewBindFactory.h
│ │ │ ├── ScrollViewBindFactory.m
│ │ │ ├── NoLoopBinder.m
│ │ │ ├── RepeatEmptyBinder.m
│ │ │ └── RepeatEdgeBinder.m
│ │ ├── RCTSynchronousList.h
│ │ └── RCTSynchronousListManager.m
│ └── RCTSynchronousListManager.xcodeproj
│ │ └── project.pbxproj
└── js
│ ├── components
│ └── SynchronousList.js
│ └── utils
│ └── SyncRegistry.js
├── jsconfig.json
├── index.js
├── .npmignore
├── RNKeychain.podspec
├── .gitignore
├── LICENSE
├── package.json
└── README.md
/RNExample/.watchmanconfig:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/RNExample/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/RNExample/index.js:
--------------------------------------------------------------------------------
1 | import App from './src/App';
--------------------------------------------------------------------------------
/RNExample/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": ["react-native"]
3 | }
4 |
--------------------------------------------------------------------------------
/RNExample/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "RNExample",
3 | "displayName": "RNExample"
4 | }
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RNExample
3 |
4 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample/Images.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/RNExample/.buckconfig:
--------------------------------------------------------------------------------
1 |
2 | [android]
3 | target = Google Inc.:Google APIs:23
4 |
5 | [maven_repositories]
6 | central = https://repo1.maven.org/maven2
7 |
--------------------------------------------------------------------------------
/lib/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SudoPlz/react-native-synchronous-list/HEAD/lib/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/RNExample/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SudoPlz/react-native-synchronous-list/HEAD/RNExample/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/RNExample/android/keystores/debug.keystore.properties:
--------------------------------------------------------------------------------
1 | key.store=debug.keystore
2 | key.alias=androiddebugkey
3 | key.store.password=android
4 | key.alias.password=android
5 |
--------------------------------------------------------------------------------
/lib/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SudoPlz/react-native-synchronous-list/HEAD/RNExample/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SudoPlz/react-native-synchronous-list/HEAD/RNExample/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/jsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowJs": true,
4 | "allowSyntheticDefaultImports": true
5 | },
6 | "exclude": [
7 | "node_modules"
8 | ]
9 | }
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SudoPlz/react-native-synchronous-list/HEAD/RNExample/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SudoPlz/react-native-synchronous-list/HEAD/RNExample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import SynchronousList from './lib/js/components/SynchronousList';
2 | import SyncRegistry from './lib/js/utils/SyncRegistry';
3 |
4 | module.exports = {
5 | SynchronousList,
6 | SyncRegistry,
7 | };
--------------------------------------------------------------------------------
/RNExample/android/keystores/BUCK:
--------------------------------------------------------------------------------
1 | keystore(
2 | name = "debug",
3 | properties = "debug.keystore.properties",
4 | store = "debug.keystore",
5 | visibility = [
6 | "PUBLIC",
7 | ],
8 | )
9 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .idea/
3 | .DS_Store
4 |
5 | android/.DS_Store
6 | android/android.iml
7 | android/gradlew
8 | android/gradlew.bat
9 | android/local.properties
10 | lib/android/build/
11 |
12 | ios/.DS_Store
13 |
14 | RNExample
15 | .RNExample/
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RNExample/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6 |
--------------------------------------------------------------------------------
/RNExample/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'RNExample'
2 | include ':react-native-synchronous-list'
3 | project(':react-native-synchronous-list').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-synchronous-list/lib/android')
4 |
5 | include ':app'
6 |
--------------------------------------------------------------------------------
/lib/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Feb 14 19:32:49 EET 2018
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/RNExample/__tests__/App.js:
--------------------------------------------------------------------------------
1 | import 'react-native';
2 | import React from 'react';
3 | import App from '../App';
4 |
5 | // Note: test renderer must be required after react-native.
6 | import renderer from 'react-test-renderer';
7 |
8 | it('renders correctly', () => {
9 | const tree = renderer.create(
10 |
11 | );
12 | });
13 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Sync/RCCSyncRootView.h:
--------------------------------------------------------------------------------
1 |
2 | #import
3 |
4 | #if __has_include()
5 | #import
6 | #else
7 | #import "RCTRootView.h"
8 | #endif
9 |
10 | @interface RCCSyncRootView : RCTRootView
11 |
12 | - (void)updateProps:(NSDictionary *)newProps;
13 |
14 | @property (nonatomic) int boundToIndex;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/RCTSynchronousListManager.h:
--------------------------------------------------------------------------------
1 | #if __has_include()
2 | #import
3 | #else
4 | #import "RCTViewManager.h"
5 | #endif
6 |
7 | #import "RCTSynchronousList.h"
8 |
9 | @interface RCTSynchronousListManager : RCTViewManager
10 |
11 | @property (nonatomic, strong) RCTSynchronousList * _Nullable scrollView;
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/NoLoopBinder.h:
--------------------------------------------------------------------------------
1 | //
2 | // NoLoopBinder.h
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import "ScrollViewBindFactory.h"
10 |
11 | @interface NoLoopBinder : ScrollViewBindFactory
12 |
13 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/RepeatEdgeBinder.h:
--------------------------------------------------------------------------------
1 | //
2 | // RepeatEdgeBinder.h
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import "ScrollViewBindFactory.h"
10 |
11 | @interface RepeatEdgeBinder : ScrollViewBindFactory
12 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data;
13 | @end
14 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/RepeatEmptyBinder.h:
--------------------------------------------------------------------------------
1 | //
2 | // RepeatEmptyBinder.h
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import "ScrollViewBindFactory.h"
10 |
11 | @interface RepeatEmptyBinder : ScrollViewBindFactory
12 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data;
13 | @end
14 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Sync/RCCSyncRegistry.h:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | #if __has_include()
4 | #import
5 | #else
6 | #import "RCTBridgeModule.h"
7 | #endif
8 |
9 | @interface RCCSyncRegistry : NSObject
10 |
11 | @property (nonatomic, strong) NSMutableDictionary *registry;
12 | @property (nonatomic, strong) NSNumber *lastTag;
13 |
14 | @end
15 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/ScrollViewBindFactory.h:
--------------------------------------------------------------------------------
1 | //
2 | // ScrollViewBindFactory.h
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ScrollViewBindFactory : NSObject
12 |
13 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/ScrollViewBindFactory.m:
--------------------------------------------------------------------------------
1 | //
2 | // ScrollViewBindFactory.m
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import "ScrollViewBindFactory.h"
10 |
11 | @implementation ScrollViewBindFactory
12 |
13 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data {
14 | return nil;
15 | }
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/java/com/rnexample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.rnexample;
2 |
3 | import com.facebook.react.ReactActivity;
4 |
5 | public class MainActivity extends ReactActivity {
6 |
7 | /**
8 | * Returns the name of the main component registered from JavaScript.
9 | * This is used to schedule rendering of the component.
10 | */
11 | @Override
12 | protected String getMainComponentName() {
13 | return "RNExample";
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample/AppDelegate.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #import
11 |
12 | @interface AppDelegate : UIResponder
13 |
14 | @property (nonatomic, strong) UIWindow *window;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Sync/RCCSyncRegistry.m:
--------------------------------------------------------------------------------
1 | #import "RCCSyncRegistry.h"
2 |
3 | @implementation RCCSyncRegistry
4 |
5 | RCT_EXPORT_MODULE();
6 |
7 | -(instancetype)init
8 | {
9 | self = [super init];
10 | self.registry = [NSMutableDictionary new];
11 | self.lastTag = @(1000001);
12 | return self;
13 | }
14 |
15 | RCT_EXPORT_METHOD(registerRecipe:(NSString*)registeredName props:(NSDictionary*)props recipe:(NSArray*)recipe)
16 | {
17 | [self.registry setObject:@{@"props": props, @"recipe": recipe} forKey:registeredName];
18 | }
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample/main.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #import
11 |
12 | #import "AppDelegate.h"
13 |
14 | int main(int argc, char * argv[]) {
15 | @autoreleasepool {
16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lib/android/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | compile 'com.android.support:appcompat-v7:26.0.2'
22 | compile "com.facebook.react:react-native:+" // From node_modules
23 | compile 'com.android.support:recyclerview-v7:26.0.2'
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Sync/Instructions/Instruction.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Sync.Instructions;
2 |
3 | import com.facebook.react.bridge.ReadableArray;
4 | import com.facebook.react.bridge.ReadableMap;
5 | import com.sudoplz.rnsynchronouslistmanager.Utils.WritableAdvancedMap;
6 |
7 | /**
8 | * Created by SudoPlz on 02/11/2017.
9 | */
10 |
11 | public interface Instruction {
12 |
13 | public int getInitialRootTag();
14 | public int getTag();
15 | public String getModuleName();
16 | public WritableAdvancedMap getProps();
17 | public ReadableArray getHierarchy();
18 | public String getInstructionType();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/RNExample/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to learn about possible attributes.
3 | // Hover to view descriptions of existing attributes.
4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": "Attach to packager",
9 | "program": "${workspaceRoot}/.vscode/launchReactNative.js",
10 | "type": "reactnative",
11 | "request": "attach",
12 | "sourceMaps": true,
13 | "outDir": "${workspaceRoot}/.vscode/.react"
14 | },
15 | {
16 | "type": "node",
17 | "request": "launch",
18 | "name": "Launch Program",
19 | "program": "${workspaceFolder}/start"
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/RNExample/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {
3 | AppRegistry,
4 | StyleSheet,
5 | View,
6 | Text,
7 | } from 'react-native';
8 |
9 | import { TemplateName } from './RowTemplate'; // must run before rendering anything else
10 | import ListExample from './ListExample';
11 |
12 |
13 |
14 | const styles = StyleSheet.create({
15 | container: {
16 | flex: 1,
17 | alignItems: 'center',
18 | justifyContent: 'center',
19 | backgroundColor: 'blue'
20 | },
21 | });
22 |
23 |
24 | export default class App extends React.Component {
25 | render() {
26 | return (
27 |
28 |
29 |
30 | );
31 | }
32 | }
33 | AppRegistry.registerComponent('RNExample', () => App);
34 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | }
33 | ],
34 | "info" : {
35 | "version" : 1,
36 | "author" : "xcode"
37 | }
38 | }
--------------------------------------------------------------------------------
/RNKeychain.podspec:
--------------------------------------------------------------------------------
1 | require 'json'
2 | version = JSON.parse(File.read('package.json'))["version"]
3 |
4 | Pod::Spec.new do |s|
5 |
6 | s.name = "SPRNSynchronousList"
7 | s.version = version
8 | s.summary = "A list that renders synchronously on React Native."
9 | s.homepage = "https://github.com/SudoPlz/react-native-synchronous-list"
10 | s.license = "MIT"
11 | s.author = { "Ioannis Kokkinidis" => "sudoplz@gmail.com" }
12 | s.ios.deployment_target = '7.0'
13 | s.tvos.deployment_target = '9.0'
14 | s.source = { :git => "https://github.com/SudoPlz/react-native-synchronous-list.git", :tag => "v#{s.version}" }
15 | s.source_files = 'SPRNSynchronousListManager/**/*.{h,m}'
16 | s.preserve_paths = "**/*.js"
17 | s.dependency 'React'
18 |
19 | end
20 |
--------------------------------------------------------------------------------
/RNExample/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "RNExample",
3 | "version": "0.0.1",
4 | "private": true,
5 | "scripts": {
6 | "start": "node node_modules/react-native/local-cli/cli.js start",
7 | "test": "jest",
8 | "forceClean": "watchman watch-del-all;rm -rf ./node_modules;rm -rf $TMPDIR/react-*;yarn install",
9 | "copyToLib": "cp -R node_modules/react-native-synchronous-list/lib/ ../lib/"
10 | },
11 | "dependencies": {
12 | "react": "16.2.0",
13 | "react-native": "0.53.0"
14 | },
15 | "devDependencies": {
16 | "babel-jest": "22.2.2",
17 | "babel-preset-react-native": "4.0.0",
18 | "jest": "22.3.0",
19 | "react-test-renderer": "16.2.0",
20 | "react-native-synchronous-list": "github:SudoPlz/react-native-synchronous-list"
21 | },
22 | "jest": {
23 | "preset": "react-native"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/NoLoopBinder.m:
--------------------------------------------------------------------------------
1 | //
2 | // NoLoopBinder.m
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import "NoLoopBinder.h"
10 |
11 | @implementation NoLoopBinder
12 |
13 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data {
14 | if (data != nil) {
15 | // NSLog(@"\n\n******* Binding data row %d.", rowIndex);
16 | if (rowIndex >= 0 && rowIndex < data.count) { // if the data index is within our data bounds
17 | NSMutableDictionary* rowData = [[data objectAtIndex:rowIndex] mutableCopy];
18 | rowData[@"index"] = [NSNumber numberWithInt:rowIndex];
19 | return rowData;
20 | }
21 | }
22 | return nil;
23 | }
24 |
25 | @end
26 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExampleTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample-tvOSTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 |
24 |
25 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/RepeatEmptyBinder.m:
--------------------------------------------------------------------------------
1 | //
2 | // RepeatEmptyBinder.m
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import "RepeatEmptyBinder.h"
10 |
11 | @implementation RepeatEmptyBinder
12 |
13 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data {
14 | if (data != nil) {
15 | // NSLog(@"******* Binding childIndex %d to data row %d.", childIndex, rowIndex);
16 |
17 | if (rowIndex >= 0 && rowIndex < data.count) { // if the data index is within our data bounds
18 | NSMutableDictionary* rowData = [[data objectAtIndex:rowIndex] mutableCopy];
19 | rowData[@"index"] = [NSNumber numberWithInt:rowIndex];
20 | return rowData;
21 | }
22 | }
23 | return nil;
24 | }
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Utils/FrameUtils.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Utils;
2 |
3 | import android.content.res.Resources;
4 |
5 | import com.facebook.react.bridge.ReadableMap;
6 |
7 | /**
8 | * Created by idynopia on 23/02/2018.
9 | */
10 |
11 | public class FrameUtils {
12 | public static int extractItemWidth(ReadableMap props) {
13 | if (props != null && props.hasKey("width")) {
14 | return dpToPx(props.getInt("width"));
15 | }
16 | return 0;
17 | }
18 |
19 | public static int extractItemHeight(ReadableMap props) {
20 | if (props != null && props.hasKey("height")) {
21 | return dpToPx(props.getInt("height"));
22 | }
23 | return 0;
24 | }
25 |
26 | public static int dpToPx(int dp) {
27 | return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/RNExample/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | android.useDeprecatedNdk=true
21 |
--------------------------------------------------------------------------------
/RNExample/android/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 | maven {
7 | url 'https://maven.google.com/'
8 | name 'Google'
9 | }
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:2.2.3'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | mavenLocal()
22 | jcenter()
23 | maven {
24 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
25 | url "$rootDir/../node_modules/react-native/android"
26 | }
27 | maven {
28 | url 'https://maven.google.com/'
29 | name 'Google'
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/RNExample/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # Xcode
6 | #
7 | build/
8 | *.pbxuser
9 | !default.pbxuser
10 | *.mode1v3
11 | !default.mode1v3
12 | *.mode2v3
13 | !default.mode2v3
14 | *.perspectivev3
15 | !default.perspectivev3
16 | xcuserdata
17 | *.xccheckout
18 | *.moved-aside
19 | DerivedData
20 | *.hmap
21 | *.ipa
22 | *.xcuserstate
23 | project.xcworkspace
24 |
25 | # Android/IntelliJ
26 | #
27 | build/
28 | .idea
29 | .gradle
30 | local.properties
31 | *.iml
32 |
33 | # node.js
34 | #
35 | node_modules/
36 | npm-debug.log
37 | yarn-error.log
38 |
39 | # BUCK
40 | buck-out/
41 | \.buckd/
42 | *.keystore
43 |
44 | # fastlane
45 | #
46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47 | # screenshots whenever they are needed.
48 | # For more information about the recommended setup visit:
49 | # https://docs.fastlane.tools/best-practices/source-control/
50 |
51 | */fastlane/report.xml
52 | */fastlane/Preview.html
53 | */fastlane/screenshots
54 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | !**/*.xcodeproj
3 | !**/*.pbxproj
4 | !**/*.xcworkspacedata
5 | !**/*.xcsettings
6 | !**/*.xcscheme
7 | *.pbxuser
8 | !default.pbxuser
9 | *.mode1v3
10 | !default.mode1v3
11 | *.mode2v3
12 | !default.mode2v3
13 | *.perspectivev3
14 | !default.perspectivev3
15 | xcuserdata
16 | *.xccheckout
17 | *.moved-aside
18 | DerivedData
19 | *.hmap
20 | *.ipa
21 | *.xcuserstate
22 | project.xcworkspace
23 |
24 | # Gradle
25 | /build/
26 | **/lib/android/build/
27 | **/android/build/
28 | RNExample/android/app/build/
29 | RNExample/android/app/gradle/
30 | RNExample/android/app/gradlew
31 | RNExample/android/app/gradlew.bat
32 | RNExample/build/
33 | RNExample/android/captures
34 |
35 | # Buck
36 | .buckd
37 | buck-out
38 | RNExample/src/main/jni/prebuilt/lib/armeabi-v7a/
39 | RNExample/src/main/jni/prebuilt/lib/x86/
40 | RNExample/src/main/gen
41 |
42 | # Android
43 | .idea
44 | .gradle
45 | local.properties
46 | *.iml
47 | /android/
48 |
49 | # Node
50 | node_modules
51 | *.log
52 | .nvm
53 | /danger/node_modules/
54 |
55 | # OS X
56 | .DS_Store
57 |
58 | # Test generated files
59 | *.js.meta
60 |
61 | /coverage
62 | /third-party
63 |
64 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Ioannis Kokkinidis
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
19 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/RNExample/android/app/src/main/java/com/rnexample/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.rnexample;
2 |
3 | import android.app.Application;
4 |
5 | import com.facebook.react.ReactApplication;
6 | import com.sudoplz.rnsynchronouslistmanager.SynchronousListPackage;
7 | import com.facebook.react.ReactNativeHost;
8 | import com.facebook.react.ReactPackage;
9 | import com.facebook.react.shell.MainReactPackage;
10 | import com.facebook.soloader.SoLoader;
11 |
12 | import java.util.Arrays;
13 | import java.util.List;
14 |
15 | public class MainApplication extends Application implements ReactApplication {
16 |
17 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
18 | @Override
19 | public boolean getUseDeveloperSupport() {
20 | return BuildConfig.DEBUG;
21 | }
22 |
23 | @Override
24 | protected List getPackages() {
25 | return Arrays.asList(
26 | new MainReactPackage(),
27 | new SynchronousListPackage(getReactNativeHost())
28 | );
29 | }
30 |
31 | @Override
32 | protected String getJSMainModuleName() {
33 | return "index";
34 | }
35 | };
36 |
37 | @Override
38 | public ReactNativeHost getReactNativeHost() {
39 | return mReactNativeHost;
40 | }
41 |
42 | @Override
43 | public void onCreate() {
44 | super.onCreate();
45 | SoLoader.init(this, /* native exopackage */ false);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/lib/js/components/SynchronousList.js:
--------------------------------------------------------------------------------
1 | import PropTypes from 'prop-types';
2 | import React from 'react';
3 | import {
4 | requireNativeComponent,
5 | findNodeHandle,
6 | NativeModules,
7 | } from 'react-native';
8 |
9 |
10 | const SynchronousListNativeComponent = requireNativeComponent('RCTSynchronousList', null);
11 | const { SynchronousListManager } = NativeModules;
12 |
13 | const LOOP_MODES = {
14 | NO_LOOP: 'no-loop',
15 | REPEAT_EMPTY: 'repeat-empty',
16 | REPEAT_EDGE: 'repeat-edge',
17 | }
18 |
19 | class SynchronousList extends React.Component {
20 |
21 | prepareRows() {
22 | SynchronousListManager.prepareRows();
23 | }
24 |
25 | updateDataAtIndex(index, newData) {
26 | SynchronousListManager.updateDataAtIndex(index, newData);
27 | }
28 |
29 | appendDataToDataSource(newData) {
30 | SynchronousListManager.appendDataToDataSource(newData);
31 | }
32 |
33 | prependDataToDataSource(newData) {
34 | SynchronousListManager.prependDataToDataSource(newData);
35 | }
36 |
37 | scrollToItem(position, animated) {
38 | let useAnimation = animated;
39 | if (useAnimation == null) {
40 | useAnimation = true;
41 | }
42 | SynchronousListManager.scrollToItem(position, useAnimation);
43 | }
44 |
45 | render() {
46 | return (
47 |
48 | );
49 | }
50 | }
51 | SynchronousList.LOOP_MODES = LOOP_MODES;
52 | export default SynchronousList;
53 |
--------------------------------------------------------------------------------
/RNExample/src/RowTemplate.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {
3 | // TextInput,
4 | Text,
5 | View,
6 | } from 'react-native';
7 | import { SyncRegistry } from 'react-native-synchronous-list';
8 |
9 | const TemplateName = 'MyTemplate';
10 |
11 | // const RowTemplate = (props) => (
12 | //
13 | //
18 | //
19 | // );
20 | const RowTemplate = (props) => (
21 |
22 |
26 | {props.name}
27 |
28 |
29 | );
30 |
31 | /*
32 | CAUTION:
33 | We swizzle react.render so if you try to register a recipe while other components are rendering,
34 | you will get errors (usually manage children errors)
35 | ALWAYS register the recipe when react is NOT rendering other components
36 | (Preferably right when the app launches - and before you render other components!!)
37 | */
38 | SyncRegistry.registerComponent(TemplateName, () => RowTemplate, ['name','width','height']);
39 |
40 | RowTemplate.TemplateName = TemplateName;
41 | export default RowTemplate;
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/RCTSynchronousList.h:
--------------------------------------------------------------------------------
1 | //
2 | // RNTableViewChildren.h
3 | // example
4 | //
5 | // Created by Tal Kol on 6/8/16.
6 | // Copyright © 2016 Facebook. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "RCCSyncRootView.h"
11 | #import "ScrollViewBindFactory.h"
12 | #import "NoLoopBinder.h"
13 | #import "RepeatEdgeBinder.h"
14 | #import "RepeatEmptyBinder.h"
15 |
16 | @class RCTBridge;
17 |
18 | @interface RCTSynchronousList : UIScrollView
19 |
20 | - (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
21 | - (void) createRows;
22 | - (void) appendDataToDataSource: (NSArray*) newData;
23 | - (void) prependDataToDataSource: (NSArray*) newData;
24 | - (void) updateDataAtIndex: (int) rowIndex withNewData: (id) newData;
25 | - (void) setScrollerZoom: (float) zoomScale animated: (BOOL) animated;
26 | - (int) getCurrentViewIndex;
27 |
28 | @property (nonatomic) float rowHeight;
29 | @property (nonatomic) float rowWidth;
30 | @property (nonatomic) float yeep;
31 | @property (nonatomic) int initialPosition;
32 | @property (nonatomic) NSInteger numRenderRows;
33 | @property (nonatomic) NSString *loopMode;
34 | @property (nonatomic) NSString *templateName;
35 | @property (nonatomic) NSMutableArray *data;
36 | @property (nonatomic) NSDictionary *defaultChildData;
37 | @property (nonatomic) BOOL horizontal;
38 | @property (nonatomic) BOOL paging;
39 | @property (nonatomic) BOOL dynamicViewSizes;
40 |
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample/AppDelegate.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #import "AppDelegate.h"
11 |
12 | #import
13 | #import
14 |
15 | @implementation AppDelegate
16 |
17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
18 | {
19 | NSURL *jsCodeLocation;
20 |
21 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
22 |
23 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
24 | moduleName:@"RNExample"
25 | initialProperties:nil
26 | launchOptions:launchOptions];
27 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
28 |
29 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
30 | UIViewController *rootViewController = [UIViewController new];
31 | rootViewController.view = rootView;
32 | self.window.rootViewController = rootViewController;
33 | [self.window makeKeyAndVisible];
34 | return YES;
35 | }
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Sync/Instructions/SetViewInstruction.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Sync.Instructions;
2 |
3 | import com.facebook.react.bridge.ReadableArray;
4 | import com.facebook.react.bridge.WritableNativeArray;
5 | import com.sudoplz.rnsynchronouslistmanager.Utils.WritableAdvancedMap;
6 |
7 | import java.util.Map;
8 |
9 | /**
10 | * Created by SudoPlz on 19/02/2018.
11 | */
12 |
13 | public class SetViewInstruction implements Instruction {
14 | private int initialRootTag;
15 | private ReadableArray hierarchyArr;
16 |
17 | public SetViewInstruction(ReadableArray recipeArgs) {
18 | // "args": [3, [2]],
19 | initialRootTag = recipeArgs.getInt(0);
20 | hierarchyArr = recipeArgs.getArray(1);
21 | }
22 | @Override
23 | public int getInitialRootTag() {
24 | return initialRootTag;
25 | }
26 |
27 | @Override
28 | public int getTag() {
29 | return -1;
30 | }
31 |
32 | @Override
33 | public String getModuleName() {
34 | return null;
35 | }
36 |
37 | @Override
38 | public WritableAdvancedMap getProps() {
39 | return null;
40 | }
41 |
42 | @Override
43 | public ReadableArray getHierarchy() {
44 | return hierarchyArr;
45 | }
46 |
47 | @Override
48 | public String getInstructionType() {
49 | return "setChildren";
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return "setChildren: "+initialRootTag+", "+hierarchyArr;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-synchronous-list",
3 | "version": "0.2.1",
4 | "description": "A react-native list (for iOS only) that renders it's children synchronously",
5 | "keywords": [
6 | "synchronous",
7 | "list",
8 | "react-native",
9 | "react-native-synchronous-list"
10 | ],
11 | "author": {
12 | "name": "Ioannis Kokkinidis",
13 | "email": "sudoplz@gmail.com",
14 | "url": "https://www.linkedin.com/in/sudoplz"
15 | },
16 | "license": "MIT",
17 | "repository": {
18 | "type": "git",
19 | "url": "git://github.com/SudoPlz/react-native-synchronous-list.git"
20 | },
21 | "main": "index",
22 | "scripts": {
23 | "start": "node node_modules/react-native/local-cli/cli.js start",
24 | "test": "jest"
25 | },
26 | "rnpm": {
27 | "android": {
28 | "sourceDir": "./lib/android",
29 | "packageInstance": "\t\tnew SynchronousListPackage(getReactNativeHost())"
30 | }
31 | },
32 | "peerDependencies": {
33 | "react": "*",
34 | "react-native": "*",
35 | "prop-types": "*"
36 | },
37 | "devDependencies": {
38 | "babel-eslint": "^6.1.2",
39 | "babel-plugin-module-resolver": "^2.3.0",
40 | "babel-preset-airbnb": "^1.1.1",
41 | "babel-preset-react-native": "3.0.2",
42 | "eslint": "^3.3.1",
43 | "eslint-config-airbnb": "^10.0.1",
44 | "eslint-plugin-import": "^1.14.0",
45 | "eslint-plugin-jsx-a11y": "^2.1.0",
46 | "eslint-plugin-prefer-object-spread": "^1.1.0",
47 | "eslint-plugin-react": "^6.1.2"
48 | },
49 | "jest": {
50 | "preset": "react-native"
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Sync/SyncRegistry.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Sync;
2 |
3 | import com.facebook.react.bridge.ReactApplicationContext;
4 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
5 | import com.facebook.react.bridge.ReactMethod;
6 | import com.facebook.react.bridge.ReadableArray;
7 | import com.facebook.react.bridge.ReadableMap;
8 |
9 | import java.util.HashMap;
10 | import java.util.Map;
11 |
12 | /**
13 | * Created by SudoPlz on 02/11/2017.
14 | */
15 |
16 | public class SyncRegistry extends ReactContextBaseJavaModule {
17 |
18 | protected Map recipeRegistry;
19 | protected long lastTag;
20 |
21 | public SyncRegistry(ReactApplicationContext reactContext) {
22 | super(reactContext);
23 | recipeRegistry = new HashMap();
24 | lastTag = 1000001;
25 | }
26 |
27 | @Override
28 | public String getName() {
29 | return "RCCSyncRegistry";
30 | }
31 |
32 | public Map getRegistry() {
33 | return recipeRegistry;
34 | }
35 |
36 | @ReactMethod
37 | public void registerRecipe(String registeredName, ReadableMap props, ReadableArray recipe) {
38 | // Toast.makeText(getReactApplicationContext(), message, duration).show();
39 | // [self.registry setObject:@{@"props": props, @"recipe": recipe} forKey:registeredName];
40 | recipeRegistry.put(registeredName, new Recipe(props,recipe));
41 | }
42 |
43 | public long getLastTag() {
44 | return lastTag;
45 | }
46 |
47 | public void setLastTag(long newLastTag) {
48 | lastTag = newLastTag;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/RNExample/.flowconfig:
--------------------------------------------------------------------------------
1 | [ignore]
2 | ; We fork some components by platform
3 | .*/*[.]android.js
4 |
5 | ; Ignore "BUCK" generated dirs
6 | /\.buckd/
7 |
8 | ; Ignore unexpected extra "@providesModule"
9 | .*/node_modules/.*/node_modules/fbjs/.*
10 |
11 | ; Ignore duplicate module providers
12 | ; For RN Apps installed via npm, "Libraries" folder is inside
13 | ; "node_modules/react-native" but in the source repo it is in the root
14 | .*/Libraries/react-native/React.js
15 |
16 | ; Ignore polyfills
17 | .*/Libraries/polyfills/.*
18 |
19 | ; Ignore metro
20 | .*/node_modules/metro/.*
21 |
22 | [include]
23 |
24 | [libs]
25 | node_modules/react-native/Libraries/react-native/react-native-interface.js
26 | node_modules/react-native/flow/
27 | node_modules/react-native/flow-github/
28 |
29 | [options]
30 | emoji=true
31 |
32 | module.system=haste
33 |
34 | munge_underscores=true
35 |
36 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
37 |
38 | module.file_ext=.js
39 | module.file_ext=.jsx
40 | module.file_ext=.json
41 | module.file_ext=.native.js
42 |
43 | suppress_type=$FlowIssue
44 | suppress_type=$FlowFixMe
45 | suppress_type=$FlowFixMeProps
46 | suppress_type=$FlowFixMeState
47 |
48 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
49 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
50 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
51 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
52 |
53 | [version]
54 | ^0.63.0
55 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Sync/Instructions/CreateViewInstruction.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Sync.Instructions;
2 |
3 | import com.facebook.react.bridge.ReadableArray;
4 | import com.sudoplz.rnsynchronouslistmanager.Utils.WritableAdvancedMap;
5 |
6 | /**
7 | * Created by SudoPlz on 19/02/2018.
8 | */
9 |
10 | public class CreateViewInstruction implements Instruction {
11 | private String moduleName;
12 | private int tag;
13 | private int initialRootTag;
14 | private WritableAdvancedMap props;
15 |
16 | public CreateViewInstruction (ReadableArray recipeArgs) {
17 | // "args":[125,"RCTText",1,{"allowFontScaling":true,"ellipsizeMode":"tail","accessible":true}],"
18 | tag = recipeArgs.getInt(0);
19 | moduleName = recipeArgs.getString(1);
20 | initialRootTag = recipeArgs.getInt(2);
21 | props = new WritableAdvancedMap(recipeArgs.getMap(3));
22 | }
23 | @Override
24 | public int getInitialRootTag() {
25 | return initialRootTag;
26 | }
27 |
28 | @Override
29 | public int getTag() {
30 | return tag;
31 | }
32 |
33 | @Override
34 | public String getModuleName() {
35 | return moduleName;
36 | }
37 |
38 | @Override
39 | public WritableAdvancedMap getProps() {
40 | return props;
41 | }
42 |
43 | @Override
44 | public ReadableArray getHierarchy() {
45 | return null;
46 | }
47 |
48 | @Override
49 | public String getInstructionType() {
50 | return "createView";
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return "createView: ["+tag+", "+moduleName+", "+initialRootTag+", "+props;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample-tvOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UIViewControllerBasedStatusBarAppearance
38 |
39 | NSLocationWhenInUseUsageDescription
40 |
41 | NSAppTransportSecurity
42 |
43 |
44 | NSExceptionDomains
45 |
46 | localhost
47 |
48 | NSExceptionAllowsInsecureHTTPLoads
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/RNExample/android/app/BUCK:
--------------------------------------------------------------------------------
1 | # To learn about Buck see [Docs](https://buckbuild.com/).
2 | # To run your application with Buck:
3 | # - install Buck
4 | # - `npm start` - to start the packager
5 | # - `cd android`
6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8 | # - `buck install -r android/app` - compile, install and run application
9 | #
10 |
11 | lib_deps = []
12 |
13 | for jarfile in glob(['libs/*.jar']):
14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15 | lib_deps.append(':' + name)
16 | prebuilt_jar(
17 | name = name,
18 | binary_jar = jarfile,
19 | )
20 |
21 | for aarfile in glob(['libs/*.aar']):
22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23 | lib_deps.append(':' + name)
24 | android_prebuilt_aar(
25 | name = name,
26 | aar = aarfile,
27 | )
28 |
29 | android_library(
30 | name = "all-libs",
31 | exported_deps = lib_deps,
32 | )
33 |
34 | android_library(
35 | name = "app-code",
36 | srcs = glob([
37 | "src/main/java/**/*.java",
38 | ]),
39 | deps = [
40 | ":all-libs",
41 | ":build_config",
42 | ":res",
43 | ],
44 | )
45 |
46 | android_build_config(
47 | name = "build_config",
48 | package = "com.rnexample",
49 | )
50 |
51 | android_resource(
52 | name = "res",
53 | package = "com.rnexample",
54 | res = "src/main/res",
55 | )
56 |
57 | android_binary(
58 | name = "app",
59 | keystore = "//android/keystores:debug",
60 | manifest = "src/main/AndroidManifest.xml",
61 | package_type = "debug",
62 | deps = [
63 | ":app-code",
64 | ],
65 | )
66 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/RCTSynchronousListManager.m:
--------------------------------------------------------------------------------
1 | #import "RCTSynchronousListManager.h"
2 |
3 | @implementation RCTSynchronousListManager
4 |
5 | RCT_EXPORT_MODULE();
6 |
7 | - (UIView *)view
8 | {
9 | _scrollView = [[RCTSynchronousList alloc] initWithBridge:self.bridge];
10 | // [_scrollView setFrame:CGRectMake(0, 0, 960, 1132)];
11 | return _scrollView;
12 | }
13 |
14 | RCT_EXPORT_VIEW_PROPERTY(templateName, NSString)
15 | RCT_EXPORT_VIEW_PROPERTY(rowHeight, float)
16 | RCT_EXPORT_VIEW_PROPERTY(rowWidth, float)
17 | RCT_EXPORT_VIEW_PROPERTY(numRenderRows, NSInteger)
18 | RCT_EXPORT_VIEW_PROPERTY(loopMode, NSString)
19 | RCT_EXPORT_VIEW_PROPERTY(data, NSArray)
20 | RCT_EXPORT_VIEW_PROPERTY(defaultChildData, NSDictionary)
21 | RCT_EXPORT_VIEW_PROPERTY(initialPosition, int)
22 | RCT_EXPORT_VIEW_PROPERTY(horizontal, BOOL)
23 | RCT_EXPORT_VIEW_PROPERTY(paging, BOOL)
24 | RCT_EXPORT_VIEW_PROPERTY(dynamicViewSizes, BOOL)
25 |
26 | RCT_EXPORT_METHOD(prepareRows)
27 | {
28 | [_scrollView createRows];
29 | }
30 |
31 | RCT_EXPORT_METHOD(appendDataToDataSource: (NSArray *) newData) {
32 | [_scrollView appendDataToDataSource:newData];
33 | }
34 |
35 | RCT_EXPORT_METHOD(prependDataToDataSource: (NSArray *) newData) {
36 | [_scrollView prependDataToDataSource:newData];
37 | }
38 |
39 | RCT_EXPORT_METHOD(updateDataAtIndex: (int) rowIndex withNewData: (id) newData) {
40 | [_scrollView updateDataAtIndex:rowIndex withNewData:newData];
41 | }
42 |
43 | RCT_EXPORT_METHOD(setScrollerZoom: (float) zoomScale animated: (BOOL) animated) {
44 | [_scrollView setScrollerZoom:zoomScale animated:animated];
45 | }
46 |
47 | RCT_EXPORT_METHOD(getCurrentViewIndex:(RCTPromiseResolveBlock)resolve
48 | rejecter:(RCTPromiseRejectBlock)reject) {
49 | resolve([NSNumber numberWithInt:[_scrollView getCurrentViewIndex]]);
50 | }
51 |
52 |
53 |
54 | @end
55 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | RNExample
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | UILaunchStoryboardName
28 | LaunchScreen
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UIViewControllerBasedStatusBarAppearance
40 |
41 | NSLocationWhenInUseUsageDescription
42 |
43 | NSAppTransportSecurity
44 |
45 |
46 | NSExceptionDomains
47 |
48 | localhost
49 |
50 | NSExceptionAllowsInsecureHTTPLoads
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Sync/Recipe.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Sync;
2 |
3 | import com.facebook.react.bridge.ReadableArray;
4 | import com.facebook.react.bridge.ReadableMap;
5 | import com.sudoplz.rnsynchronouslistmanager.Sync.Instructions.CreateViewInstruction;
6 | import com.sudoplz.rnsynchronouslistmanager.Sync.Instructions.Instruction;
7 | import com.sudoplz.rnsynchronouslistmanager.Sync.Instructions.SetViewInstruction;
8 | import com.sudoplz.rnsynchronouslistmanager.Utils.WritableAdvancedMap;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by SudoPlz on 19/02/2018.
14 | */
15 |
16 | public class Recipe {
17 |
18 | private WritableAdvancedMap recipeBindings;
19 | private WritableAdvancedMap recipeInverseBindings;
20 | private ArrayList recipeInstructions;
21 |
22 | public Recipe(ReadableMap bindings, ReadableArray recipe) {
23 | recipeBindings = new WritableAdvancedMap(bindings);
24 | recipeInverseBindings = recipeBindings.getInverted();
25 |
26 | recipeInstructions = new ArrayList();
27 | for (int i = 0; i < recipe.size(); i++ ) {
28 | ReadableMap curInstruction = recipe.getMap(i);
29 | if (curInstruction.getString("cmd").equals("createView")) {
30 | recipeInstructions.add(new CreateViewInstruction(curInstruction.getArray("args")));
31 | } else if (curInstruction.getString("cmd").equals("setChildren")) {
32 | recipeInstructions.add(new SetViewInstruction(curInstruction.getArray("args")));
33 | }
34 | }
35 | }
36 |
37 |
38 | public ArrayList getRecipeInstructions() {
39 | return recipeInstructions;
40 | }
41 |
42 | public WritableAdvancedMap getRecipeBindings() {
43 | return recipeBindings;
44 | }
45 |
46 | public WritableAdvancedMap getRecipeInverseBindings() {
47 | return recipeInverseBindings;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/SynchronousListPackage.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager;
2 |
3 |
4 | import com.sudoplz.rnsynchronouslistmanager.Sync.SyncRegistry;
5 | import com.sudoplz.rnsynchronouslistmanager.Utils.*;
6 | import com.facebook.react.ReactNativeHost;
7 | import com.facebook.react.ReactPackage;
8 | import com.facebook.react.bridge.NativeModule;
9 | import com.facebook.react.bridge.ReactApplicationContext;
10 | import com.facebook.react.uimanager.ViewManager;
11 |
12 | import java.util.Arrays;
13 | import java.util.List;
14 |
15 | public class SynchronousListPackage implements ReactPackage {
16 | private SynchronousListManager listManager;
17 | private ReactNativeHost rcHost;
18 |
19 | public SynchronousListPackage(ReactNativeHost host) {
20 | rcHost = host;
21 | }
22 | /**
23 | * @param reactContext react application context that can be used to create modules
24 | * @return list of native modules to register with the newly created catalyst instance
25 | */
26 | @Override
27 | public List createNativeModules(ReactApplicationContext reactContext) {
28 | if (listManager == null) {
29 | listManager = new SynchronousListManager(reactContext, rcHost);
30 | // we've passed the host, no need to keep a reference of it any more
31 | rcHost = null;
32 | }
33 | return Arrays.asList(
34 | new SyncRegistry(reactContext),
35 | new SynchronousListModule(reactContext, listManager)
36 | );
37 | }
38 |
39 |
40 |
41 | /**
42 | * @param reactContext
43 | * @return a list of view managers that should be registered with {@link UIManagerModule}
44 | */
45 | @Override
46 | public List createViewManagers(ReactApplicationContext reactContext) {
47 | if (listManager == null) {
48 | listManager = new SynchronousListManager(reactContext, rcHost);
49 | }
50 | return Arrays.asList(
51 | listManager
52 | );
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/lib/js/utils/SyncRegistry.js:
--------------------------------------------------------------------------------
1 | import _ from 'lodash';
2 | import React from 'react';
3 | const ReactNative = require('react-native/Libraries/Renderer/shims/ReactNative');
4 | const NativeModules = require('react-native').NativeModules;
5 | const UIManager = NativeModules.UIManager;
6 | const RCCSyncRegistry = NativeModules.RCCSyncRegistry;
7 |
8 | const origCreateView = UIManager.createView;
9 | const origSetChildren = UIManager.setChildren;
10 | const origManageChildren = UIManager.manageChildren;
11 |
12 | export default class SyncRegistry {
13 | static registerComponent(registeredName, componentGenerator, propNames) {
14 | const Template = componentGenerator();
15 | const props = {};
16 | for (const propName of propNames) {
17 | props[propName] = `__${propName}__`;
18 | }
19 | const recipe = [];
20 | prepareRecipeBySwizzlingUiManager(recipe);
21 | const rendered = ReactNative.render(, 1000001);
22 | restoreUiManager();
23 | RCCSyncRegistry.registerRecipe(registeredName, props, recipe);
24 | }
25 | }
26 |
27 | function prepareRecipeBySwizzlingUiManager(recipe) {
28 | UIManager.createView = (...args) => {
29 | // let childArgs = args;
30 | // const props = childArgs[3];
31 | // for (propKey in props) {
32 | // const curProp = props[propKey];
33 | // if (curProp && curProp.indexOf != null && curProp.indexOf('_') != -1) {
34 | // console.log(`tampered prop: ${JSON.stringify(curProp)}`)
35 | // childArgs[3][propKey] = 'test';
36 | // }
37 | // }
38 | // console.log(`new args: ${JSON.stringify(childArgs)}`)
39 | recipe.push({ cmd: 'createView', args });
40 | }
41 | UIManager.setChildren = (...args) => {
42 | recipe.push({ cmd: 'setChildren', args });
43 | }
44 |
45 | UIManager.manageChildren = (...args) => {
46 | // we really need to intercept manageChildren as well,
47 | // otherwise it might end up being dispatched and create an Exception
48 | // console.log(`manage children -> ${JSON.stringify(args)}`)
49 | }
50 | }
51 |
52 | function restoreUiManager() {
53 | UIManager.createView = origCreateView;
54 | UIManager.setChildren = origSetChildren;
55 | UIManager.manageChildren = origManageChildren;
56 | }
57 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Utils/SPGlobals.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Utils;
2 |
3 | import com.facebook.react.ReactNativeHost;
4 | import com.facebook.react.bridge.ReactContext;
5 |
6 | /**
7 | * Created by idynopia on 15/02/2018.
8 | */
9 |
10 | public class SPGlobals {
11 | private static SPGlobals ourInstance;
12 | private ReactContext rcContext;
13 | private ReactNativeHost rcHost;
14 | private String mainViewTemplateName = "MyTemplate";
15 | private int numRenderRows;
16 | private String loopMode;
17 |
18 | public static SPGlobals getInstance() {
19 | return ourInstance;
20 | }
21 |
22 | public static SPGlobals init(ReactContext ctx, ReactNativeHost host) {
23 | if (ourInstance == null) {
24 | ourInstance = new SPGlobals(ctx, host);
25 | } else {
26 | ourInstance.setRcContext(ctx);
27 | ourInstance.setRcHost(host);
28 | }
29 | return ourInstance;
30 | }
31 |
32 | private SPGlobals(ReactContext ctx, ReactNativeHost host) {
33 | rcContext = ctx;
34 | rcHost = host;
35 | }
36 |
37 |
38 | // setters and getters
39 |
40 |
41 | public String getMainViewTemplateName() {
42 | return mainViewTemplateName;
43 | }
44 |
45 | public void setMainViewTemplateName(String mainViewTemplateName) {
46 | this.mainViewTemplateName = mainViewTemplateName;
47 | }
48 |
49 | public ReactContext getRcContext() {
50 | return rcContext;
51 | }
52 |
53 | public void setRcContext(ReactContext rcContext) {
54 | this.rcContext = rcContext;
55 | }
56 |
57 | public ReactNativeHost getRcHost() {
58 | return rcHost;
59 | }
60 |
61 | public void setRcHost(ReactNativeHost rcHost) {
62 | this.rcHost = rcHost;
63 | }
64 |
65 | public int getNumRenderRows() {
66 | return numRenderRows;
67 | }
68 |
69 | public void setNumRenderRows(int numRenderRows) {
70 | this.numRenderRows = numRenderRows;
71 | }
72 |
73 | public String getLoopMode() {
74 | return loopMode;
75 | }
76 |
77 | public void setLoopMode(String loopMode) {
78 | this.loopMode = loopMode;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/SynchronousListModule.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager;
2 |
3 | import com.facebook.react.bridge.Promise;
4 | import com.facebook.react.bridge.ReactApplicationContext;
5 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
6 | import com.facebook.react.bridge.ReactMethod;
7 | import com.facebook.react.bridge.ReadableArray;
8 | import com.facebook.react.bridge.ReadableMap;
9 | import com.sudoplz.rnsynchronouslistmanager.Views.List.SPRecyclerView;
10 |
11 | class SynchronousListModule extends ReactContextBaseJavaModule {
12 | private SPRecyclerView calendarInstance;
13 |
14 | public SynchronousListModule (ReactApplicationContext reactContext, SynchronousListManager calManager) {
15 | super(reactContext);
16 | if (calManager != null) {
17 | calendarInstance = calManager.getListView();
18 | }
19 | }
20 |
21 | /**
22 | * @return the name of this module. This will be the name used to {@code require()} this module
23 | * from javascript.
24 | */
25 | @Override
26 | public String getName() {
27 | return "SynchronousListManager";
28 | }
29 |
30 | @ReactMethod
31 | public void prepareRows(Promise promise) {
32 | if (calendarInstance != null) {
33 | calendarInstance.prepareRows(promise);
34 | }
35 | }
36 |
37 | @ReactMethod
38 | public void scrollToItem(int item, Boolean animated) {
39 | if (calendarInstance != null) {
40 | calendarInstance.rcScrollToItem(item, animated);
41 | }
42 | }
43 |
44 | @ReactMethod
45 | public void prependDataToDataSource(ReadableArray newData) {
46 | if (calendarInstance != null) {
47 | calendarInstance.rcPrependDataToDataSource(newData);
48 | }
49 | }
50 |
51 | @ReactMethod
52 | public void appendDataToDataSource(ReadableArray newData) {
53 | if (calendarInstance != null) {
54 | calendarInstance.rcAppendDataToDataSource(newData);
55 | }
56 | }
57 |
58 | @ReactMethod
59 | public void updateDataAtIndex(int indexToUpdate, ReadableMap newData) {
60 | if (calendarInstance != null) {
61 | calendarInstance.rcUpdateDataAtIndex(indexToUpdate, newData);
62 | }
63 | }
64 |
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExampleTests/RNExampleTests.m:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2015-present, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | */
9 |
10 | #import
11 | #import
12 |
13 | #import
14 | #import
15 |
16 | #define TIMEOUT_SECONDS 600
17 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
18 |
19 | @interface RNExampleTests : XCTestCase
20 |
21 | @end
22 |
23 | @implementation RNExampleTests
24 |
25 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
26 | {
27 | if (test(view)) {
28 | return YES;
29 | }
30 | for (UIView *subview in [view subviews]) {
31 | if ([self findSubviewInView:subview matching:test]) {
32 | return YES;
33 | }
34 | }
35 | return NO;
36 | }
37 |
38 | - (void)testRendersWelcomeScreen
39 | {
40 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
41 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
42 | BOOL foundElement = NO;
43 |
44 | __block NSString *redboxError = nil;
45 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
46 | if (level >= RCTLogLevelError) {
47 | redboxError = message;
48 | }
49 | });
50 |
51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
54 |
55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
57 | return YES;
58 | }
59 | return NO;
60 | }];
61 | }
62 |
63 | RCTSetLogFunction(RCTDefaultLogFunction);
64 |
65 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
66 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
67 | }
68 |
69 |
70 | @end
71 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Bind/RepeatEdgeBinder.m:
--------------------------------------------------------------------------------
1 | //
2 | // RepeatEdgeBinder.m
3 | // example
4 | //
5 | // Created by John Kokkinidis on 12/09/2017.
6 | // Copyright © 2017 Facebook. All rights reserved.
7 | //
8 |
9 | #import "RepeatEdgeBinder.h"
10 |
11 | @implementation RepeatEdgeBinder
12 | - (NSDictionary*) getValueForRow: (int)rowIndex andDatasource: (NSMutableArray*) data {
13 | if (data != nil) {
14 | // NSLog(@"******* Binding childIndex %d to data row %d.", childIndex, rowIndex);
15 |
16 | if (rowIndex >= 0 && rowIndex < data.count) { // if the data index is within our data bounds
17 | NSMutableDictionary* rowData = [[data objectAtIndex:rowIndex] mutableCopy];
18 | rowData[@"index"] = [NSNumber numberWithInt:rowIndex];
19 | return rowData;
20 | } else {
21 | NSNumber *newDataIndex;
22 |
23 | // find the (absolute) modulo of the row index
24 | int moduloRowIndex = (ABS(rowIndex) % data.count);
25 | if (rowIndex >= 0) { // if the row index is a positive number
26 | newDataIndex = [NSNumber numberWithInt:moduloRowIndex];
27 | } else { // else if the row index is a negative number
28 | // we'll need to do some more work to calculate the new index
29 |
30 | // calculate the new data index
31 | newDataIndex = moduloRowIndex == 0 ? // if the modulo is 0
32 | [NSNumber numberWithInt:moduloRowIndex] // just return the modulo
33 | : // else
34 | [NSNumber numberWithInt:(int) data.count - moduloRowIndex];
35 | // we do that because we want the values to start again from the end of the array once the user reaches child 0 (a.k.a when rowIndex is negative)
36 | }
37 | // NSLog(@"rowIndex %d was translated to %d because %d mod %lu", rowIndex, newDataIndex.intValue, rowIndex, (unsigned long)data.count);
38 |
39 | if (newDataIndex != nil) { // if we have a newDataIndex value
40 | // just set the view data to the value of that index
41 | NSMutableDictionary* rowData = [[data objectAtIndex:newDataIndex.intValue] mutableCopy];
42 | rowData[@"index"] = [NSNumber numberWithInt:newDataIndex.intValue];
43 | return rowData;
44 | }
45 | }
46 | }
47 | return nil;
48 | }
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/lib/android/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 |
--------------------------------------------------------------------------------
/RNExample/android/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 |
--------------------------------------------------------------------------------
/RNExample/android/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 /usr/local/Cellar/android-sdk/24.3.3/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 |
19 | # Disabling obfuscation is useful if you collect stack traces from production crashes
20 | # (unless you are using a system that supports de-obfuscate the stack traces).
21 | -dontobfuscate
22 |
23 | # React Native
24 |
25 | # Keep our interfaces so they can be used by other ProGuard rules.
26 | # See http://sourceforge.net/p/proguard/bugs/466/
27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
30 |
31 | # Do not strip any method/class that is annotated with @DoNotStrip
32 | -keep @com.facebook.proguard.annotations.DoNotStrip class *
33 | -keep @com.facebook.common.internal.DoNotStrip class *
34 | -keepclassmembers class * {
35 | @com.facebook.proguard.annotations.DoNotStrip *;
36 | @com.facebook.common.internal.DoNotStrip *;
37 | }
38 |
39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
40 | void set*(***);
41 | *** get*();
42 | }
43 |
44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; }
46 | -keepclassmembers,includedescriptorclasses class * { native ; }
47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; }
48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; }
49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; }
50 |
51 | -dontwarn com.facebook.react.**
52 |
53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
55 | -dontwarn android.text.StaticLayout
56 |
57 | # okhttp
58 |
59 | -keepattributes Signature
60 | -keepattributes *Annotation*
61 | -keep class okhttp3.** { *; }
62 | -keep interface okhttp3.** { *; }
63 | -dontwarn okhttp3.**
64 |
65 | # okio
66 |
67 | -keep class sun.misc.Unsafe { *; }
68 | -dontwarn java.nio.file.*
69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
70 | -dontwarn okio.**
71 |
--------------------------------------------------------------------------------
/RNExample/src/ListExample.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {
3 | StyleSheet,
4 | Text,
5 | View,
6 | Dimensions,
7 | } from 'react-native';
8 | import { SynchronousList } from 'react-native-synchronous-list';
9 |
10 |
11 |
12 |
13 | const complexDataObj = [{
14 | name: "Row 1",
15 | width: 150,
16 | height: 150,
17 | },{
18 | name: "Row 2",
19 | width: 250,
20 | height: 300,
21 | },{
22 | name: "Row 3",
23 | width: 300,
24 | height: 150,
25 | },{
26 | name: "Row 4",
27 | width: 450,
28 | height: 150,
29 | },{
30 | name: "Row 5",
31 | width: 550,
32 | height: 150,
33 | },{
34 | name: "Row 6",
35 | width: 450,
36 | height: 150,
37 | },{
38 | name: "Row 7",
39 | width: 350,
40 | height: 150,
41 | },{
42 | name: "Row 8",
43 | width: 150,
44 | height: 150,
45 | },{
46 | name: "Row 9",
47 | width: 150,
48 | height: 150,
49 | },{
50 | name: "Row 10",
51 | width: 150,
52 | height: 150,
53 | }];
54 |
55 | for (const i = 11; i < 30; i++) {
56 | complexDataObj.push({
57 | name: `Row ${i}`,
58 | width: 400,
59 | height: 150,
60 | })
61 | }
62 |
63 | class ListExample extends React.Component {
64 | componentDidMount() {
65 | setTimeout(() => {
66 | if (this.synchronousList) {
67 | // this.synchronousList.scrollToItem(20);
68 |
69 | // this.synchronousList.prependDataToDataSource([
70 | // {
71 | // name: "Row -1",
72 | // width: 250,
73 | // height: 150,
74 | // },
75 | // {
76 | // name: "Row 0",
77 | // width: 250,
78 | // height: 150,
79 | // },
80 | // ]);
81 |
82 | // this.synchronousList.appendDataToDataSource([
83 | // {
84 | // name: "Row 32",
85 | // width: 250,
86 | // height: 150,
87 | // },
88 | // ]);
89 |
90 | // this.synchronousList.updateDataAtIndex(2, {
91 | // name: "Row 999",
92 | // width: 350,
93 | // height: 150,
94 | // });
95 | }
96 | }, 5000);
97 | }
98 | render() {
99 | return (
100 | {
102 | this.synchronousList = l;
103 | setTimeout(() => {
104 | this.synchronousList.prepareRows();
105 | }, 100)
106 | // setInterval(async () => {
107 | // const curViewIndex = await this.synchronousList.getCurrentViewIndex();
108 | // console.log(`Currently at :${curViewIndex}`);
109 | // }, 500);
110 | }}
111 | style={{ top: 0, width: Dimensions.get('window').width, height: Dimensions.get('window').height, backgroundColor: '#F2F2F2' }}
112 | templateName={this.props.templateName}
113 | rowHeight={100}
114 | dynamicViewSizes
115 | numRenderRows={10}
116 | data={complexDataObj}
117 | loopMode={SynchronousList.LOOP_MODES.NO_LOOP}
118 | />
119 | );
120 | }
121 | }
122 | export default ListExample;
--------------------------------------------------------------------------------
/RNExample/ios/RNExample/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/SynchronousListManager.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.graphics.Point;
6 | import android.os.Build;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.widget.NestedScrollView;
9 | import android.support.v7.widget.LinearLayoutManager;
10 | import android.view.ViewGroup;
11 | import android.view.WindowManager;
12 |
13 | import com.facebook.react.bridge.ReadableArray;
14 | import com.facebook.react.uimanager.annotations.ReactProp;
15 | import com.sudoplz.rnsynchronouslistmanager.Views.List.SPRecyclerView;
16 | import com.facebook.react.ReactNativeHost;
17 | import com.facebook.react.bridge.ReactContext;
18 | import com.facebook.react.uimanager.ThemedReactContext;
19 | import com.facebook.react.uimanager.ViewGroupManager;
20 | import com.sudoplz.rnsynchronouslistmanager.Utils.SPGlobals;
21 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
22 |
23 | /**
24 | * Created by SudoPlz on 05/02/2018.
25 | */
26 |
27 | public class SynchronousListManager extends ViewGroupManager {
28 | private SPRecyclerView listView;
29 | private SPGlobals globals;
30 | private boolean hasInitialised;
31 |
32 | public SynchronousListManager(ReactContext context, ReactNativeHost rcHost) {
33 | super();
34 | globals = SPGlobals.init(context, rcHost);
35 | hasInitialised = false;
36 | }
37 |
38 |
39 | @Override
40 | public String getName() {
41 | return "RCTSynchronousList";
42 | }
43 |
44 | SPRecyclerView initListView(ReactContext context) {
45 | SPRecyclerView lView = new SPRecyclerView(context);
46 | lView.setNestedScrollingEnabled(true);
47 | lView.setHorizontalScrollBarEnabled(true);
48 |
49 | // setting the layout parameters
50 | // setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
51 | lView.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
52 |
53 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
54 | linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);//or HORIZONTAL
55 | // linearLayoutManager.setMe
56 |
57 | // setting the layout manager (which will be responsible for laying out the views)
58 | lView.setLayoutManager(linearLayoutManager);
59 | return lView;
60 | }
61 |
62 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
63 | @Override
64 | public SPRecyclerView createViewInstance(ThemedReactContext context) {
65 | // return new SPView(context, map);
66 | // System.out.println("@@@@@@@@@@@@@ Created Synchronous list");
67 | // WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
68 | // Point screenSize = new Point();
69 | // wm.getDefaultDisplay().getRealSize(screenSize);
70 | // int calHeight = 1980;
71 |
72 | if (listView == null) {
73 | listView = initListView(context);
74 | } else if (hasInitialised == true) {
75 | // if the list has not been initialised yet, but SOMEHOW the list view was NOT null
76 | // that means the app reloaded, so let's remove the listView from it's parent (since it's going to be added on another parent)
77 | globals.setRcContext(context);
78 | listView.onReload();
79 |
80 | }
81 | hasInitialised = true;
82 | // NestedScrollView verticalParent = new NestedScrollView(context);
83 | // verticalParent.setVerticalScrollBarEnabled(true);
84 | //// HorizontalScrollView hr = new HorizontalScrollView(context);
85 | // verticalParent.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
86 | // verticalParent.addView(listView);
87 | //
88 | // hr.addView(listView);
89 | // return hr;
90 | return listView;
91 | }
92 |
93 | public SPRecyclerView getListView() {
94 | if (listView == null) {
95 | listView = initListView(globals.getRcContext());
96 | }
97 | return listView;
98 | }
99 |
100 | @ReactProp(name = "data")
101 | public void setData(ViewGroup view, @Nullable ReadableArray data) {
102 | listView.setData(data);
103 | }
104 |
105 | @ReactProp(name = "templateName")
106 | public void setTemplateName(ViewGroup view, @Nullable String templateName) {
107 | globals.setMainViewTemplateName(templateName);
108 | }
109 |
110 | @ReactProp(name = "numRenderRows")
111 | public void setNumRenderRows(ViewGroup view, @Nullable int numRenderRows) {
112 | globals.setNumRenderRows(numRenderRows);
113 | }
114 |
115 | @ReactProp(name = "loopMode")
116 | public void setLoopMode(ViewGroup view, @Nullable String loopMode) {
117 | globals.setLoopMode(loopMode);
118 | }
119 |
120 |
121 |
122 |
123 | }
124 |
125 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample.xcodeproj/xcshareddata/xcschemes/RNExample.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
59 |
60 |
62 |
68 |
69 |
70 |
71 |
72 |
78 |
79 |
80 |
81 |
82 |
83 |
94 |
96 |
102 |
103 |
104 |
105 |
106 |
107 |
113 |
115 |
121 |
122 |
123 |
124 |
126 |
127 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/RNExample/ios/RNExample.xcodeproj/xcshareddata/xcschemes/RNExample-tvOS.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
52 |
53 |
58 |
59 |
61 |
67 |
68 |
69 |
70 |
71 |
77 |
78 |
79 |
80 |
81 |
82 |
92 |
94 |
100 |
101 |
102 |
103 |
104 |
105 |
111 |
113 |
119 |
120 |
121 |
122 |
124 |
125 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-synchronous-list
2 |
3 |
4 |
5 | ## Consept
6 | #### What:
7 | This is an infinite list implementation that uses a template defined in javascript to render it's (native) children through an interesting mechanism called [synchronous rendering](https://www.youtube.com/watch?v=wUNC6pXSgqA) first envisioned by [Tal Kol](https://medium.com/@talkol) from wix.
8 |
9 | #### Why:
10 | Because trying to render children on the fly while scrolling sends to much information through the RNBridge and blocks it.
11 | As a result we see a white flicker when scrolling fast, plus it doesn't give the native feeling that native lists give.
12 |
13 | #### How:
14 |
15 | - When the app starts we register a component "template" that we'll be using as our row view of our native list.
16 | - We then create a set of instructions so that the native side knows how to convert that template into a native view
17 | - Finally we use the list like a typical native UI component
18 |
19 |
20 | [Here's his](https://github.com/wix/rn-synchronous-render) initial proof of concept project:
21 |
22 |
23 |
24 |
25 | ## Installation
26 |
27 | 1 . `$ npm install --save react-native-synchronous-list`
28 |
29 | or
30 |
31 | `$ yarn add react-native-synchronous-list`
32 |
33 |
34 | 2 . `$ react-native link react-native-synchronous-list`
35 |
36 | 3 . Run the project
37 |
38 | You should able to see this:
39 |
40 | iOS | Android
41 | :-------------------------:|:-------------------------:
42 |
|
43 |
44 |
45 |
46 | ## Caution
47 |
48 | That's still a WIP project and you should definitely not use it as it is on production apps.
49 |
50 |
51 | ## Typical usage
52 |
53 | ### Step 1:
54 | Basically you first register a template synchronously by invoking the SyncRegistry.
55 |
56 | [Here's](https://github.com/SudoPlz/react-native-synchronous-list/blob/master/RNExample/src/RowTemplate.js) how a template looks like and [here's](https://github.com/SudoPlz/react-native-synchronous-list/blob/master/RNExample/src/RowTemplate.js#L38) where we register it.
57 |
58 | So we'll declare that jsx template and the native code will create a recipe out of it.
59 | Next time we want to create that view, the native code will create a new view based on that recipe (without the need to go to javascript) - it all happens on the native side now.
60 |
61 | ### Step 2:
62 | Prepare the native component for rendering
63 |
64 | this.synchronousList.prepareRows();
65 |
66 | In the example we just do it whenever we first get a [ref of the list](https://github.com/SudoPlz/react-native-synchronous-list/blob/c0af3b808059f9520c2f633210b2136ca60b6456/RNExample/src/ListExample.js#L70).
67 |
68 |
69 | ### Step 3:
70 | Then all you have to do is render the list like a [normal js component](https://github.com/SudoPlz/react-native-synchronous-list/blob/c0af3b808059f9520c2f633210b2136ca60b6456/RNExample/src/ListExample.js#L66).
71 |
72 | ## Available props
73 |
74 | | Name | Type| Description | Default |
75 | | --- | --- | --- | --- |
76 | | data | array | **REQUIRED** The data that we'll be mapping to our views | - |
77 | | numRenderRows | number | **REQUIRED** The total views we'll be re/using (this list is recycling views remember?). Choose a value that's big enough so that the rows cover at least 1 screen. | - |
78 | | loopMode | string | Either **no-loop** (typical list), **repeat-empty** (a list that repeats empty views after we're out of data or **repeat-edge** (a least that repeats views that were in the beggining of our data once we're out of data (infinite loop mode) | `no-loop` |
79 | | horizontal | bool | Wether we'll be running the list in horizontal mode or vertical | `false` |
80 | | dynamicViewSizes | bool | True if we'll be calculating the row sizes based on the props data or false if we'll be using the `rowHeight` and `rowWidth` static values | `false` |
81 | | rowHeight | number | The height of each row when using the list in static row size mode. | - |
82 | | rowWidth | number | The width of each row when using the list in static row size mode. | - |
83 | | templateName | string | The name of the template object we'll be using. (No need to change that) | 'RNSynchronousListRowTemplate' |
84 |
85 | ## Exposed methods
86 |
87 | - (Promise) prependDataToDataSource(newData : Array) Prepends the newData to the list datasource
88 | - (Promise) appendDataToDataSource(newData : Array) Appends the newData to the list datasource
89 | - (Promise) updateDataAtIndex(index: int, newData : Object) Updates the data of the specified item
90 | - (void) scrollToItem(position: int) Scrolls to the position specified
91 |
92 |
93 | ## Example
94 |
95 | See the [RNExample](https://github.com/SudoPlz/react-native-synchronous-list/tree/master/RNExample) folder
96 |
97 | ## Todo
98 |
99 | | TODO | Status |
100 | | --- | --- |
101 | | Recipe registration implementation | ✅ |
102 | | SyncRootView implementation | ✅ |
103 | | RecyclerListView implementation | ✅ |
104 | | RecyclerListView row item item (extends `SyncRootView`) | ✅|
105 | | Reload working ( [RN Issue here](https://github.com/facebook/react-native/issues/18413#issuecomment-373694707) )| :x: |
106 |
107 | ## License
108 | MIT © Ioannis Kokkinidis 2017-2018
109 |
--------------------------------------------------------------------------------
/lib/android/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 |
--------------------------------------------------------------------------------
/RNExample/android/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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/lib/ios/RCTSynchronousListManager/Sync/RCCSyncRootView.m:
--------------------------------------------------------------------------------
1 |
2 | #import "RCCSyncRootView.h"
3 | #import "RCCSyncRegistry.h"
4 | #import
5 |
6 | @protocol UIManagerInternals
7 | -(void) createView:(NSNumber *)reactTag viewName:(NSString *)viewName rootTag:(NSNumber *)rootTag props:(NSDictionary *)props;
8 | -(void) updateView:(NSNumber *)reactTag viewName:(NSString *)viewName props:(NSDictionary *)props;
9 | -(void) setChildren:(NSNumber *)containerTag reactTags:(NSArray *)reactTags;
10 | @end
11 |
12 | @interface RCCSyncRootView()
13 |
14 | @property (nonatomic, retain) NSMutableDictionary *recipeTagToTag;
15 |
16 | @end
17 |
18 | @implementation RCCSyncRootView
19 |
20 | - (void)runApplication:(RCTBridge *)bridge
21 | {
22 | NSNumber *rootTag = [self performSelector:@selector(reactTag) withObject:nil];
23 | RCCSyncRegistry *module = [self registryModule];
24 | NSDictionary *details = [module.registry objectForKey:self.moduleName];
25 | NSDictionary *binding = details[@"props"];
26 | NSDictionary *inverseBinding = [self invertDictionary:binding];
27 | NSArray *recipe = details[@"recipe"];
28 |
29 | RCTUIManager *uiManager = (RCTUIManager*)self.bridge.uiManager;
30 |
31 | _boundToIndex = 0;
32 |
33 | self.recipeTagToTag = [NSMutableDictionary new];
34 | self.recipeTagToTag[@(1)] = rootTag;
35 | self.recipeTagToTag[@(1000001)] = rootTag;
36 |
37 |
38 | for (NSDictionary *call in recipe)
39 | {
40 |
41 | if ([call[@"cmd"] isEqualToString:@"createView"])
42 | {
43 | NSNumber *tag = [self translateTag:self.recipeTagToTag recipeTag:call[@"args"][0]];
44 | NSDictionary *props = [self bindProps:call[@"args"][3] binding:binding inverseBinding:inverseBinding values:self.appProperties onlyChanges:NO];
45 |
46 | dispatch_async([uiManager methodQueue], ^
47 | {
48 | [uiManager createView:tag viewName:call[@"args"][1] rootTag:rootTag props:props];
49 | });
50 |
51 | } else if ([call[@"cmd"] isEqualToString:@"setChildren"])
52 | {
53 | NSNumber *tag = [self translateTag:self.recipeTagToTag recipeTag:call[@"args"][0]];
54 | NSMutableArray *childTags = [NSMutableArray new];
55 | NSArray *arr = call[@"args"][1];
56 | for (NSNumber *childTag in arr)
57 | {
58 | [childTags addObject:[self translateTag:self.recipeTagToTag recipeTag:childTag]];
59 | }
60 |
61 | dispatch_async([uiManager methodQueue], ^
62 | {
63 | [uiManager setChildren:tag reactTags:childTags];
64 | });
65 | }
66 |
67 | }
68 | }
69 |
70 | -(void)updateProps:(NSDictionary *)newProps
71 | {
72 | if (self.recipeTagToTag == nil) return;
73 |
74 | RCCSyncRegistry *module = [self registryModule];
75 | NSDictionary *details = [module.registry objectForKey:self.moduleName];
76 | NSDictionary *binding = details[@"props"];
77 | NSDictionary *inverseBinding = [self invertDictionary:binding];
78 | NSArray *recipe = details[@"recipe"];
79 |
80 | RCTUIManager *uiManager = (RCTUIManager*)self.bridge.uiManager;
81 |
82 | for (NSDictionary *call in recipe)
83 | {
84 |
85 | if ([call[@"cmd"] isEqualToString:@"createView"])
86 | {
87 | NSNumber *tag = [self translateTag:self.recipeTagToTag recipeTag:call[@"args"][0]];
88 | NSDictionary *props = [self bindProps:call[@"args"][3] binding:binding inverseBinding:inverseBinding values:newProps onlyChanges:YES];
89 | if (props == nil) continue;
90 |
91 | dispatch_async([uiManager methodQueue], ^
92 | {
93 | [uiManager updateView:tag viewName:call[@"args"][1] props:props];
94 | });
95 | }
96 |
97 | }
98 |
99 | dispatch_async([uiManager methodQueue], ^
100 | {
101 | [uiManager batchDidComplete];
102 | });
103 | }
104 |
105 | -(NSDictionary*)invertDictionary:(NSDictionary*)dict
106 | {
107 | NSArray * keys = [dict allKeys];
108 | NSArray * vals = [dict objectsForKeys:keys notFoundMarker:[NSNull null]];
109 | return [NSDictionary dictionaryWithObjects:keys forKeys:vals];
110 | }
111 |
112 | -(NSDictionary*)bindProps:(id)props binding:(NSDictionary*)binding inverseBinding:(NSDictionary*)inverseBinding values:(NSDictionary*)values onlyChanges:(BOOL)onlyChanges
113 | {
114 | if (props == [NSNull null]) return nil;
115 | NSMutableDictionary *res = [NSMutableDictionary new];
116 |
117 | for (NSString *propName in (NSDictionary*)props)
118 | {
119 |
120 | id propValue = [props objectForKey:propName];
121 | if (!onlyChanges)
122 | {
123 | [res setObject:propValue forKey:propName]; // i.e propValue is @"__item__"
124 | }
125 |
126 | if ([propValue isKindOfClass:[NSString class]])
127 | {
128 | NSString *valueKey = [inverseBinding objectForKey:propValue];
129 | if (valueKey)
130 | {
131 | id newValue;
132 |
133 | // if item name is a nested object string (i.e item.name.firstName) - contains fullstops
134 | if ([valueKey rangeOfString:@"."].location != NSNotFound) { // if valueKey contains fullstops
135 | newValue = [values valueForKeyPath:valueKey]; // get the nested object
136 | } else { // otherwise it's a plain object (not nested)
137 | newValue = [values objectForKey:valueKey];
138 | }
139 | if (newValue == nil) newValue = [NSNull null];
140 | [res setObject:newValue forKey:propName];
141 | }
142 | }
143 | }
144 |
145 | if ([res count] == 0) return nil;
146 | return res;
147 | }
148 |
149 | -(NSNumber*)allocateTag
150 | {
151 | long result = [[self registryModule].lastTag longValue];
152 | result++;
153 | if (result % 10 == 1)
154 | {
155 | result++;
156 | }
157 | [self registryModule].lastTag = @(result);
158 | return @(result);
159 | }
160 |
161 | -(NSNumber*)translateTag:(NSMutableDictionary*)recipeTagToTag recipeTag:(NSNumber*)recipeTag
162 | {
163 | if ([recipeTagToTag objectForKey:recipeTag]) return [recipeTagToTag objectForKey:recipeTag];
164 | NSNumber *result = [self allocateTag];
165 | [recipeTagToTag setObject:result forKey:recipeTag];
166 | return result;
167 | }
168 |
169 | -(RCCSyncRegistry*)registryModule
170 | {
171 | return [self.bridge moduleForClass:RCCSyncRegistry.class];
172 | }
173 |
174 |
175 | @end
176 |
--------------------------------------------------------------------------------
/RNExample/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | import com.android.build.OutputFile
4 |
5 | /**
6 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7 | * and bundleReleaseJsAndAssets).
8 | * These basically call `react-native bundle` with the correct arguments during the Android build
9 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10 | * bundle directly from the development server. Below you can see all the possible configurations
11 | * and their defaults. If you decide to add a configuration block, make sure to add it before the
12 | * `apply from: "../../node_modules/react-native/react.gradle"` line.
13 | *
14 | * project.ext.react = [
15 | * // the name of the generated asset file containing your JS bundle
16 | * bundleAssetName: "index.android.bundle",
17 | *
18 | * // the entry file for bundle generation
19 | * entryFile: "index.android.js",
20 | *
21 | * // whether to bundle JS and assets in debug mode
22 | * bundleInDebug: false,
23 | *
24 | * // whether to bundle JS and assets in release mode
25 | * bundleInRelease: true,
26 | *
27 | * // whether to bundle JS and assets in another build variant (if configured).
28 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29 | * // The configuration property can be in the following formats
30 | * // 'bundleIn${productFlavor}${buildType}'
31 | * // 'bundleIn${buildType}'
32 | * // bundleInFreeDebug: true,
33 | * // bundleInPaidRelease: true,
34 | * // bundleInBeta: true,
35 | *
36 | * // whether to disable dev mode in custom build variants (by default only disabled in release)
37 | * // for example: to disable dev mode in the staging build type (if configured)
38 | * devDisabledInStaging: true,
39 | * // The configuration property can be in the following formats
40 | * // 'devDisabledIn${productFlavor}${buildType}'
41 | * // 'devDisabledIn${buildType}'
42 | *
43 | * // the root of your project, i.e. where "package.json" lives
44 | * root: "../../",
45 | *
46 | * // where to put the JS bundle asset in debug mode
47 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
48 | *
49 | * // where to put the JS bundle asset in release mode
50 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release",
51 | *
52 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
53 | * // require('./image.png')), in debug mode
54 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
55 | *
56 | * // where to put drawable resources / React Native assets, e.g. the ones you use via
57 | * // require('./image.png')), in release mode
58 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
59 | *
60 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means
61 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
62 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle
63 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
64 | * // for example, you might want to remove it from here.
65 | * inputExcludes: ["android/**", "ios/**"],
66 | *
67 | * // override which node gets called and with what additional arguments
68 | * nodeExecutableAndArgs: ["node"],
69 | *
70 | * // supply additional arguments to the packager
71 | * extraPackagerArgs: []
72 | * ]
73 | */
74 |
75 | project.ext.react = [
76 | entryFile: "index.js"
77 | ]
78 |
79 | apply from: "../../node_modules/react-native/react.gradle"
80 |
81 | /**
82 | * Set this to true to create two separate APKs instead of one:
83 | * - An APK that only works on ARM devices
84 | * - An APK that only works on x86 devices
85 | * The advantage is the size of the APK is reduced by about 4MB.
86 | * Upload all the APKs to the Play Store and people will download
87 | * the correct one based on the CPU architecture of their device.
88 | */
89 | def enableSeparateBuildPerCPUArchitecture = false
90 |
91 | /**
92 | * Run Proguard to shrink the Java bytecode in release builds.
93 | */
94 | def enableProguardInReleaseBuilds = false
95 |
96 | android {
97 | compileSdkVersion 26
98 | buildToolsVersion "26.0.2"
99 |
100 | defaultConfig {
101 | applicationId "com.rnexample"
102 | minSdkVersion 16
103 | targetSdkVersion 26
104 | versionCode 1
105 | versionName "1.0"
106 | ndk {
107 | abiFilters "armeabi-v7a", "x86"
108 | }
109 | }
110 | splits {
111 | abi {
112 | reset()
113 | enable enableSeparateBuildPerCPUArchitecture
114 | universalApk false // If true, also generate a universal APK
115 | include "armeabi-v7a", "x86"
116 | }
117 | }
118 | buildTypes {
119 | release {
120 | minifyEnabled enableProguardInReleaseBuilds
121 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
122 | }
123 | }
124 | // applicationVariants are e.g. debug, release
125 | applicationVariants.all { variant ->
126 | variant.outputs.each { output ->
127 | // For each separate APK per architecture, set a unique version code as described here:
128 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
129 | def versionCodes = ["armeabi-v7a":1, "x86":2]
130 | def abi = output.getFilter(OutputFile.ABI)
131 | if (abi != null) { // null for the universal-debug, universal-release variants
132 | output.versionCodeOverride =
133 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
134 | }
135 | }
136 | }
137 | }
138 |
139 | dependencies {
140 | compile project(':react-native-synchronous-list')
141 | compile fileTree(dir: "libs", include: ["*.jar"])
142 | compile "com.android.support:appcompat-v7:23.0.1"
143 | compile "com.facebook.react:react-native:+" // From node_modules
144 | }
145 |
146 | // Run this once to be able to run the application with BUCK
147 | // puts all compile dependencies into folder libs for BUCK to use
148 | task copyDownloadableDepsToLibs(type: Copy) {
149 | from configurations.compile
150 | into 'libs'
151 | }
152 |
--------------------------------------------------------------------------------
/lib/android/src/main/java/com/sudoplz/rnsynchronouslistmanager/Views/List/SPAdapter.java:
--------------------------------------------------------------------------------
1 | package com.sudoplz.rnsynchronouslistmanager.Views.List;
2 |
3 | //import android.support.v4.widget.NestedScrollView;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.ViewGroup;
8 | //import android.widget.TextView;
9 |
10 | import com.facebook.react.bridge.ReactContext;
11 | import com.facebook.react.bridge.ReadableMap;
12 | import com.sudoplz.rnsynchronouslistmanager.Views.SyncRootView;
13 | import com.sudoplz.rnsynchronouslistmanager.Utils.SPGlobals;
14 |
15 | import java.util.ArrayList;
16 |
17 | /**
18 | * Created by SudoPlz on 15/02/2018.
19 | */
20 |
21 | public class SPAdapter extends RecyclerView.Adapter {
22 |
23 | ArrayList