Skip to content

Commit

Permalink
Improve splash display on android (#3105)
Browse files Browse the repository at this point in the history
* Set window background during startup on android

* Set statusbar color to transparent and fine-tune it
  • Loading branch information
edo-bari-ikutsu authored Mar 6, 2024
1 parent 317e0cd commit 26fc0cf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ const DARK_SPLASH_CONFIG = {
resizeMode: 'cover',
}

const SPLASH_CONFIG_ANDROID = {
backgroundColor: '#0c7cff',
image: './assets/splash.png',
resizeMode: 'cover',
}
const DARK_SPLASH_CONFIG_ANDROID = {
backgroundColor: '#0f141b',
image: './assets/splash-dark.png',
resizeMode: 'cover',
}

module.exports = function (config) {
/**
* App version number. Should be incremented as part of a release cycle.
Expand Down Expand Up @@ -70,8 +81,8 @@ module.exports = function (config) {
},
},
androidStatusBar: {
barStyle: 'dark-content',
backgroundColor: '#ffffff',
barStyle: 'light-content',
backgroundColor: '#00000000',
},
android: {
icon: './assets/icon.png',
Expand Down Expand Up @@ -101,8 +112,8 @@ module.exports = function (config) {
},
],
splash: {
...SPLASH_CONFIG,
dark: DARK_SPLASH_CONFIG,
...SPLASH_CONFIG_ANDROID,
dark: DARK_SPLASH_CONFIG_ANDROID,
},
},
web: {
Expand Down Expand Up @@ -146,6 +157,7 @@ module.exports = function (config) {
},
],
'./plugins/withAndroidManifestPlugin.js',
'./plugins/withAndroidStylesWindowBackgroundPlugin.js',
'./plugins/shareExtension/withShareExtensions.js',
].filter(Boolean),
extra: {
Expand Down
20 changes: 20 additions & 0 deletions plugins/withAndroidStylesWindowBackgroundPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const {withAndroidStyles, AndroidConfig} = require('@expo/config-plugins')

module.exports = function withAndroidStylesWindowBackgroundPlugin(appConfig) {
return withAndroidStyles(appConfig, function (decoratedAppConfig) {
try {
decoratedAppConfig.modResults = AndroidConfig.Styles.assignStylesValue(
decoratedAppConfig.modResults,
{
add: true,
parent: AndroidConfig.Styles.getAppThemeLightNoActionBarGroup(),
name: 'android:windowBackground',
value: '@drawable/splashscreen',
},
)
} catch (e) {
console.error(`withAndroidStylesWindowBackgroundPlugin failed`, e)
}
return decoratedAppConfig
})
}
3 changes: 3 additions & 0 deletions src/App.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import {Provider as PortalProvider} from '#/components/Portal'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useIntentHandler} from 'lib/hooks/useIntentHandler'
import {StatusBar} from 'expo-status-bar'
import {isAndroid} from 'platform/detection'

SplashScreen.preventAutoHideAsync()

Expand All @@ -69,6 +71,7 @@ function InnerApp() {

return (
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
{isAndroid && <StatusBar />}
<Alf theme={theme}>
<Splash isReady={!isInitialLoad}>
<React.Fragment
Expand Down

0 comments on commit 26fc0cf

Please sign in to comment.