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
#6743)

* [android][web-browser] Fix WebBrowser sending 'dismiss' before opening

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.

* 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 <lukasz.kosmaty@student.uj.edu.pl>

Co-authored-by: Łukasz Kosmaty <lukasz.kosmaty@student.uj.edu.pl>
Co-authored-by: Brent Vatne <brentvatne@gmail.com>
  • Loading branch information
3 people committed Apr 16, 2020
1 parent 5259b7c commit 3686e36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/expo-web-browser/CHANGELOG.md
Expand Up @@ -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))
9 changes: 9 additions & 0 deletions packages/expo-web-browser/build/WebBrowser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/expo-web-browser/src/WebBrowser.ts
Expand Up @@ -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();
}
Expand Down

0 comments on commit 3686e36

Please sign in to comment.