From 347f93a84e46cc13655b33ed0e0d968e2505569d Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Wed, 22 May 2019 10:42:52 -0500 Subject: [PATCH] Fixes issue where closing iOS app with immediate fingerprint would momentarily show fingerprint auth alert, 3.0.8 --- android/app/build.gradle | 4 +-- android/settings.gradle | 6 ++++- ios/StandardNotes/Info.plist | 2 +- package.json | 6 ++--- src/lib/ApplicationState.js | 29 +++++++++----------- src/screens/Authentication/Authenticate.js | 31 +++++++++++++++++----- 6 files changed, 48 insertions(+), 30 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 8996a515..a42cb16b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -102,8 +102,8 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 3000070 - versionName "3.0.7" + versionCode 3000080 + versionName "3.0.8" multiDexEnabled true diff --git a/android/settings.gradle b/android/settings.gradle index dbdc1500..c97e1aaf 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,12 +1,17 @@ rootProject.name = 'StandardNotes' + include ':@react-native-community_async-storage' project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android') + include ':react-native-webview' project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android') + include ':react-native-file-viewer' project(':react-native-file-viewer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-file-viewer/android') + include ':react-native-fs' project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android') + include ':app' include ':react-native-gesture-handler' @@ -35,4 +40,3 @@ project(':react-native-fingerprint-scanner').projectDir = new File(rootProject.p include ':react-native-flag-secure-android' project(':react-native-flag-secure-android').projectDir = new File(rootProject.projectDir, '../vendor/react-native-flag-secure-android/android') - diff --git a/ios/StandardNotes/Info.plist b/ios/StandardNotes/Info.plist index 460e7323..56d5a856 100644 --- a/ios/StandardNotes/Info.plist +++ b/ios/StandardNotes/Info.plist @@ -67,7 +67,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 3.0.7 + 3.0.8 CFBundleSignature ???? CFBundleVersion diff --git a/package.json b/package.json index 6dd35148..e6738195 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "StandardNotes", - "version": "3.0.7", - "versionIOS": "3.0.7", - "versionAndroid": "3.0.7", + "version": "3.0.8", + "versionIOS": "3.0.8", + "versionAndroid": "3.0.8", "license": "AGPL-3.0-or-later", "private": true, "scripts": { diff --git a/src/lib/ApplicationState.js b/src/lib/ApplicationState.js index 587a933b..fd034530 100644 --- a/src/lib/ApplicationState.js +++ b/src/lib/ApplicationState.js @@ -47,7 +47,6 @@ export default class ApplicationState { this.observers = []; this.eventSubscribers = []; this.locked = true; - this.previousEvents = []; this._isAndroid = Platform.OS === "android"; this.setTabletModeEnabled(this.isTabletDevice); @@ -163,8 +162,6 @@ export default class ApplicationState { var isLosingFocus = nextAppState == 'inactive'; if(isEnteringBackground) { - // Set most recent state before notifying observers, in case they need to query this value. - this.mostRecentState = ApplicationState.Backgrounding; this.notifyOfState(ApplicationState.Backgrounding); if(this.shouldLockApplication()) { @@ -174,17 +171,14 @@ export default class ApplicationState { if(isResumingFromBackground || isResuming) { if(isResumingFromBackground) { - this.mostRecentState = ApplicationState.ResumingFromBackground; this.notifyOfState(ApplicationState.ResumingFromBackground); } // Notify of GainingFocus even if resuming from background - this.mostRecentState = ApplicationState.GainingFocus; this.notifyOfState(ApplicationState.GainingFocus); } if(isLosingFocus) { - this.mostRecentState = ApplicationState.LosingFocus; this.notifyOfState(ApplicationState.LosingFocus); // If a privileges authentication session is in progress, we don't want to lock the application @@ -201,9 +195,9 @@ export default class ApplicationState { If we are backgrounding or losing focus, I assume we no longer care about previous events that occurred. (This was added in relation to the issue where pressing the Android back button would reconstruct App and cause all events to be re-forwarded) */ - if(isEnteringBackground || isLosingFocus) { - this.clearPreviousState(); - } + // if(isEnteringBackground || isLosingFocus) { + // this.clearPreviousState(); + // } } // Visibility change events are like active, inactive, background, @@ -237,16 +231,17 @@ export default class ApplicationState { didLaunch() { this.notifyOfState(ApplicationState.Launching); - this.mostRecentState = ApplicationState.Launching; } notifyOfState(state) { if(this.ignoreStateChanges) {return;} + + // Set most recent state before notifying observers, in case they need to query this value. + this.mostRecentState = state; + for(var observer of this.observers) { observer.callback(state); } - - this.previousEvents.push(state); } /* End State */ @@ -272,16 +267,16 @@ export default class ApplicationState { var observer = {key: Math.random, callback: callback}; this.observers.push(observer); - for(var prevState of this.previousEvents) { - callback(prevState); + if(this.mostRecentState) { + callback(this.mostRecentState); } return observer; } - clearPreviousState() { - this.previousEvents = []; - } + // clearPreviousState() { + // this.previousEvents = []; + // } removeStateObserver(observer) { _.pull(this.observers, observer); diff --git a/src/screens/Authentication/Authenticate.js b/src/screens/Authentication/Authenticate.js index a6246de9..bb040204 100644 --- a/src/screens/Authentication/Authenticate.js +++ b/src/screens/Authentication/Authenticate.js @@ -89,7 +89,10 @@ export default class Authenticate extends Abstract { componentWillFocus() { super.componentWillFocus(); - this.begin(); + + if(ApplicationState.get().getMostRecentState() !== ApplicationState.LosingFocus) { + this.begin(); + } } cancel() { @@ -194,21 +197,37 @@ export default class Authenticate extends Abstract { } onSuccess() { - // Wait for componentWillBlur to call onSuccess callback. + // Wait for componentWillBlur/componentDidlBlur to call onSuccess callback. // This way, if the callback has another route change, the dismissal // of this one won't affect it. - this.successful = true; + this.needsSuccessCallback = true; this.dismiss(); } componentWillBlur() { super.componentWillBlur(); - if(this.successful) { - this.getProp("onSuccess")(this._sessionLength); - this.successful = false; + if(this.needsSuccessCallback) { + this.triggerSuccessCallback(); } } + /* + On Android, when pressing physical back then re-opening app and authenticating and closing modal, + componentWillBlur is not called for some reason. componentDidBlur is called however, albiet ~2 seconds later. + Note however that this only seems to happen on the emulator, and not on physical device. + */ + componentDidBlur() { + super.componentDidBlur(); + if(this.needsSuccessCallback) { + this.triggerSuccessCallback(); + } + } + + triggerSuccessCallback() { + this.getProp("onSuccess")(this._sessionLength); + this.needsSuccessCallback = false; + } + inputTextChanged(text, source) { source.setAuthenticationValue(text); this.forceUpdate();