From d9a85c87f3475632483b18534ec45d8bebca3d04 Mon Sep 17 00:00:00 2001 From: Richard Hua Date: Mon, 14 Nov 2016 22:40:36 -0800 Subject: [PATCH] Support React Native 0.36.0 and 0.37.0 (#602) * Upgrade example app to react-native@0.37.0 * Fix crash on restart caused by loadBundle() being called twice --- Examples/CodePushDemoApp/.flowconfig | 6 +++--- .../CodePushDemoApp/android/app/build.gradle | 4 ++-- .../iOS/CodePushDemoApp/Info.plist | 2 +- Examples/CodePushDemoApp/package.json | 2 +- .../codepush/react/CodePushNativeModule.java | 18 +++++++----------- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Examples/CodePushDemoApp/.flowconfig b/Examples/CodePushDemoApp/.flowconfig index f565799..3b261e2 100644 --- a/Examples/CodePushDemoApp/.flowconfig +++ b/Examples/CodePushDemoApp/.flowconfig @@ -48,11 +48,11 @@ suppress_type=$FlowIssue suppress_type=$FlowFixMe suppress_type=$FixMe -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-2]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-2]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ +suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-3]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) +suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-3]\\|1[0-9]\\|[1-2][0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy unsafe.enable_getters_and_setters=true [version] -^0.32.0 +^0.33.0 diff --git a/Examples/CodePushDemoApp/android/app/build.gradle b/Examples/CodePushDemoApp/android/app/build.gradle index ad7e280..f2bfa81 100644 --- a/Examples/CodePushDemoApp/android/app/build.gradle +++ b/Examples/CodePushDemoApp/android/app/build.gradle @@ -136,6 +136,6 @@ dependencies { // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { - from configurations.compile - into 'libs' + from configurations.compile + into 'libs' } diff --git a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist index 2970ede..876e639 100644 --- a/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist +++ b/Examples/CodePushDemoApp/iOS/CodePushDemoApp/Info.plist @@ -45,7 +45,7 @@ localhost - NSTemporaryExceptionAllowsInsecureHTTPLoads + NSExceptionAllowsInsecureHTTPLoads diff --git a/Examples/CodePushDemoApp/package.json b/Examples/CodePushDemoApp/package.json index 19fc640..950fbca 100644 --- a/Examples/CodePushDemoApp/package.json +++ b/Examples/CodePushDemoApp/package.json @@ -8,7 +8,7 @@ "dependencies": { "babel-preset-react-native-stage-0": "1.0.1", "react": "15.3.1", - "react-native": "0.35.0", + "react-native": "0.37.0", "react-native-code-push": "file:../../" } } diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java index f994c9e..7c0cb05 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java @@ -451,17 +451,13 @@ public class CodePushNativeModule extends ReactContextBaseJavaModule { @Override public void onHostResume() { - if (installMode == CodePushInstallMode.IMMEDIATE.getValue()) { - loadBundle(); - } else { - // Determine how long the app was in the background and ensure - // that it meets the minimum duration amount of time. - long durationInBackground = 0; - if (lastPausedDate != null) { - durationInBackground = (new Date().getTime() - lastPausedDate.getTime()) / 1000; - } - - if (durationInBackground >= CodePushNativeModule.this.mMinimumBackgroundDuration) { + // As of RN 36, the resume handler fires immediately if the app is in + // the foreground, so explicitly wait for it to be backgrounded first + if (lastPausedDate != null) { + long durationInBackground = (new Date().getTime() - lastPausedDate.getTime()) / 1000; + if (installMode == CodePushInstallMode.IMMEDIATE.getValue() + || durationInBackground >= CodePushNativeModule.this.mMinimumBackgroundDuration) { + CodePushUtils.log("Loading bundle on resume"); loadBundle(); } }