Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources>
<color name="bootsplash_background">#FFFFFF</color>
<color name="white">#FAFAFA</color>
<color name="white">#FFFFFF</color>

Copy link
Copy Markdown
Contributor Author

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.

<color name="accent">#0185ff</color>
<color name="dark">#0b1b34</color>
<color name="gray4">#7D8B8F</color>
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/values/styles.xml
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">
Expand All @@ -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>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android:windowLightStatusBar and android:windowLightNavigationBar are not available on Android 21 (the min version), tools:ignore silents the Android studio linter.

</style>

<style name="BootTheme" parent="AppTheme">
Expand Down
4 changes: 2 additions & 2 deletions ios/NewExpensify/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];

[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // <- initialization using the storyboard file name

// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;

[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // <- initialization using the storyboard file name

// Start the "js_load" custom performance tracing metric. This timer is stopped by a native
// module in the JS so we can measure total time starting in the native layer and ending in
// the JS layer.
Expand Down
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ PODS:
- React-perflogger (= 0.64.1)
- rn-fetch-blob (0.12.0):
- React-Core
- RNBootSplash (3.2.0):
- RNBootSplash (3.2.6):
- React-Core
- RNCAsyncStorage (1.15.5):
- React-Core
Expand Down Expand Up @@ -920,7 +920,7 @@ SPEC CHECKSUMS:
React-runtimeexecutor: ff951a0c241bfaefc4940a3f1f1a229e7cb32fa6
ReactCommon: bedc99ed4dae329c4fcf128d0c31b9115e5365ca
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
RNBootSplash: 3123ba68fe44d8be09a014e89cc8f0f55b68a521
RNBootSplash: 00f99e3c05fb44af3613e6088406de4be0a8eca3
RNCAsyncStorage: 8324611026e8dc3706f829953aa6e3899f581589
RNCClipboard: 5e299c6df8e0c98f3d7416b86ae563d3a9f768a3
RNCMaskedView: 138134c4d8a9421b4f2bf39055a79aa05c2d47b1
Expand Down
23 changes: 11 additions & 12 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"react-collapse": "^5.1.0",
"react-dom": "^17.0.2",
"react-native": "0.64.1",
"react-native-bootsplash": "^3.2.0",
"react-native-bootsplash": "^3.2.6",
"react-native-collapsible": "^1.6.0",
"react-native-config": "^1.4.0",
"react-native-document-picker": "^5.1.0",
Expand Down
81 changes: 42 additions & 39 deletions src/Expensify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
};
}

Expand All @@ -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();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wait for react-navigation to be ready. So there's no need to hide the splash screen here.


// 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();
}

Expand All @@ -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() {
Comment thread
zoontek marked this conversation as resolved.
Resolved
const authToken = lodashGet(this.props, 'session.authToken', null);
return Boolean(authToken);
}

initializeClient() {
Expand All @@ -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);
}
});
Expand All @@ -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()}
/>
</>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/ErrorBoundary/BaseErrorBoundary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import BootSplash from '../../libs/BootSplash';

const propTypes = {
/* A message posted to `logError` (along with error data) when this component intercepts an error */
Expand Down Expand Up @@ -34,6 +35,9 @@ class BaseErrorBoundary extends React.Component {

componentDidCatch(error, errorInfo) {
this.props.logError(this.props.errorMessage, error, errorInfo);

// We hide the splash screen since the error might happened during app init
BootSplash.hide({fade: true});
}

render() {
Expand Down
1 change: 0 additions & 1 deletion src/libs/BootSplash/index.js
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'),
};
18 changes: 17 additions & 1 deletion src/libs/BootSplash/index.native.js
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,
};
17 changes: 16 additions & 1 deletion src/libs/Navigation/NavigationRoot.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {getPathFromState, NavigationContainer} from '@react-navigation/native';
import {getPathFromState, NavigationContainer, DefaultTheme} from '@react-navigation/native';
import * as Navigation from './Navigation';
import linkingConfig from './linkingConfig';
import AppNavigator from './AppNavigator';
import * as App from '../actions/App';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import Log from '../Log';
import themeColors from '../../styles/themes/default';

// https://reactnavigation.org/docs/themes
const navigationTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: themeColors.appBG,
},
};

const propTypes = {
/** Whether the current user is logged in with an authToken */
authenticated: PropTypes.bool.isRequired,

/** Fired when react-navigation is ready */
onReady: PropTypes.func.isRequired,
};

class NavigationRoot extends Component {
Expand Down Expand Up @@ -45,6 +58,8 @@ class NavigationRoot extends Component {
<NavigationContainer
fallback={<FullScreenLoadingIndicator />}
onStateChange={this.parseAndStoreRoute}
onReady={this.props.onReady}
theme={navigationTheme}
ref={Navigation.navigationRef}
linking={linkingConfig}
documentTitle={{
Expand Down
11 changes: 0 additions & 11 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,6 @@ const styles = {
marginBottom: 24,
},

genericView: {
backgroundColor: themeColors.heading,
height: '100%',
},

signInPageInner: {
marginLeft: 'auto',
marginRight: 'auto',
Expand Down Expand Up @@ -1127,12 +1122,6 @@ const styles = {
...optionAlternateTextPlatformStyles,
},

// App Content Wrapper styles
appContentWrapper: {
backgroundColor: themeColors.appBG,
color: themeColors.text,
},

appContent: {
backgroundColor: themeColors.appBG,
overflow: 'hidden',
Expand Down