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 Jan 12, 2020
1 parent 11a48ca commit 4144dcf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/expo-web-browser/src/WebBrowser.ts
Expand Up @@ -135,12 +135,22 @@ 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();
}
}

async function _openBrowserAndWaitAndroidAsync(startUrl: string): Promise<BrowserResult> {
let appStateChangedToActive = new Promise(resolve => {
_onWebBrowserCloseAndroid = resolve;
Expand Down

0 comments on commit 4144dcf

Please sign in to comment.