import { FC, useCallback } from "react" import { TextStyle, View, ViewStyle } from "react-native" import { useMMKVString } from "react-native-mmkv" import { Icon } from "@/components/Icon" import { ListItem } from "@/components/ListItem" import { Screen } from "@/components/Screen" import { Text } from "@/components/Text" import { translate } from "@/i18n/translate" import { AppStackScreenProps } from "@/navigators/navigationTypes" import { useAppTheme } from "@/theme/context" import { $styles } from "@/theme/styles" import type { ImmutableThemeContextModeT } from "@/theme/types" import type { ThemedStyle } from "@/theme/types" import { s } from "@/utils/responsive" import { storage } from "@/utils/storage" import { useHeader } from "@/utils/useHeader" type ThemeOption = { value: ImmutableThemeContextModeT | "system" labelKey: string } const THEME_OPTIONS: ThemeOption[] = [ { value: "system", labelKey: "themeScreen:system" }, { value: "light", labelKey: "themeScreen:light" }, { value: "dark", labelKey: "themeScreen:dark" }, ] export const ThemeScreen: FC> = function ThemeScreen({ navigation }) { const { themed, theme, setThemeContextOverride } = useAppTheme() // Read the stored theme preference directly from MMKV // undefined = system, "light" = light, "dark" = dark const [themeScheme] = useMMKVString("ignite.themeScheme", storage) // Determine current selection: if no stored value, it's "system" const currentTheme = themeScheme === "light" || themeScheme === "dark" ? themeScheme : "system" const handleSelectTheme = useCallback( (value: ImmutableThemeContextModeT | "system") => { if (value === "system") { setThemeContextOverride(undefined) } else { setThemeContextOverride(value) } navigation.goBack() }, [setThemeContextOverride, navigation], ) useHeader( { title: translate("themeScreen:title"), leftIcon: "back", onLeftPress: () => navigation.goBack(), }, [], ) return ( {translate("themeScreen:selectHint")} {THEME_OPTIONS.map((option) => { const isSelected = currentTheme === option.value return ( : undefined } onPress={() => handleSelectTheme(option.value)} /> ) })} ) } const $container: ThemedStyle = ({ spacing }) => ({ paddingTop: spacing.md, }) const $hint: ThemedStyle = ({ colors, spacing }) => ({ color: colors.textDim, marginBottom: spacing.md, }) const $listContainer: ThemedStyle = ({ colors }) => ({ backgroundColor: colors.palette.neutral200, borderRadius: s(8), overflow: "hidden", }) const $selectedText: ThemedStyle = ({ colors }) => ({ color: colors.tint, fontWeight: "600", })