disable changing the system background

This commit is contained in:
Samuel Newman
2024-10-03 09:57:14 +03:00
parent f5b2fe7558
commit 1cbc0fc8a0
2 changed files with 18 additions and 55 deletions
+5 -3
View File
@@ -2,8 +2,8 @@ import React from 'react'
import {ColorSchemeName, useColorScheme} from 'react-native' import {ColorSchemeName, useColorScheme} from 'react-native'
import * as SystemUI from 'expo-system-ui' import * as SystemUI from 'expo-system-ui'
import {isWeb} from 'platform/detection' import {isIOS, isWeb} from '#/platform/detection'
import {useThemePrefs} from 'state/shell' import {useThemePrefs} from '#/state/shell'
import {dark, dim, light} from '#/alf/themes' import {dark, dim, light} from '#/alf/themes'
import {ThemeName} from '#/alf/types' import {ThemeName} from '#/alf/types'
@@ -12,7 +12,9 @@ export function useColorModeTheme(): ThemeName {
React.useLayoutEffect(() => { React.useLayoutEffect(() => {
updateDocument(theme) updateDocument(theme)
SystemUI.setBackgroundColorAsync(getBackgroundColor(theme)) if (!isIOS) {
SystemUI.setBackgroundColorAsync(getBackgroundColor(theme))
}
}, [theme]) }, [theme])
return theme return theme
+13 -52
View File
@@ -1,11 +1,9 @@
import React, {useLayoutEffect} from 'react' import React from 'react'
import {Modal, View} from 'react-native' import {Modal, View} from 'react-native'
import {StatusBar} from 'expo-status-bar' import {StatusBar} from 'expo-status-bar'
import * as SystemUI from 'expo-system-ui'
import {useComposerState} from '#/state/shell/composer' import {useComposerState} from '#/state/shell/composer'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {getBackgroundColor, useThemeName} from '#/alf/util/useColorModeTheme'
import {ComposePost, useComposerCancelRef} from '../com/composer/Composer' import {ComposePost, useComposerCancelRef} from '../com/composer/Composer'
export function Composer({}: {winHeight: number}) { export function Composer({}: {winHeight: number}) {
@@ -24,56 +22,19 @@ export function Composer({}: {winHeight: number}) {
animationType="slide" animationType="slide"
onRequestClose={() => ref.current?.onPressCancel()}> onRequestClose={() => ref.current?.onPressCancel()}>
<View style={[t.atoms.bg, a.flex_1]}> <View style={[t.atoms.bg, a.flex_1]}>
<Providers open={open}> <ComposePost
<ComposePost cancelRef={ref}
cancelRef={ref} replyTo={state?.replyTo}
replyTo={state?.replyTo} onPost={state?.onPost}
onPost={state?.onPost} quote={state?.quote}
quote={state?.quote} quoteCount={state?.quoteCount}
quoteCount={state?.quoteCount} mention={state?.mention}
mention={state?.mention} text={state?.text}
text={state?.text} imageUris={state?.imageUris}
imageUris={state?.imageUris} videoUri={state?.videoUri}
videoUri={state?.videoUri} />
/> {open ? <StatusBar style="light" animated /> : null}
</Providers>
</View> </View>
</Modal> </Modal>
) )
} }
function Providers({
children,
open,
}: {
children: React.ReactNode
open: boolean
}) {
// on iOS, it's a native formSheet. We use FullWindowOverlay to make
// the dialogs appear over it
return (
<>
{children}
<IOSModalBackground active={open} />
</>
)
}
// Generally, the backdrop of the app is the theme color, but when this is open
// we want it to be black due to the modal being a form sheet.
function IOSModalBackground({active}: {active: boolean}) {
const theme = useThemeName()
useLayoutEffect(() => {
SystemUI.setBackgroundColorAsync('black')
return () => {
SystemUI.setBackgroundColorAsync(getBackgroundColor(theme))
}
}, [theme])
// Set the status bar to light - however, only if the modal is active
// If we rely on this component being mounted to set this,
// there'll be a delay before it switches back to default.
return active ? <StatusBar style="light" animated /> : null
}