Repository navigation
Update splash screen logic #6478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| <resources> | ||
| <resources xmlns:tools="http://schemas.android.com/tools"> | ||
|
|
||
| <!-- Base application theme. --> | ||
| <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> | ||
|
|
@@ -7,7 +7,7 @@ | |
| <item name="android:colorEdgeEffect">@color/gray4</item> | ||
| <item name="colorAccent">@color/accent</item> | ||
| <item name="android:statusBarColor">@color/white</item> | ||
| <item name="android:windowLightStatusBar">true</item> | ||
| <item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| </style> | ||
|
|
||
| <style name="BootTheme" parent="AppTheme"> | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,15 +2,14 @@ import _ from 'underscore'; | |
| import lodashGet from 'lodash/get'; | ||
| import PropTypes from 'prop-types'; | ||
| import React, {PureComponent} from 'react'; | ||
| import {View, AppState} from 'react-native'; | ||
| import {AppState} from 'react-native'; | ||
| import Onyx, {withOnyx} from 'react-native-onyx'; | ||
|
|
||
| import BootSplash from './libs/BootSplash'; | ||
| import * as ActiveClientManager from './libs/ActiveClientManager'; | ||
| import ONYXKEYS from './ONYXKEYS'; | ||
| import NavigationRoot from './libs/Navigation/NavigationRoot'; | ||
| import migrateOnyx from './libs/migrateOnyx'; | ||
| import styles from './styles/styles'; | ||
| import PushNotification from './libs/Notification/PushNotification'; | ||
| import UpdateAppModal from './components/UpdateAppModal'; | ||
| import Visibility from './libs/Visibility'; | ||
|
|
@@ -67,10 +66,12 @@ class Expensify extends PureComponent { | |
|
|
||
| // Initialize this client as being an active client | ||
| ActiveClientManager.init(); | ||
| this.hideSplash = this.hideSplash.bind(this); | ||
| this.setNavigationReady = this.setNavigationReady.bind(this); | ||
| this.initializeClient = this.initializeClient.bind(true); | ||
| this.state = { | ||
| isNavigationReady: false, | ||
| isOnyxMigrated: false, | ||
| isSplashShown: true, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -84,12 +85,8 @@ class Expensify extends PureComponent { | |
| // Run any Onyx schema migrations and then continue loading the main app | ||
| migrateOnyx() | ||
| .then(() => { | ||
| // When we don't have an authToken we'll want to show the sign in screen immediately so we'll hide our | ||
| // boot screen right away | ||
| if (!this.getAuthToken()) { | ||
| this.hideSplash(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We wait for |
||
|
|
||
| // In case of a crash that led to disconnection, we want to remove all the push notifications. | ||
| // In case of a crash that led to disconnection, we want to remove all the push notifications. | ||
| if (!this.isAuthenticated()) { | ||
| PushNotification.clearNotifications(); | ||
| } | ||
|
|
||
|
|
@@ -102,28 +99,37 @@ class Expensify extends PureComponent { | |
| componentDidUpdate(prevProps) { | ||
| const previousAccountID = lodashGet(prevProps, 'session.accountID', null); | ||
| const currentAccountID = lodashGet(this.props, 'session.accountID', null); | ||
|
|
||
| if (currentAccountID && (currentAccountID !== previousAccountID)) { | ||
| PushNotification.register(currentAccountID); | ||
| } | ||
|
|
||
| // If we previously had no authToken and now have an authToken we'll want to reshow the boot splash screen so | ||
| // that we can remove it again once the content is ready | ||
| const previousAuthToken = lodashGet(prevProps, 'session.authToken', null); | ||
| if (this.getAuthToken() && !previousAuthToken) { | ||
| this.showSplash(); | ||
| } | ||
| if (this.state.isNavigationReady && this.state.isSplashShown) { | ||
| const authStackReady = this.props.initialReportDataLoaded && this.props.isSidebarLoaded; | ||
| const shouldHideSplash = !this.isAuthenticated() || authStackReady; | ||
|
|
||
| if (this.getAuthToken() && this.props.initialReportDataLoaded && this.props.isSidebarLoaded) { | ||
| this.hideSplash(); | ||
| if (shouldHideSplash) { | ||
| BootSplash | ||
| .hide({fade: true}) | ||
| .then(() => this.setState({isSplashShown: false})); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| AppState.removeEventListener('change', this.initializeClient); | ||
| } | ||
|
|
||
| getAuthToken() { | ||
| return lodashGet(this.props, 'session.authToken', null); | ||
| setNavigationReady() { | ||
| this.setState({isNavigationReady: true}); | ||
| } | ||
|
|
||
| /** | ||
| * @returns {boolean} | ||
| */ | ||
| isAuthenticated() { | ||
|
zoontek marked this conversation as resolved.
Resolved
|
||
| const authToken = lodashGet(this.props, 'session.authToken', null); | ||
| return Boolean(authToken); | ||
| } | ||
|
|
||
| initializeClient() { | ||
|
|
@@ -134,25 +140,15 @@ class Expensify extends PureComponent { | |
| ActiveClientManager.init(); | ||
| } | ||
|
|
||
| showSplash() { | ||
| Log.info('[BootSplash] showing splash screen', false); | ||
| BootSplash.show({fade: true}); | ||
| } | ||
|
|
||
| hideSplash() { | ||
| Log.info('[BootSplash] hiding splash screen', false); | ||
| BootSplash.hide({fade: true}) | ||
| .catch(error => Log.alert('[BootSplash] hiding failed', {message: error.message, error}, false)); | ||
| } | ||
|
|
||
| reportBootSplashStatus() { | ||
| BootSplash.getVisibilityStatus() | ||
| BootSplash | ||
| .getVisibilityStatus() | ||
| .then((status) => { | ||
| Log.info('[BootSplash] splash screen status', false, {status}); | ||
|
|
||
| if (status === 'visible') { | ||
| const props = _.omit(this.props, ['children', 'session']); | ||
| props.hasAuthToken = !_.isEmpty(this.getAuthToken()); | ||
| props.isAuthenticated = this.isAuthenticated(); | ||
| Log.alert('[BootSplash] splash screen is still visible', {props}, false); | ||
| } | ||
| }); | ||
|
|
@@ -161,16 +157,23 @@ class Expensify extends PureComponent { | |
| render() { | ||
| // Display a blank page until the onyx migration completes | ||
| if (!this.state.isOnyxMigrated) { | ||
| return ( | ||
| <View style={styles.genericView} /> | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <GrowlNotification ref={Growl.growlRef} /> | ||
| {/* We include the modal for showing a new update at the top level so the option is always present. */} | ||
| {this.props.updateAvailable ? <UpdateAppModal /> : null} | ||
| <NavigationRoot authenticated={Boolean(this.getAuthToken())} /> | ||
| {!this.state.isSplashShown && ( | ||
| <> | ||
| <GrowlNotification ref={Growl.growlRef} /> | ||
| {/* We include the modal for showing a new update at the top level so the option is always present. */} | ||
| {this.props.updateAvailable ? <UpdateAppModal /> : null} | ||
| </> | ||
| )} | ||
|
|
||
| <NavigationRoot | ||
| onReady={this.setNavigationReady} | ||
| authenticated={this.isAuthenticated()} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| export default { | ||
| hide: () => Promise.resolve(), | ||
| show: () => Promise.resolve(), | ||
| getVisibilityStatus: () => Promise.resolve('hidden'), | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,19 @@ | ||
| import RNBootSplash from 'react-native-bootsplash'; | ||
| import Log from '../Log'; | ||
|
|
||
| export default RNBootSplash; | ||
| // react-native-bootsplash 3.x could reject if not init (ex: when opening app via iOS >= 15 notifications) | ||
| // As the splash screen is not visible on these cases, we chose to ignore these errors. | ||
| function hide(config) { | ||
| Log.info('[BootSplash] hiding splash screen', false); | ||
|
|
||
| return RNBootSplash | ||
| .hide(config) | ||
| .catch((error) => { | ||
| Log.alert('[BootSplash] hiding failed', {message: error.message, error}, false); | ||
| }); | ||
| } | ||
|
|
||
| export default { | ||
| hide, | ||
| getVisibilityStatus: RNBootSplash.getVisibilityStatus, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix status bar being a different color than the splash screen background.