diff --git a/packages/expo-web-browser/CHANGELOG.md b/packages/expo-web-browser/CHANGELOG.md index 7544efc39da36..ab076e05ee176 100644 --- a/packages/expo-web-browser/CHANGELOG.md +++ b/packages/expo-web-browser/CHANGELOG.md @@ -9,3 +9,5 @@ - 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 3174d1ceb1290..8959bca90188a 100644 --- a/packages/expo-web-browser/build/WebBrowser.js +++ b/packages/expo-web-browser/build/WebBrowser.js @@ -120,7 +120,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 fa21422a7df5b..7de6ecc51866f 100644 --- a/packages/expo-web-browser/src/WebBrowser.ts +++ b/packages/expo-web-browser/src/WebBrowser.ts @@ -165,7 +165,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(); }