From 58151ea1abb58621c4b0a0903bc0f6bdd389ee90 Mon Sep 17 00:00:00 2001 From: Luca Colonnello Date: Fri, 17 Apr 2020 00:12:05 +0100 Subject: [PATCH] [android][web-browser] Fix WebBrowser sending 'dismiss' before opening (#6743) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [android][web-browser] Fix WebBrowser sending 'dismiss' before opening Fixes https://github.com/expo/expo/issues/6679 TL;DR A wrong usage of AppState causes WebBrowser to resolve with `{ type: 'dismiss' }` before opening the view. This is related to AppState being not initialised yet, triggering a change before the user leaves the app view to focus on the browser view. * Build packages * Updated CHANGELOG * Store only if AppState is available instead of every state change * Clean yarn.lock * Update packages/expo-web-browser/CHANGELOG.md Co-Authored-By: Łukasz Kosmaty Co-authored-by: Łukasz Kosmaty Co-authored-by: Brent Vatne --- packages/expo-web-browser/CHANGELOG.md | 13 +++++++++++++ packages/expo-web-browser/build/WebBrowser.js | 9 +++++++++ packages/expo-web-browser/src/WebBrowser.ts | 10 ++++++++++ 3 files changed, 32 insertions(+) create mode 100644 packages/expo-web-browser/CHANGELOG.md diff --git a/packages/expo-web-browser/CHANGELOG.md b/packages/expo-web-browser/CHANGELOG.md new file mode 100644 index 0000000000000..ab076e05ee176 --- /dev/null +++ b/packages/expo-web-browser/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +## master + +### 🛠 Breaking changes + +### 🎉 New features + +- Add `readerMode` and `dismissButtonStyle` (iOS) and `enableDefaultShare` (Android) flags for `WebBrowser` ([#7221](https://github.com/expo/expo/pull/7221) by [@LinusU](https://github.com/LinusU)) & [@mczernek](https://github.com/mczernek)) + +### 🐛 Bug fixes + +- Fix `WebBrowser` sending `dismiss` before opening. ([#6743](https://github.com/expo/expo/pull/6743) by [@LucaColonnello](https://github.com/LucaColonnello)) diff --git a/packages/expo-web-browser/build/WebBrowser.js b/packages/expo-web-browser/build/WebBrowser.js index 91daac423d968..832e842a5f86c 100644 --- a/packages/expo-web-browser/build/WebBrowser.js +++ b/packages/expo-web-browser/build/WebBrowser.js @@ -106,7 +106,16 @@ let _redirectHandler = null; // Store the `resolve` function from a Promise to fire when the AppState // returns to active let _onWebBrowserCloseAndroid = null; +// If the initial AppState.currentState is null, we assume that the first call to +// AppState#change event is not actually triggered by a real change, +// is triggered instead by the bridge capturing the current state +// (https://facebook.github.io/react-native/docs/appstate#basic-usage) +let _isAppStateAvailable = AppState.currentState !== null; function _onAppStateChangeAndroid(state) { + if (!_isAppStateAvailable) { + _isAppStateAvailable = true; + return; + } if (state === 'active' && _onWebBrowserCloseAndroid) { _onWebBrowserCloseAndroid(); } diff --git a/packages/expo-web-browser/src/WebBrowser.ts b/packages/expo-web-browser/src/WebBrowser.ts index 37ee736ffcb01..03915912d66b8 100644 --- a/packages/expo-web-browser/src/WebBrowser.ts +++ b/packages/expo-web-browser/src/WebBrowser.ts @@ -149,7 +149,17 @@ let _redirectHandler: ((event: RedirectEvent) => void) | null = null; // returns to active let _onWebBrowserCloseAndroid: null | (() => void) = null; +// If the initial AppState.currentState is null, we assume that the first call to +// AppState#change event is not actually triggered by a real change, +// is triggered instead by the bridge capturing the current state +// (https://facebook.github.io/react-native/docs/appstate#basic-usage) +let _isAppStateAvailable: boolean = AppState.currentState !== null; function _onAppStateChangeAndroid(state: AppStateStatus) { + if (!_isAppStateAvailable) { + _isAppStateAvailable = true; + return; + } + if (state === 'active' && _onWebBrowserCloseAndroid) { _onWebBrowserCloseAndroid(); }