From 2c97d95f9b60f846eedee401fcd500174a971dee Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 11 Oct 2021 13:18:43 +0300 Subject: [PATCH 01/57] RN 65 React Native upgrade + babel unit tests running as expected --- package.json | 15 +++++++++++---- scripts/test-js.js | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f59e0878e18..9df2d849dae 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "tslib": "1.9.3" }, "devDependencies": { - "@babel/core": "7.10.3", "@babel/plugin-proposal-export-default-from": "7.10.1", "@babel/plugin-proposal-export-namespace-from": "7.10.1", "@babel/types": "7.6.x", @@ -95,13 +94,15 @@ "github-release-notes": "https://github.com/yogevbd/github-release-notes/tarball/e601b3dba72dcd6cba323c1286ea6dd0c0110b58", "husky": "4.2.5", "identity-obj-proxy": "3.0.0", + "@babel/core": "7.15.8", + "@babel/runtime": "7.15.4", "jest": "26.1.0", "jest-circus": "26.1.0", "lint-staged": "10.2.11", "metro-react-native-babel-preset": "0.59.0", "prettier": "2.1.2", - "react": "16.13.1", - "react-native": "0.63.2", + "react": "17.0.2", + "react-native": "0.65.1", "react-native-fast-image": "^8.3.4", "react-native-gesture-handler": "^1.6.1", "react-native-reanimated": "^1.9.0", @@ -119,6 +120,9 @@ }, "jest": { "preset": "react-native", + "transformIgnorePatterns": [ + "node_modules/(?!(@react-native|react-native|@react-native-community/async-storage|@sentry/react-native)/)" + ], "transform": { "^.+\\.js$": "/node_modules/react-native/jest/preprocessor.js" }, @@ -132,6 +136,9 @@ "setupFilesAfterEnv": [ "./jest-setup.js" ], + "testPathIgnorePatterns": [ + "/node_modules/" + ], "moduleNameMapper": { "react-native-navigation/Mock": "/lib/src/Mock", "react-native-navigation": "/lib/src", @@ -257,4 +264,4 @@ } } } -} \ No newline at end of file +} diff --git a/scripts/test-js.js b/scripts/test-js.js index 6e0fbe6fd80..5c2e379cc3a 100644 --- a/scripts/test-js.js +++ b/scripts/test-js.js @@ -19,7 +19,7 @@ run(); function run() { exec.execSync(`eslint ${dirs} ${fix} --ext .js,.jsx,.ts,.tsx --format "codeframe"`); assertAllTsFilesInSrc(); - exec.execSync(`jest --coverage`); + exec.execSync(`jest /Users/warda/Desktop/work/wix/react-native-navigation/lib/src/processors/OptionProcessorsStore.test.ts`); } function assertAllTsFilesInSrc() { From 52a734565589f5b1f8248fbf07e5128298e016a2 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 11 Oct 2021 14:32:28 +0300 Subject: [PATCH 02/57] RN66 - Normal unit tests working - Upgrade to RN66. - Move jest to jest config file. - Use babel-test transformer to make unit tests working - e2e tests that can run as unit wont work. --- jest.config.js | 41 +++++++++++++++++++++++++++++++++ package.json | 62 ++++++-------------------------------------------- 2 files changed, 48 insertions(+), 55 deletions(-) create mode 100644 jest.config.js diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000000..d12fead7f38 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,41 @@ +module.exports = { + preset: 'react-native', + transformIgnorePatterns: [ + 'node_modules/(?!(@react-native|react-native|react-native-ui-lib|@sentry/react-native)/)', + ], + transform: { + '\\.[jt]sx?$': 'babel-jest', + '^.+\\.js$': '/node_modules/react-native/jest/preprocessor.js', + }, + roots: [ + '/lib/src/', + '/playground/src/', + '/integration/', + '/scripts/', + '/e2e/', + ], + setupFilesAfterEnv: ['./jest-setup.js'], + testPathIgnorePatterns: ['/node_modules/'], + moduleNameMapper: { + 'react-native-navigation/Mock': '/lib/src/Mock', + 'react-native-navigation': '/lib/src', + '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': + '/playground/img/layouts@2x.png', + }, + collectCoverageFrom: [ + 'lib/src/**/*.ts', + 'lib/src/**/*.tsx', + 'integration/**/*.js', + '!lib/dist/index.js', + '!lib/dist/Navigation.js', + '!lib/dist/adapters/**/*', + '!lib/dist/interfaces/**/*', + '!lib/dist/**/*.test.*', + '!integration/**/*.test.*', + '!integration/*.test.*', + '!e2e/**/*test.js', + ], + resetMocks: true, + resetModules: true, + coverageReporters: ['json', 'lcov', 'text', 'html'], +}; diff --git a/package.json b/package.json index 9df2d849dae..9daca93d3fc 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "devDependencies": { "@babel/plugin-proposal-export-default-from": "7.10.1", "@babel/plugin-proposal-export-namespace-from": "7.10.1", - "@babel/types": "7.6.x", + "@babel/types": "7.15.6", "@react-native-community/blur": "^3.6.0", "@react-native-community/datetimepicker": "^3.4.7", "@react-native-community/eslint-config": "2.0.0", @@ -85,7 +85,7 @@ "@types/react-test-renderer": "16.9.2", "@typescript-eslint/eslint-plugin": "3.3.0", "@typescript-eslint/parser": "3.3.0", - "babel-jest": "26.1.0", + "babel-jest": "^26.6.3", "clang-format": "^1.4.0", "detox": "18.19.0", "eslint": "7.3.0", @@ -96,13 +96,13 @@ "identity-obj-proxy": "3.0.0", "@babel/core": "7.15.8", "@babel/runtime": "7.15.4", - "jest": "26.1.0", - "jest-circus": "26.1.0", + "jest": "^26.6.3", + "jest-circus": "^26.6.3", "lint-staged": "10.2.11", - "metro-react-native-babel-preset": "0.59.0", + "metro-react-native-babel-preset": "0.66.2", "prettier": "2.1.2", "react": "17.0.2", - "react-native": "0.65.1", + "react-native": "0.66.0", "react-native-fast-image": "^8.3.4", "react-native-gesture-handler": "^1.6.1", "react-native-reanimated": "^1.9.0", @@ -118,54 +118,6 @@ "detox-testing-library-rnn-adapter": "2.x.x", "remx": "3.x.x" }, - "jest": { - "preset": "react-native", - "transformIgnorePatterns": [ - "node_modules/(?!(@react-native|react-native|@react-native-community/async-storage|@sentry/react-native)/)" - ], - "transform": { - "^.+\\.js$": "/node_modules/react-native/jest/preprocessor.js" - }, - "roots": [ - "/lib/src/", - "/playground/src/", - "/integration/", - "/scripts/", - "/e2e/" - ], - "setupFilesAfterEnv": [ - "./jest-setup.js" - ], - "testPathIgnorePatterns": [ - "/node_modules/" - ], - "moduleNameMapper": { - "react-native-navigation/Mock": "/lib/src/Mock", - "react-native-navigation": "/lib/src", - "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/playground/img/layouts@2x.png" - }, - "collectCoverageFrom": [ - "lib/src/**/*.ts", - "lib/src/**/*.tsx", - "integration/**/*.js", - "!lib/dist/index.js", - "!lib/dist/Navigation.js", - "!lib/dist/adapters/**/*", - "!lib/dist/interfaces/**/*", - "!lib/dist/**/*.test.*", - "!integration/**/*.test.*", - "!integration/*.test.*", - "!e2e/**/*test.js" - ], - "resetMocks": true, - "resetModules": true, - "coverageReporters": [ - "json", - "lcov", - "text", - "html" - ] - }, "husky": { "hooks": { "pre-commit": "lint-staged" @@ -264,4 +216,4 @@ } } } -} +} \ No newline at end of file From 5428b4751f0b15bc50d0fd2644be9cea027ef246 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 11 Oct 2021 15:24:43 +0300 Subject: [PATCH 03/57] disable running e2es as units --- jest.config.js | 2 +- package.json | 2 +- scripts/test-js.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jest.config.js b/jest.config.js index d12fead7f38..3396d5e2c16 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,7 +12,7 @@ module.exports = { '/playground/src/', '/integration/', '/scripts/', - '/e2e/', + // '/e2e/', ], setupFilesAfterEnv: ['./jest-setup.js'], testPathIgnorePatterns: ['/node_modules/'], diff --git a/package.json b/package.json index 9daca93d3fc..3d9b325f549 100644 --- a/package.json +++ b/package.json @@ -216,4 +216,4 @@ } } } -} \ No newline at end of file +} diff --git a/scripts/test-js.js b/scripts/test-js.js index 5c2e379cc3a..b70e766aa8b 100644 --- a/scripts/test-js.js +++ b/scripts/test-js.js @@ -19,7 +19,7 @@ run(); function run() { exec.execSync(`eslint ${dirs} ${fix} --ext .js,.jsx,.ts,.tsx --format "codeframe"`); assertAllTsFilesInSrc(); - exec.execSync(`jest /Users/warda/Desktop/work/wix/react-native-navigation/lib/src/processors/OptionProcessorsStore.test.ts`); + exec.execSync(`jest --config ./jest.config.js`); } function assertAllTsFilesInSrc() { From dea57771ce100661ee4f59e3d070a615224207f4 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 11 Oct 2021 15:55:53 +0300 Subject: [PATCH 04/57] use Hermes + Fix Reanimated --- .../react/NavigationReactNativeHost.java | 3 ++- playground/android/app/build.gradle | 19 ++++++++----------- .../playground/MainApplication.java | 7 ++++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/android/app/src/reactNative51/java/com/reactnativenavigation/react/NavigationReactNativeHost.java b/lib/android/app/src/reactNative51/java/com/reactnativenavigation/react/NavigationReactNativeHost.java index 8ff7f4dc12b..088c16e359a 100644 --- a/lib/android/app/src/reactNative51/java/com/reactnativenavigation/react/NavigationReactNativeHost.java +++ b/lib/android/app/src/reactNative51/java/com/reactnativenavigation/react/NavigationReactNativeHost.java @@ -8,6 +8,7 @@ import com.facebook.react.common.LifecycleState; import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; import com.reactnativenavigation.NavigationApplication; +import com.facebook.hermes.reactexecutor.HermesExecutorFactory; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -44,7 +45,7 @@ protected ReactInstanceManager createReactInstanceManager() { .setJSMainModulePath(getJSMainModuleName()) .setUseDeveloperSupport(getUseDeveloperSupport()) .setRedBoxHandler(getRedBoxHandler()) - .setJavaScriptExecutorFactory(getJavaScriptExecutorFactory()) + .setJavaScriptExecutorFactory(new HermesExecutorFactory()) .setUIImplementationProvider(getUIImplementationProvider()) .setInitialLifecycleState(LifecycleState.BEFORE_CREATE) .setDevBundleDownloadListener(getDevBundleDownloadListener()); diff --git a/playground/android/app/build.gradle b/playground/android/app/build.gradle index 7581e6895af..f3652de52cd 100644 --- a/playground/android/app/build.gradle +++ b/playground/android/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: "com.android.application" -def enableHermes = false project.ext.react = [ root : "../../../", entryFile: "index.js", + cliPath : "node_modules/react-native/cli.js", bundleAssetName: "index.android.bundle", bundleInAlpha: true, bundleInBeta: true, - enableHermes: enableHermes, + enableHermes: true, hermesFlagsDebug:['-Xes6-proxy','-output-source-map'], hermesFlagsRelease:['-output-source-map'], hermesCommand: "../../../node_modules/hermes-engine/%OS-BIN%/hermesc", @@ -33,7 +33,7 @@ android { versionCode 1 versionName "1.0" ndk { - abiFilters "armeabi-v7a", "x86", 'x86_64' + abiFilters "armeabi-v7a", "x86", "arm64-v8a", 'x86_64' } testBuildType System.getProperty('testBuildType', 'debug') @@ -63,13 +63,10 @@ dependencies { implementation 'com.facebook.react:react-native:+' implementation project(':react-native-fast-image') - if (enableHermes) { - def hermesPath = "../../node_modules/hermes-engine/android/"; - debugImplementation files(hermesPath + "hermes-debug.aar") - releaseImplementation files(hermesPath + "hermes-release.aar") - } else { - implementation jscFlavor - } + def hermesPath = "../../../node_modules/hermes-engine/android/"; + debugImplementation files(hermesPath + "hermes-debug.aar") + releaseImplementation files(hermesPath + "hermes-release.aar") + //noinspection GradleDynamicVersion implementation project(':react-native-navigation') @@ -80,7 +77,7 @@ dependencies { task copyDownloadableDepsToLibs(type: Copy) { - from configurations.compile + from configurations.implementation into 'libs' } diff --git a/playground/android/app/src/main/java/com/reactnativenavigation/playground/MainApplication.java b/playground/android/app/src/main/java/com/reactnativenavigation/playground/MainApplication.java index bad653f3f50..e0046495a10 100644 --- a/playground/android/app/src/main/java/com/reactnativenavigation/playground/MainApplication.java +++ b/playground/android/app/src/main/java/com/reactnativenavigation/playground/MainApplication.java @@ -6,7 +6,8 @@ import com.reactnativenavigation.NavigationApplication; import com.reactnativenavigation.react.NavigationPackage; import com.reactnativenavigation.react.NavigationReactNativeHost; - +import com.swmansion.reanimated.ReanimatedJSIModulePackage; +import com.facebook.react.bridge.JSIModulePackage; import java.util.ArrayList; import java.util.List; @@ -14,6 +15,10 @@ public class MainApplication extends NavigationApplication { private final ReactNativeHost mReactNativeHost = new NavigationReactNativeHost(this) { + @Override + protected JSIModulePackage getJSIModulePackage() { + return new ReanimatedJSIModulePackage(); + } @Override protected String getJSMainModuleName() { return "index"; From 5df90876b9db4114b746fc70602d490471535b72 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 11 Oct 2021 15:56:29 +0300 Subject: [PATCH 05/57] update reanimated and use babel plugin --- babel.config.js | 1 + package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/babel.config.js b/babel.config.js index c1d044b7c29..7d688a04fb7 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,6 +3,7 @@ module.exports = function (api) { return { presets: ['module:metro-react-native-babel-preset'], plugins: [ + 'react-native-reanimated/plugin', '@babel/plugin-proposal-export-namespace-from', '@babel/plugin-proposal-export-default-from', ], diff --git a/package.json b/package.json index 3d9b325f549..e14195d7cfe 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,7 @@ "react-native": "0.66.0", "react-native-fast-image": "^8.3.4", "react-native-gesture-handler": "^1.6.1", - "react-native-reanimated": "^1.9.0", + "react-native-reanimated": "2.3.0-beta.2", "react-native-ui-lib": "5.11.0", "react-redux": "5.x.x", "react-test-renderer": "16.13.1", From 52acbab4647bd5fbaffce811bd27adf252fbdde8 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Mon, 11 Oct 2021 16:18:33 +0300 Subject: [PATCH 06/57] Enable coverage --- scripts/test-js.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test-js.js b/scripts/test-js.js index b70e766aa8b..98f2a1f9cdd 100644 --- a/scripts/test-js.js +++ b/scripts/test-js.js @@ -19,7 +19,7 @@ run(); function run() { exec.execSync(`eslint ${dirs} ${fix} --ext .js,.jsx,.ts,.tsx --format "codeframe"`); assertAllTsFilesInSrc(); - exec.execSync(`jest --config ./jest.config.js`); + exec.execSync(`jest --coverage --config ./jest.config.js`); } function assertAllTsFilesInSrc() { From 6757c16f0afa36a5c1254b53c711dc40d75cc98a Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Tue, 12 Oct 2021 11:39:48 +0300 Subject: [PATCH 07/57] Upgrade jest and babel to 27 --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e14195d7cfe..21a8a0bab8a 100644 --- a/package.json +++ b/package.json @@ -78,14 +78,14 @@ "@types/detox": "16.4.1", "@types/hoist-non-react-statics": "^3.0.1", "@types/jasmine": "3.5.10", - "@types/jest": "26.0.3", + "@types/jest": "27.0.2", "@types/lodash": "^4.14.149", "@types/react": "16.9.41", "@types/react-native": "0.63.1", "@types/react-test-renderer": "16.9.2", "@typescript-eslint/eslint-plugin": "3.3.0", "@typescript-eslint/parser": "3.3.0", - "babel-jest": "^26.6.3", + "babel-jest": "^27.2.5", "clang-format": "^1.4.0", "detox": "18.19.0", "eslint": "7.3.0", @@ -96,8 +96,8 @@ "identity-obj-proxy": "3.0.0", "@babel/core": "7.15.8", "@babel/runtime": "7.15.4", - "jest": "^26.6.3", - "jest-circus": "^26.6.3", + "jest": "^27.2.5", + "jest-circus": "^27.2.5", "lint-staged": "10.2.11", "metro-react-native-babel-preset": "0.66.2", "prettier": "2.1.2", From ce6738b32e76f9f652ef613cd604e00d4d3226e4 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Tue, 12 Oct 2021 11:40:16 +0300 Subject: [PATCH 08/57] enable JS e2e add animatable to transform ignore --- jest.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jest.config.js b/jest.config.js index 3396d5e2c16..44002137a9f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,7 @@ module.exports = { preset: 'react-native', transformIgnorePatterns: [ - 'node_modules/(?!(@react-native|react-native|react-native-ui-lib|@sentry/react-native)/)', + 'node_modules/(?!(@react-native|react-native|react-native-ui-lib|react-native-animatable)/)', ], transform: { '\\.[jt]sx?$': 'babel-jest', @@ -12,7 +12,7 @@ module.exports = { '/playground/src/', '/integration/', '/scripts/', - // '/e2e/', + '/e2e/', ], setupFilesAfterEnv: ['./jest-setup.js'], testPathIgnorePatterns: ['/node_modules/'], From 3cc05b211fa8c04cf8fcec6da6c55df54b7bc7da Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Tue, 12 Oct 2021 12:04:15 +0300 Subject: [PATCH 09/57] use babel jest as transformer instead of the react native one --- jest.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 44002137a9f..66fd19e6741 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,7 +5,6 @@ module.exports = { ], transform: { '\\.[jt]sx?$': 'babel-jest', - '^.+\\.js$': '/node_modules/react-native/jest/preprocessor.js', }, roots: [ '/lib/src/', From 99f3935e7b6bf846c4ba88a6bb81d9707f7ea734 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Tue, 12 Oct 2021 23:23:54 +0300 Subject: [PATCH 10/57] update android to 30 --- lib/android/app/build.gradle | 26 ++++++++++++++------------ playground/android/app/build.gradle | 6 ++---- playground/android/build.gradle | 6 +++++- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/android/app/build.gradle b/lib/android/app/build.gradle index 51148fea824..b4b39f73837 100644 --- a/lib/android/app/build.gradle +++ b/lib/android/app/build.gradle @@ -3,27 +3,29 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback } -def DEFAULT_COMPILE_SDK_VERSION = 29 -def DEFAULT_MIN_SDK_VERSION = 19 -def DEFAULT_TARGET_SDK_VERSION = 29 -def kotlinVersion = rootProject.ext.get("RNNKotlinVersion") -def kotlinStdlib = safeExtGet('RNNKotlinStdlib', 'kotlin-stdlib-jdk8') -def kotlinCoroutinesCore = safeExtGet('RNNKotlinCoroutinesCore', '1.4.3') +def safeExtGetFallbackLowerBound(prop, fallback) { + Math.max(safeExtGet(prop,fallback),fallback) +} +def DEFAULT_COMPILE_SDK_VERSION = 30 +def DEFAULT_MIN_SDK_VERSION = 21 +def DEFAULT_TARGET_SDK_VERSION = 30 +def DEFAULT_KOTLIN_VERSION = "1.5.31" +def DEFAULT_KOTLIN_STDLIB = 'kotlin-stdlib-jdk8' +def kotlinVersion = safeExtGet("RNNKotlinVersion", DEFAULT_KOTLIN_VERSION) +def kotlinStdlib = safeExtGet('RNNKotlinStdlib',DEFAULT_KOTLIN_STDLIB ) +def kotlinCoroutinesCore = safeExtGet('RNNKotlinCoroutinesCore', '1.5.2') android { - compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) + compileSdkVersion safeExtGetFallbackLowerBound('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION) defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION) - targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) - versionCode 1 - versionName "1.0" + minSdkVersion safeExtGetFallbackLowerBound('minSdkVersion', DEFAULT_MIN_SDK_VERSION) + targetSdkVersion safeExtGetFallbackLowerBound('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION) } buildTypes { release { diff --git a/playground/android/app/build.gradle b/playground/android/app/build.gradle index f3652de52cd..c156cec030c 100644 --- a/playground/android/app/build.gradle +++ b/playground/android/app/build.gradle @@ -13,12 +13,10 @@ project.ext.react = [ hermesCommand: "../../../node_modules/hermes-engine/%OS-BIN%/hermesc", ] -def jscFlavor = 'org.webkit:android-jsc:+' - apply from: "../../../node_modules/react-native/react.gradle" android { - compileSdkVersion 29 + compileSdkVersion rootProject.ext.get("compileSdkVersion") ndkVersion "20.1.5948944" compileOptions { @@ -29,7 +27,7 @@ android { defaultConfig { applicationId "com.reactnativenavigation.playground" minSdkVersion 21 - targetSdkVersion 29 + targetSdkVersion rootProject.ext.get("targetSdkVersion") versionCode 1 versionName "1.0" ndk { diff --git a/playground/android/build.gradle b/playground/android/build.gradle index edd3c51ce9d..79f2f68dfbd 100644 --- a/playground/android/build.gradle +++ b/playground/android/build.gradle @@ -2,9 +2,13 @@ buildscript { ext { - kotlinVersion = "1.3.72" + kotlinVersion = "1.5.31" RNNKotlinVersion = kotlinVersion detoxKotlinVersion = kotlinVersion + compileSdkVersion = 30 + buildToolsVersion = "30.0.2" + minSdkVersion = 21 + targetSdkVersion = 30 } repositories { From 06cfe63b3a938974183a89425ab14d45ba6a4ad5 Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Tue, 12 Oct 2021 23:24:42 +0300 Subject: [PATCH 11/57] Fix overlay insets and use non deprecated methods --- .../component/ComponentViewController.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/component/ComponentViewController.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/component/ComponentViewController.java index 3117dcc53be..e4e6704c4cc 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/component/ComponentViewController.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/component/ComponentViewController.java @@ -15,6 +15,7 @@ import com.reactnativenavigation.views.component.ComponentLayout; import androidx.annotation.NonNull; +import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; @@ -137,13 +138,13 @@ public void applyBottomInset() { @Override protected WindowInsetsCompat applyWindowInsets(ViewController view, WindowInsetsCompat insets) { - ViewCompat.onApplyWindowInsets(view.getView(), insets.replaceSystemWindowInsets( - insets.getSystemWindowInsetLeft(), - insets.getSystemWindowInsetTop(), + final WindowInsetsCompat.Builder builder = new WindowInsetsCompat.Builder(); + final WindowInsetsCompat finalInsets = builder.setSystemWindowInsets(Insets.of(insets.getSystemWindowInsetLeft(), + Math.max(insets.getSystemWindowInsetTop() - getTopInset(), 0), insets.getSystemWindowInsetRight(), - Math.max(insets.getSystemWindowInsetBottom() - getBottomInset(), 0) - )); - return insets; + Math.max(insets.getSystemWindowInsetBottom() - getBottomInset(), 0))).build(); + ViewCompat.onApplyWindowInsets(view.getView(), finalInsets); + return finalInsets; } @Override From ba9fe1dafc5750e4fb9e7140ddabe95343c9fc8b Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Wed, 13 Oct 2021 12:51:53 +0300 Subject: [PATCH 12/57] Kotlin convert --- .../utils/StatusBarUtils.java | 41 ------------------- .../utils/StatusBarUtils.kt | 39 ++++++++++++++++++ 2 files changed, 39 insertions(+), 41 deletions(-) delete mode 100644 lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.java create mode 100644 lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.kt diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.java b/lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.java deleted file mode 100644 index 1fb0d92488f..00000000000 --- a/lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.reactnativenavigation.utils; - -import android.content.Context; -import android.content.res.Resources; -import android.os.Build; -import android.view.Window; -import android.view.WindowManager; - -import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; -import static com.reactnativenavigation.utils.UiUtils.dpToPx; - -public class StatusBarUtils { - private static final int STATUS_BAR_HEIGHT_M = 24; - private static final int STATUS_BAR_HEIGHT_L = 25; - private static int statusBarHeight = -1; - - public static void saveStatusBarHeight(int height) { - statusBarHeight = height; - } - - public static int getStatusBarHeight(Context context) { - if (statusBarHeight > 0) { - return statusBarHeight; - } - final Resources resources = context.getResources(); - final int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); - statusBarHeight = resourceId > 0 ? - resources.getDimensionPixelSize(resourceId) : - dpToPx(context, Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? STATUS_BAR_HEIGHT_M : STATUS_BAR_HEIGHT_L); - return statusBarHeight; - } - - public static int getStatusBarHeightDp(Context context) { - return (int) UiUtils.pxToDp(context, getStatusBarHeight(context)); - } - - public static boolean isTranslucent(Window window) { - WindowManager.LayoutParams lp = window.getAttributes(); - return lp != null && (lp.flags & FLAG_TRANSLUCENT_STATUS) == FLAG_TRANSLUCENT_STATUS; - } -} diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.kt b/lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.kt new file mode 100644 index 00000000000..3076cc58df2 --- /dev/null +++ b/lib/android/app/src/main/java/com/reactnativenavigation/utils/StatusBarUtils.kt @@ -0,0 +1,39 @@ +package com.reactnativenavigation.utils + +import android.content.Context +import android.os.Build +import android.view.Window +import android.view.WindowManager +import com.reactnativenavigation.utils.StatusBarUtils + +object StatusBarUtils { + private const val STATUS_BAR_HEIGHT_M = 24 + private const val STATUS_BAR_HEIGHT_L = 25 + private var statusBarHeight = -1 + fun saveStatusBarHeight(height: Int) { + statusBarHeight = height + } + + fun getStatusBarHeight(context: Context): Int { + if (statusBarHeight > 0) { + return statusBarHeight + } + val resources = context.resources + val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") + statusBarHeight = if (resourceId > 0) resources.getDimensionPixelSize(resourceId) else UiUtils.dpToPx( + context, + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) STATUS_BAR_HEIGHT_M else STATUS_BAR_HEIGHT_L + ) + return statusBarHeight + } + + fun getStatusBarHeightDp(context: Context): Int { + return UiUtils.pxToDp(context, getStatusBarHeight(context).toFloat()) + .toInt() + } + + fun isTranslucent(window: Window): Boolean { + val lp = window.attributes + return lp != null && lp.flags and WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS == WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + } +} \ No newline at end of file From aff2b87bf8837f18abdf1164e415342c1376c04a Mon Sep 17 00:00:00 2001 From: Ward Abbass Date: Thu, 14 Oct 2021 15:24:50 +0300 Subject: [PATCH 13/57] tmp status --- lib/android/app/build.gradle | 6 +- .../react/NavigationModule.java | 5 +- .../react/modal/ModalFrameLayout.kt | 2 +- .../react/modal/ModalViewManager.kt | 17 +-- .../utils/StatusBarUtils.kt | 104 +++++++++++++++--- .../child/ChildController.java | 2 +- .../viewcontroller/Presenter.java | 35 +++--- .../src/screens/StatusBarOptionsScreen.tsx | 15 +++ 8 files changed, 135 insertions(+), 51 deletions(-) diff --git a/lib/android/app/build.gradle b/lib/android/app/build.gradle index b4b39f73837..6a5e257eeac 100644 --- a/lib/android/app/build.gradle +++ b/lib/android/app/build.gradle @@ -172,13 +172,13 @@ allprojects { p -> } dependencies { - implementation "androidx.core:core-ktx:1.3.2" + implementation "androidx.core:core-ktx:1.6.0" implementation "org.jetbrains.kotlin:$kotlinStdlib:$kotlinVersion" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinCoroutinesCore" implementation "androidx.constraintlayout:constraintlayout:2.0.4" - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.annotation:annotation:1.1.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'androidx.annotation:annotation:1.2.0' implementation 'com.google.android.material:material:1.2.0-alpha03' implementation 'com.github.wix-playground:ahbottomnavigation:3.3.0' diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java b/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java index ccae0c70fa4..897173e6824 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java @@ -34,6 +34,8 @@ import static com.reactnativenavigation.utils.UiUtils.pxToDp; +import android.app.Activity; + public class NavigationModule extends ReactContextBaseJavaModule { private static final String NAME = "RNNBridgeModule"; @@ -88,10 +90,11 @@ public void getLaunchArgs(String commandId, Promise promise) { private WritableMap createNavigationConstantsMap() { ReactApplicationContext ctx = getReactApplicationContext(); + final Activity currentActivity = ctx.getCurrentActivity(); WritableMap constants = Arguments.createMap(); constants.putString(Constants.BACK_BUTTON_JS_KEY, Constants.BACK_BUTTON_ID); constants.putDouble(Constants.BOTTOM_TABS_HEIGHT_KEY, pxToDp(ctx, UiUtils.getBottomTabsHeight(ctx))); - constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, pxToDp(ctx, StatusBarUtils.getStatusBarHeight(ctx))); + constants.putDouble(Constants.STATUS_BAR_HEIGHT_KEY, pxToDp(ctx, StatusBarUtils.getStatusBarHeight(currentActivity))); constants.putDouble(Constants.TOP_BAR_HEIGHT_KEY, pxToDp(ctx, UiUtils.getTopBarHeight(ctx))); return constants; } diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalFrameLayout.kt b/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalFrameLayout.kt index 07e0690127b..4ae7901ade3 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalFrameLayout.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalFrameLayout.kt @@ -13,7 +13,7 @@ class ModalFrameLayout(context: ReactContext) : FrameLayout(context) { val translucent = context.currentActivity?.window?.let { StatusBarUtils.isTranslucent(context.currentActivity?.window) } ?: false - topMargin = if (translucent) 0 else StatusBarUtils.getStatusBarHeight(context) + topMargin = if (translucent) 0 else StatusBarUtils.getStatusBarHeight(context.currentActivity) }) } } \ No newline at end of file diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalViewManager.kt b/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalViewManager.kt index 23a93c54060..05b59531918 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalViewManager.kt +++ b/lib/android/app/src/main/java/com/reactnativenavigation/react/modal/ModalViewManager.kt @@ -1,5 +1,6 @@ package com.reactnativenavigation.react.modal +import android.app.Activity import android.content.Context import android.graphics.Point import android.view.WindowManager @@ -107,18 +108,18 @@ class ModalViewManager(val reactContext: ReactContext) : ViewGroupManager 0) { + statusBarHeight + } else { + statusBarHeight = activity?.let { + val rectangle = Rect() + val window: Window = activity.window + window.decorView.getWindowVisibleDisplayFrame(rectangle) + val statusBarHeight: Int = rectangle.top + val contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).top + abs(contentViewTop - statusBarHeight) + } ?: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) STATUS_BAR_HEIGHT_M else STATUS_BAR_HEIGHT_L + statusBarHeight + } + logd("StatusBarHeight $res","STATUSXXXX") + return res + } + + @JvmStatic fun saveStatusBarHeight(height: Int) { statusBarHeight = height } - fun getStatusBarHeight(context: Context): Int { - if (statusBarHeight > 0) { - return statusBarHeight + @JvmStatic + fun getStatusBarHeightDp(activity: Activity?): Int { + return UiUtils.pxToDp(activity, getStatusBarHeight(activity).toFloat()) + .toInt() + } + + @JvmStatic + fun isTranslucent(window: Window?): Boolean { + return window?.let { + val lp = window.attributes + return lp != null && lp.flags and WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS == WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + } ?: false + } + + fun hideSystemUi(window: Window?, view: View) { + window?.let { + WindowCompat.setDecorFitsSystemWindows(window, false) + WindowInsetsControllerCompat(window, view).let { controller -> + controller.hide(WindowInsetsCompat.Type.systemBars()) + controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } } - val resources = context.resources - val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android") - statusBarHeight = if (resourceId > 0) resources.getDimensionPixelSize(resourceId) else UiUtils.dpToPx( - context, - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) STATUS_BAR_HEIGHT_M else STATUS_BAR_HEIGHT_L - ) - return statusBarHeight } - fun getStatusBarHeightDp(context: Context): Int { - return UiUtils.pxToDp(context, getStatusBarHeight(context).toFloat()) - .toInt() + fun showSystemUi(window: Window?, view: View) { + window?.let { + WindowCompat.setDecorFitsSystemWindows(window, true) + WindowInsetsControllerCompat(window, view).show(WindowInsetsCompat.Type.navigationBars()) + } } - fun isTranslucent(window: Window): Boolean { - val lp = window.attributes - return lp != null && lp.flags and WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS == WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + fun hideNavigationBar(window: Window?, view: View) { + window?.let { + WindowCompat.setDecorFitsSystemWindows(window, false) + WindowInsetsControllerCompat(window, view).let { controller -> + controller.hide(WindowInsetsCompat.Type.navigationBars()) + controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } + } + } + + fun showNavigationBar(window: Window?, view: View) { + window?.let { + WindowCompat.setDecorFitsSystemWindows(window, true) + WindowInsetsControllerCompat(window, view).show(WindowInsetsCompat.Type.navigationBars()) + } + } + + fun hideStatusBar(window: Window?, view: View) { + window?.let { + WindowCompat.setDecorFitsSystemWindows(window, true) + WindowInsetsControllerCompat(window, view).let { controller -> + controller.hide(WindowInsetsCompat.Type.statusBars()) + controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + } + } + } + + fun showStatusBar(window: Window?, view: View) { + window?.let { + WindowCompat.setDecorFitsSystemWindows(window, true) + WindowInsetsControllerCompat(window, view).show(WindowInsetsCompat.Type.statusBars()) + } } } \ No newline at end of file diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/child/ChildController.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/child/ChildController.java index 0fc83e394e5..c1b0a0aea89 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/child/ChildController.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/child/ChildController.java @@ -61,7 +61,7 @@ public void onViewDisappear() { } public void onViewBroughtToFront() { - presenter.onViewBroughtToFront(resolveCurrentOptions()); + presenter.onViewBroughtToFront(this,resolveCurrentOptions()); } @Override diff --git a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/viewcontroller/Presenter.java b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/viewcontroller/Presenter.java index 9feab908f3e..8e0ed81c554 100644 --- a/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/viewcontroller/Presenter.java +++ b/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/viewcontroller/Presenter.java @@ -44,13 +44,13 @@ public void applyOptions(ViewController view, Options options) { Options withDefaultOptions = options.copy().withDefaultOptions(defaultOptions); applyOrientation(withDefaultOptions.layout.orientation); applyViewOptions(view, withDefaultOptions); - applyStatusBarOptions(withDefaultOptions); + applyStatusBarOptions(view, withDefaultOptions); applyNavigationBarOptions(withDefaultOptions.navigationBar); } - public void onViewBroughtToFront(Options options) { + public void onViewBroughtToFront(ViewController viewController, Options options) { Options withDefaultOptions = options.copy().withDefaultOptions(defaultOptions); - applyStatusBarOptions(withDefaultOptions); + applyStatusBarOptions(viewController, withDefaultOptions); } private void applyOrientation(OrientationOptions options) { @@ -83,12 +83,12 @@ private void applyBackgroundColor(ViewController view, Options options) { } } - private void applyStatusBarOptions(Options options) { + private void applyStatusBarOptions(ViewController viewController, Options options) { StatusBarOptions statusBar = options.copy().withDefaultOptions(defaultOptions).statusBar; setStatusBarBackgroundColor(statusBar); setTextColorScheme(statusBar); setTranslucent(statusBar); - setStatusBarVisible(statusBar.visible); + setStatusBarVisible(viewController, statusBar.visible); } private void setTranslucent(StatusBarOptions options) { @@ -100,19 +100,17 @@ private void setTranslucent(StatusBarOptions options) { } } - private void setStatusBarVisible(Bool visible) { - View decorView = activity.getWindow().getDecorView(); - int flags = decorView.getSystemUiVisibility(); + private void setStatusBarVisible(ViewController viewController, Bool visible) { + final View view = viewController.view != null ? viewController.view : activity.getWindow().getDecorView(); if (visible.isFalse()) { - flags |= View.SYSTEM_UI_FLAG_FULLSCREEN; + StatusBarUtils.INSTANCE.hideStatusBar(activity.getWindow(), view); } else { - flags &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; + StatusBarUtils.INSTANCE.showStatusBar(activity.getWindow(), view); } - decorView.setSystemUiVisibility(flags); } private void setStatusBarBackgroundColor(StatusBarOptions statusBar) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && statusBar.backgroundColor.canApplyValue()) { + if (statusBar.backgroundColor.canApplyValue()) { activity.getWindow().setStatusBarColor(getStatusBarBackgroundColor(statusBar)); } } @@ -138,7 +136,7 @@ private void setTextColorScheme(StatusBarOptions statusBar) { final View view = activity.getWindow().getDecorView(); //View.post is a Workaround, added to solve internal Samsung //Android 9 issues. For more info see https://github.com/wix/react-native-navigation/pull/7231 - view.post(()->{ + view.post(() -> { int flags = view.getSystemUiVisibility(); if (isDarkTextColorScheme(statusBar)) { flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; @@ -154,7 +152,7 @@ private void mergeStatusBarOptions(View view, StatusBarOptions statusBar) { mergeStatusBarBackgroundColor(statusBar); mergeTextColorScheme(statusBar); mergeTranslucent(statusBar); - mergeStatusBarVisible(view, statusBar.visible, statusBar.drawBehind); + mergeStatusBarVisible(view, statusBar.visible); } private void mergeStatusBarBackgroundColor(StatusBarOptions statusBar) { @@ -177,16 +175,13 @@ private void mergeTranslucent(StatusBarOptions options) { } } - private void mergeStatusBarVisible(View view, Bool visible, Bool drawBehind) { + private void mergeStatusBarVisible(View view, Bool visible) { if (visible.hasValue()) { - int flags = view.getSystemUiVisibility(); if (visible.isTrue()) { - flags &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN & ~View.SYSTEM_UI_FLAG_FULLSCREEN; + StatusBarUtils.INSTANCE.showStatusBar(activity.getWindow(), view); } else { - flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN; + StatusBarUtils.INSTANCE.hideStatusBar(activity.getWindow(), view); } - if (flags != view.getSystemUiVisibility()) view.requestLayout(); - view.setSystemUiVisibility(flags); } } diff --git a/playground/src/screens/StatusBarOptionsScreen.tsx b/playground/src/screens/StatusBarOptionsScreen.tsx index 1308914944c..94e9623447e 100644 --- a/playground/src/screens/StatusBarOptionsScreen.tsx +++ b/playground/src/screens/StatusBarOptionsScreen.tsx @@ -37,6 +37,8 @@ export default class StatusBarOptions extends React.Component