import { ExpoConfig } from '@expo/config-types' ; import assert from 'assert' ; import { ConfigPlugin } from '../Plugin.types' ; import { withAndroidColors , withAndroidStyles } from '../plugins/android-plugins' ; import { assignColorValue } from './Colors' ; import { ResourceXML } from './Resources' ; import { assignStylesValue , getAppThemeLightNoActionBarGroup } from './Styles' ; const COLOR_PRIMARY_DARK_KEY = 'colorPrimaryDark' ; const WINDOW_TRANSLUCENT_STATUS = 'android:windowTranslucentStatus' ; const WINDOW_LIGHT_STATUS_BAR = 'android:windowLightStatusBar' ; export const withStatusBar = config => { config = withStatusBarColors ( config ) ; config = withStatusBarStyles ( config ) ; return config ; } ; const withStatusBarColors = config => { return withAndroidColors ( config , config => { config . modResults = setStatusBarColors ( config , config . modResults ) ; return config ; } ) ; } ; const withStatusBarStyles = config => { return withAndroidStyles ( config , config => { config . modResults = setStatusBarStyles ( config , config . modResults ) ; return config ; } ) ; } ; export function setStatusBarColors ( config , colors ) { return assignColorValue ( colors , { name : COLOR_PRIMARY_DARK_KEY , value : getStatusBarColor ( config ) } ) ; } export function setStatusBarStyles ( config , styles ) { const hexString = getStatusBarColor ( config ) ; const floatElement = getStatusBarTranslucent ( config ) ; styles = assignStylesValue ( styles , { parent : getAppThemeLightNoActionBarGroup ( ) , name : WINDOW_LIGHT_STATUS_BAR , targetApi : '23' , value : 'true' , add : getStatusBarStyle ( config ) === 'dark-content' } ) ; styles = assignStylesValue ( styles , { parent : getAppThemeLightNoActionBarGroup ( ) , name : WINDOW_TRANSLUCENT_STATUS , value : 'true' , add : floatElement } ) ; styles = assignStylesValue ( styles , { parent : getAppThemeLightNoActionBarGroup ( ) , name : COLOR_PRIMARY_DARK_KEY , value : `@color/${ COLOR_PRIMARY_DARK_KEY }` , add : ! ! hexString } ) ; return styles ; } export function getStatusBarColor ( config ) { const backgroundColor = config . androidStatusBar ?. backgroundColor ; if ( backgroundColor ) { assert ( backgroundColor !== 'translucent' , `androidStatusBar.backgroundColor must be a valid hex string, instead got: "${ backgroundColor }"` ) ; } return backgroundColor ; } default param config returns export function getStatusBarTranslucent ( config ) { return config . androidStatusBar ?. translucent ?? false ; } export function getStatusBarStyle ( config ) { return config . androidStatusBar ?. barStyle || 'light-content' ; }