From 31281d6b68c402bbb88fc3e2f1d7cfc05e8fb170 Mon Sep 17 00:00:00 2001 From: Krzysztof Magiera Date: Fri, 3 Aug 2018 13:34:09 +0200 Subject: [PATCH] Initial commit. --- .babelrc | 3 + .buckconfig | 6 + .eslintrc.js | 19 + .flowconfig | 53 + .gitignore | 48 + .npmignore | 1 + .watchmanconfig | 1 + Example/.babelrc | 3 + Example/.buckconfig | 6 + Example/.flowconfig | 67 + Example/.gitattributes | 1 + Example/.gitignore | 56 + Example/.watchmanconfig | 1 + Example/App.js | 196 + Example/android/app/build.gradle | 151 + Example/android/app/proguard-rules.pro | 17 + .../android/app/src/main/AndroidManifest.xml | 26 + .../rnscreens/example/LifecycleAwareView.java | 25 + .../rnscreens/example/MainActivity.java | 15 + .../rnscreens/example/MainApplication.java | 47 + .../SampleLifecycleAwareViewManager.java | 35 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 8 + Example/android/build.gradle | 40 + Example/android/gradle.properties | 20 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 52266 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + Example/android/gradlew | 164 + Example/android/gradlew.bat | 90 + Example/android/keystores/BUCK | 8 + .../keystores/debug.keystore.properties | 4 + Example/android/settings.gradle | 5 + Example/app.json | 4 + Example/index.js | 7 + Example/ios/ScreensExample-tvOS/Info.plist | 54 + .../ios/ScreensExample-tvOSTests/Info.plist | 24 + .../ScreensExample.xcodeproj/project.pbxproj | 1564 +++++ .../xcschemes/ScreensExample-tvOS.xcscheme | 129 + .../xcschemes/ScreensExample.xcscheme | 129 + Example/ios/ScreensExample/AppDelegate.h | 14 + Example/ios/ScreensExample/AppDelegate.m | 35 + .../Base.lproj/LaunchScreen.xib | 42 + .../AppIcon.appiconset/Contents.json | 38 + .../Images.xcassets/Contents.json | 6 + Example/ios/ScreensExample/Info.plist | 56 + Example/ios/ScreensExample/main.m | 16 + Example/ios/ScreensExampleTests/Info.plist | 24 + .../ScreensExampleTests/ScreensExampleTests.m | 68 + Example/package.json | 24 + Example/yarn.lock | 5338 ++++++++++++++ LICENSE | 21 + README.md | 3 + RNScreens.podspec | 24 + android/README.md | 15 + android/build.gradle | 115 + android/gradle.properties | 20 + android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 52266 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + android/gradlew | 164 + android/gradlew.bat | 90 + android/settings.gradle | 1 + android/src/main/AndroidManifest.xml | 5 + .../swmansion/rnscreens/LifecycleHelper.java | 65 + .../swmansion/rnscreens/RNScreenPackage.java | 26 + .../java/com/swmansion/rnscreens/Screen.java | 72 + .../swmansion/rnscreens/ScreenContainer.java | 161 + .../rnscreens/ScreenContainerViewManager.java | 46 + .../com/swmansion/rnscreens/ScreenStack.java | 35 + .../rnscreens/ScreenStackViewManager.java | 24 + .../rnscreens/ScreenViewManager.java | 27 + ios/RNSScreen.h | 20 + ios/RNSScreen.m | 76 + ios/RNSScreenContainer.h | 18 + ios/RNSScreenContainer.m | 128 + ios/RNSScreenStack.h | 14 + ios/RNSScreenStack.m | 242 + ios/RNScreens.xcodeproj/project.pbxproj | 283 + jest.config.js | 4 + package.json | 71 + prettier.config.js | 7 + src/screens.js | 14 + yarn.lock | 6214 +++++++++++++++++ 92 files changed, 16706 insertions(+) create mode 100644 .babelrc create mode 100644 .buckconfig create mode 100644 .eslintrc.js create mode 100644 .flowconfig create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 .watchmanconfig create mode 100644 Example/.babelrc create mode 100644 Example/.buckconfig create mode 100644 Example/.flowconfig create mode 100644 Example/.gitattributes create mode 100644 Example/.gitignore create mode 100644 Example/.watchmanconfig create mode 100644 Example/App.js create mode 100644 Example/android/app/build.gradle create mode 100644 Example/android/app/proguard-rules.pro create mode 100644 Example/android/app/src/main/AndroidManifest.xml create mode 100644 Example/android/app/src/main/java/com/swmansion/rnscreens/example/LifecycleAwareView.java create mode 100644 Example/android/app/src/main/java/com/swmansion/rnscreens/example/MainActivity.java create mode 100644 Example/android/app/src/main/java/com/swmansion/rnscreens/example/MainApplication.java create mode 100644 Example/android/app/src/main/java/com/swmansion/rnscreens/example/SampleLifecycleAwareViewManager.java create mode 100644 Example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 Example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 Example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 Example/android/app/src/main/res/values/strings.xml create mode 100644 Example/android/app/src/main/res/values/styles.xml create mode 100644 Example/android/build.gradle create mode 100644 Example/android/gradle.properties create mode 100644 Example/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 Example/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 Example/android/gradlew create mode 100644 Example/android/gradlew.bat create mode 100644 Example/android/keystores/BUCK create mode 100644 Example/android/keystores/debug.keystore.properties create mode 100644 Example/android/settings.gradle create mode 100644 Example/app.json create mode 100644 Example/index.js create mode 100644 Example/ios/ScreensExample-tvOS/Info.plist create mode 100644 Example/ios/ScreensExample-tvOSTests/Info.plist create mode 100644 Example/ios/ScreensExample.xcodeproj/project.pbxproj create mode 100644 Example/ios/ScreensExample.xcodeproj/xcshareddata/xcschemes/ScreensExample-tvOS.xcscheme create mode 100644 Example/ios/ScreensExample.xcodeproj/xcshareddata/xcschemes/ScreensExample.xcscheme create mode 100644 Example/ios/ScreensExample/AppDelegate.h create mode 100644 Example/ios/ScreensExample/AppDelegate.m create mode 100644 Example/ios/ScreensExample/Base.lproj/LaunchScreen.xib create mode 100644 Example/ios/ScreensExample/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/ios/ScreensExample/Images.xcassets/Contents.json create mode 100644 Example/ios/ScreensExample/Info.plist create mode 100644 Example/ios/ScreensExample/main.m create mode 100644 Example/ios/ScreensExampleTests/Info.plist create mode 100644 Example/ios/ScreensExampleTests/ScreensExampleTests.m create mode 100644 Example/package.json create mode 100644 Example/yarn.lock create mode 100644 LICENSE create mode 100644 README.md create mode 100644 RNScreens.podspec create mode 100644 android/README.md create mode 100644 android/build.gradle create mode 100644 android/gradle.properties create mode 100644 android/gradle/wrapper/gradle-wrapper.jar create mode 100644 android/gradle/wrapper/gradle-wrapper.properties create mode 100755 android/gradlew create mode 100644 android/gradlew.bat create mode 100644 android/settings.gradle create mode 100644 android/src/main/AndroidManifest.xml create mode 100644 android/src/main/java/com/swmansion/rnscreens/LifecycleHelper.java create mode 100644 android/src/main/java/com/swmansion/rnscreens/RNScreenPackage.java create mode 100644 android/src/main/java/com/swmansion/rnscreens/Screen.java create mode 100644 android/src/main/java/com/swmansion/rnscreens/ScreenContainer.java create mode 100644 android/src/main/java/com/swmansion/rnscreens/ScreenContainerViewManager.java create mode 100644 android/src/main/java/com/swmansion/rnscreens/ScreenStack.java create mode 100644 android/src/main/java/com/swmansion/rnscreens/ScreenStackViewManager.java create mode 100644 android/src/main/java/com/swmansion/rnscreens/ScreenViewManager.java create mode 100644 ios/RNSScreen.h create mode 100644 ios/RNSScreen.m create mode 100644 ios/RNSScreenContainer.h create mode 100644 ios/RNSScreenContainer.m create mode 100644 ios/RNSScreenStack.h create mode 100644 ios/RNSScreenStack.m create mode 100644 ios/RNScreens.xcodeproj/project.pbxproj create mode 100644 jest.config.js create mode 100644 package.json create mode 100644 prettier.config.js create mode 100644 src/screens.js create mode 100644 yarn.lock diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000000..8df53fe430 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ +"presets": ["react-native"] +} \ No newline at end of file diff --git a/.buckconfig b/.buckconfig new file mode 100644 index 0000000000..934256cb29 --- /dev/null +++ b/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000000..7a35885f39 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,19 @@ +module.exports = { + parser: 'babel-eslint', + extends: [ + 'standard', + 'prettier', + 'prettier/flowtype', + 'prettier/react', + 'prettier/standard', + ], + plugins: ['react', 'react-native', 'import', 'jest'], + env: { + 'react-native/react-native': true, + 'jest/globals': true, + }, + rules: { + 'import/no-unresolved': 2, + 'react/jsx-uses-vars': 2, + }, +}; diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000000..09f0776431 --- /dev/null +++ b/.flowconfig @@ -0,0 +1,53 @@ +[ignore] +; We fork some components by platform +.*/*[.]android.js + +; Ignore unexpected extra "@providesModule" +.*/node_modules/.*/node_modules/fbjs/.* + +; Ignore duplicate module providers +; For RN Apps installed via npm, "Libraries" folder is inside +; "node_modules/react-native" but in the source repo it is in the root +.*/Libraries/react-native/React.js + +; Ignore polyfills +.*/Libraries/polyfills/.* + +; Ignore any possible duplicates from within our Example folder +.*/Example/node_modules/.* + +[include] + +[libs] +node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/flow/ + +[options] +emoji=true + +module.system=haste + +munge_underscores=true + +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' + +module.file_ext=.js +module.file_ext=.jsx +module.file_ext=.json +module.file_ext=.native.js + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState +suppress_type=$FixMe + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy +suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError + +unsafe.enable_getters_and_setters=true + +[version] +^0.56.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..1f940650d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IJ +# +*.iml +.idea +.gradle +local.properties + +# node.js +# +node_modules/ +npm-debug.log +package-lock.json + +# vscode +jsconfig.json +.project +.vscode + +# BUCK +buck-out/ +bin/ +\.buckd/ +android/app/libs +android/keystores/debug.keystore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000000..057840cd22 --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +Example/ diff --git a/.watchmanconfig b/.watchmanconfig new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/Example/.babelrc b/Example/.babelrc new file mode 100644 index 0000000000..a9ce1369e6 --- /dev/null +++ b/Example/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["react-native"] +} diff --git a/Example/.buckconfig b/Example/.buckconfig new file mode 100644 index 0000000000..934256cb29 --- /dev/null +++ b/Example/.buckconfig @@ -0,0 +1,6 @@ + +[android] + target = Google Inc.:Google APIs:23 + +[maven_repositories] + central = https://repo1.maven.org/maven2 diff --git a/Example/.flowconfig b/Example/.flowconfig new file mode 100644 index 0000000000..3c0adb5663 --- /dev/null +++ b/Example/.flowconfig @@ -0,0 +1,67 @@ +[ignore] +; We fork some components by platform +.*/*[.]android.js + +; Ignore "BUCK" generated dirs +/\.buckd/ + +; Ignore unexpected extra "@providesModule" +.*/node_modules/.*/node_modules/fbjs/.* + +; Ignore duplicate module providers +; For RN Apps installed via npm, "Libraries" folder is inside +; "node_modules/react-native" but in the source repo it is in the root +.*/Libraries/react-native/React.js + +; Ignore polyfills +.*/Libraries/polyfills/.* + +; Ignore metro +.*/node_modules/metro/.* + +[include] + +[libs] +node_modules/react-native/Libraries/react-native/react-native-interface.js +node_modules/react-native/flow/ +node_modules/react-native/flow-github/ + +[options] +emoji=true + +module.system=haste +module.system.haste.use_name_reducers=true +# get basename +module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1' +# strip .js or .js.flow suffix +module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1' +# strip .ios suffix +module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1' +module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1' +module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1' +module.system.haste.paths.blacklist=.*/__tests__/.* +module.system.haste.paths.blacklist=.*/__mocks__/.* +module.system.haste.paths.blacklist=/node_modules/react-native/Libraries/Animated/src/polyfills/.* +module.system.haste.paths.whitelist=/node_modules/react-native/Libraries/.* + +munge_underscores=true + +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' + +module.file_ext=.js +module.file_ext=.jsx +module.file_ext=.json +module.file_ext=.native.js + +suppress_type=$FlowIssue +suppress_type=$FlowFixMe +suppress_type=$FlowFixMeProps +suppress_type=$FlowFixMeState + +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy +suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError + +[version] +^0.75.0 diff --git a/Example/.gitattributes b/Example/.gitattributes new file mode 100644 index 0000000000..d42ff18354 --- /dev/null +++ b/Example/.gitattributes @@ -0,0 +1 @@ +*.pbxproj -text diff --git a/Example/.gitignore b/Example/.gitignore new file mode 100644 index 0000000000..5d647565fa --- /dev/null +++ b/Example/.gitignore @@ -0,0 +1,56 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# BUCK +buck-out/ +\.buckd/ +*.keystore + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/ + +*/fastlane/report.xml +*/fastlane/Preview.html +*/fastlane/screenshots + +# Bundle artifact +*.jsbundle diff --git a/Example/.watchmanconfig b/Example/.watchmanconfig new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/Example/.watchmanconfig @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/Example/App.js b/Example/App.js new file mode 100644 index 0000000000..1301b655c4 --- /dev/null +++ b/Example/App.js @@ -0,0 +1,196 @@ +import React, { Component } from 'react'; +import { + StyleSheet, + Button, + View, + TextInput, + Animated, + Easing, +} from 'react-native'; +import { Screen, ScreenContainer, ScreenStack } from 'react-native-screens'; + +const COLORS = ['azure', 'pink', 'cyan']; + +export class Stack extends Component { + constructor(props) { + super(props); + + const progress = new Animated.Value(0); + const slideIn = progress.interpolate({ + inputRange: [0, 1], + outputRange: [320, 0], + }); + const slideOut = progress.interpolate({ + inputRange: [0, 1], + outputRange: [0, 320], + }); + const backSlideIn = progress.interpolate({ + inputRange: [0, 1], + outputRange: [-50, 0], + }); + const backSlideOut = progress.interpolate({ + inputRange: [0, 1], + outputRange: [0, -50], + }); + + this.state = { + stack: ['azure'], + transitioning: 0, + progress, + slideIn, + slideOut, + backSlideIn, + backSlideOut, + }; + } + push(key) { + this.setState({ stack: [...this.state.stack, key], transitioning: 1 }); + this.state.progress.setValue(0); + Animated.timing(this.state.progress, { + duration: 5000, + easing: Easing.out(Easing.quad), + toValue: 1, + useNativeDriver: true, + }).start(() => { + this.setState({ transitioning: 0 }); + }); + } + pop() { + this.setState({ transitioning: -1 }); + this.state.progress.setValue(0); + Animated.timing(this.state.progress, { + duration: 5000, + easing: Easing.out(Easing.quad), + toValue: 1, + useNativeDriver: true, + }).start(() => { + this.setState({ + transitioning: 0, + stack: this.state.stack.slice(0, -1), + }); + }); + } + renderScreen = (key, index) => { + let style = StyleSheet.absoluteFill; + const { stack, transitioning } = this.state; + if (index === stack.length - 1) { + if (transitioning > 0) { + style = { + ...StyleSheet.absoluteFillObject, + transform: [{ translateX: this.state.slideIn }], + }; + } else if (transitioning < 0) { + style = { + ...StyleSheet.absoluteFillObject, + transform: [{ translateX: this.state.slideOut }], + }; + } + } else if (index === stack.length - 2) { + if (transitioning > 0) { + style = { + ...StyleSheet.absoluteFillObject, + transform: [{ translateX: this.state.backSlideOut }], + }; + } else if (transitioning < 0) { + style = { + ...StyleSheet.absoluteFillObject, + transform: [{ translateX: this.state.backSlideIn }], + }; + } + } + const active = + index === stack.length - 1 || + (transitioning !== 0 && index === stack.length - 2); + return ( + + {this.props.renderScreen(key)} + + ); + }; + render() { + const screens = this.state.stack.map(this.renderScreen); + return ( + + {screens} + + ); + // return ( + // {screens} + // ); + } +} + +// class Inner extends Component { +// state = { size: 20, display: 'flex' }; +// componentDidMount() { +// setInterval(() => { +// this.setState({ size: Math.random() * 10 + 10 }); +// }, 1500); +// setTimeout(() => this.setState({ display: 'none' }), 2000); +// } +// render() { +// return ( +// +// +// +// ); +// } +// } + +class App extends Component { + renderScreen = key => { + const index = COLORS.indexOf(key); + const color = key; + const pop = index > 0 ? () => this.stack.pop() : null; + const push = index < 2 ? () => this.stack.push(COLORS[index + 1]) : null; + return ( + + {pop &&