Skip to content

Commit

Permalink
[android][web-browser] Fix WebBrowser sending 'dismiss' before opening
Browse files Browse the repository at this point in the history
Fixes #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.
  • Loading branch information
LucaColonnello committed Mar 17, 2020
1 parent 774e642 commit 2a5b737
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/expo-web-browser/src/WebBrowser.ts
Expand Up @@ -149,7 +149,18 @@ let _redirectHandler: ((event: RedirectEvent) => void) | null = null;
// returns to active
let _onWebBrowserCloseAndroid: null | (() => void) = null;

// Store previous app state to check whether the listener has ever been attached
let _previousAppState: null | string = AppState.currentState;

function _onAppStateChangeAndroid(state: AppStateStatus) {
// if _previousAppState is null, we assume that the first call to
// AppState#change event is not actually triggered by a real change
// (https://facebook.github.io/react-native/docs/appstate#basic-usage)
if (_previousAppState === null) {
_previousAppState = state;
return;
}

if (state === 'active' && _onWebBrowserCloseAndroid) {
_onWebBrowserCloseAndroid();
}
Expand Down

0 comments on commit 2a5b737

Please sign in to comment.