mirror of
https://github.com/tooot-app/app
synced 2025-02-13 02:10:39 +01:00
Fix theme changing issue
This commit is contained in:
parent
fb8bb54989
commit
dd7b9cd6a2
@ -4,7 +4,7 @@
|
|||||||
"native": "220214",
|
"native": "220214",
|
||||||
"major": 3,
|
"major": 3,
|
||||||
"minor": 5,
|
"minor": 5,
|
||||||
"patch": 0,
|
"patch": 1,
|
||||||
"expo": "44.0.0"
|
"expo": "44.0.0"
|
||||||
},
|
},
|
||||||
"description": "tooot app for Mastodon",
|
"description": "tooot app for Mastodon",
|
||||||
|
@ -40,11 +40,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
|||||||
const { t } = useTranslation('screens')
|
const { t } = useTranslation('screens')
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const instanceActive = useSelector(getInstanceActive)
|
const instanceActive = useSelector(getInstanceActive)
|
||||||
const { colors, mode, theme } = useTheme()
|
const { colors, theme } = useTheme()
|
||||||
enum barStyle {
|
|
||||||
light = 'dark-content',
|
|
||||||
dark = 'light-content'
|
|
||||||
}
|
|
||||||
|
|
||||||
const routeRef = useRef<{ name?: string; params?: {} }>()
|
const routeRef = useRef<{ name?: string; params?: {} }>()
|
||||||
|
|
||||||
@ -163,10 +159,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StatusBar
|
<StatusBar backgroundColor={colors.backgroundDefault} />
|
||||||
barStyle={barStyle[mode]}
|
|
||||||
backgroundColor={colors.backgroundDefault}
|
|
||||||
/>
|
|
||||||
<NavigationContainer
|
<NavigationContainer
|
||||||
ref={navigationRef}
|
ref={navigationRef}
|
||||||
theme={themes[theme]}
|
theme={themes[theme]}
|
||||||
|
@ -127,7 +127,7 @@ const ScreenImagesViewer = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaProvider>
|
<SafeAreaProvider>
|
||||||
<StatusBar backgroundColor='rgb(0,0,0)' />
|
<StatusBar hidden />
|
||||||
<ImageViewer
|
<ImageViewer
|
||||||
images={imageUrls}
|
images={imageUrls}
|
||||||
imageIndex={initialIndex}
|
imageIndex={initialIndex}
|
||||||
|
@ -31,7 +31,7 @@ const Tab = createBottomTabNavigator<ScreenTabsStackParamList>()
|
|||||||
|
|
||||||
const ScreenTabs = React.memo(
|
const ScreenTabs = React.memo(
|
||||||
({ navigation }: RootStackScreenProps<'Screen-Tabs'>) => {
|
({ navigation }: RootStackScreenProps<'Screen-Tabs'>) => {
|
||||||
const { colors } = useTheme()
|
const { colors, theme } = useTheme()
|
||||||
|
|
||||||
const instanceActive = useSelector(getInstanceActive)
|
const instanceActive = useSelector(getInstanceActive)
|
||||||
const instanceAccount = useSelector(
|
const instanceAccount = useSelector(
|
||||||
@ -87,7 +87,7 @@ const ScreenTabs = React.memo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
[instanceAccount?.avatarStatic, instanceActive]
|
[instanceAccount?.avatarStatic, instanceActive, theme]
|
||||||
)
|
)
|
||||||
|
|
||||||
const composeListeners = useMemo(
|
const composeListeners = useMemo(
|
||||||
|
@ -23,7 +23,7 @@ const Stack = createNativeStackNavigator<TabPublicStackParamList>()
|
|||||||
const TabPublic = React.memo(
|
const TabPublic = React.memo(
|
||||||
({ navigation }: ScreenTabsScreenProps<'Tab-Public'>) => {
|
({ navigation }: ScreenTabsScreenProps<'Tab-Public'>) => {
|
||||||
const { t, i18n } = useTranslation('screenTabs')
|
const { t, i18n } = useTranslation('screenTabs')
|
||||||
const { mode } = useTheme()
|
const { mode, theme } = useTheme()
|
||||||
|
|
||||||
const [segment, setSegment] = useState(0)
|
const [segment, setSegment] = useState(0)
|
||||||
const pages: {
|
const pages: {
|
||||||
@ -67,7 +67,7 @@ const TabPublic = React.memo(
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
[mode, segment, i18n.language]
|
[theme, segment, i18n.language]
|
||||||
)
|
)
|
||||||
|
|
||||||
const routes = pages.map(p => ({ key: p.key }))
|
const routes = pages.map(p => ({ key: p.key }))
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
import React, {
|
import React, { createContext, useContext, useEffect, useState } from 'react'
|
||||||
createContext,
|
|
||||||
useContext,
|
|
||||||
useEffect,
|
|
||||||
useRef,
|
|
||||||
useState
|
|
||||||
} from 'react'
|
|
||||||
import { Appearance } from 'react-native'
|
import { Appearance } from 'react-native'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
import { ColorDefinitions, getColors, Theme } from '@utils/styles/themes'
|
import { ColorDefinitions, getColors, Theme } from '@utils/styles/themes'
|
||||||
@ -85,25 +79,23 @@ const ThemeManager: React.FC = ({ children }) => {
|
|||||||
const userTheme = useSelector(getSettingsTheme)
|
const userTheme = useSelector(getSettingsTheme)
|
||||||
const darkTheme = useSelector(getSettingsDarkTheme)
|
const darkTheme = useSelector(getSettingsDarkTheme)
|
||||||
|
|
||||||
const mode = useRef(userTheme === 'auto' ? osTheme || 'light' : userTheme)
|
const [mode, setMode] = useState(
|
||||||
|
userTheme === 'auto' ? osTheme || 'light' : userTheme
|
||||||
|
)
|
||||||
const [theme, setTheme] = useState<Theme>(
|
const [theme, setTheme] = useState<Theme>(
|
||||||
determineTheme(osTheme, userTheme, darkTheme)
|
determineTheme(osTheme, userTheme, darkTheme)
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mode.current = userTheme === 'auto' ? osTheme || 'light' : userTheme
|
setMode(userTheme === 'auto' ? osTheme || 'light' : userTheme)
|
||||||
}, [userTheme])
|
}, [osTheme, userTheme])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTheme(determineTheme(osTheme, userTheme, darkTheme))
|
setTheme(determineTheme(osTheme, userTheme, darkTheme))
|
||||||
}, [osTheme, userTheme, darkTheme])
|
}, [osTheme, userTheme, darkTheme])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ManageThemeContext.Provider
|
<ManageThemeContext.Provider
|
||||||
value={{
|
value={{ mode, theme, colors: getColors(theme) }}
|
||||||
mode: mode.current,
|
|
||||||
theme,
|
|
||||||
colors: getColors(theme)
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</ManageThemeContext.Provider>
|
</ManageThemeContext.Provider>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user