Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SettingsLanguageRouteScreen.tsx

58 lines2.3 KB

1import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2import { useAtomSet, useAtomValue } from "@effect/atom-react";
3import { AsyncResult } from "effect/reactivity";
4import { useSafeAreaInsets } from "react-native-safe-area-context";
5​
6import { I18nProvider, useGT, useLanguagePreference } from "../../i18n/I18nProvider";
7import { SYSTEM_LANGUAGE, nativeLanguageName } from "@t3tools/client-runtime/locales";
8import { SUPPORTED_LOCALES } from "../../i18n/locales";
9import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
10import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
11import { SettingsSection } from "./components/SettingsSection";
12import { SettingsScreen } from "./components/SettingsScreen";
13​
14export function SettingsLanguageRouteScreen() {
15 return (
16 <I18nProvider>
17 <LanguageSettings />
18 </I18nProvider>
19 );
21​
22function LanguageSettings() {
23 const gt = useGT();
24 const insets = useSafeAreaInsets();
25 const preferencesResult = useAtomValue(mobilePreferencesAtom);
26 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
27 const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
28 const language = useLanguagePreference();
29 const options = [
30 { language: SYSTEM_LANGUAGE, label: gt("System default") },
31 ...SUPPORTED_LOCALES.map((locale) => ({ language: locale, label: nativeLanguageName(locale) })),
32 ];
33​
34 return (
35 <SettingsScreen title={gt("Language")}>
36 <ScrollView
37 contentInsetAdjustmentBehavior="automatic"
38 showsVerticalScrollIndicator={false}
39 className="flex-1"
40 contentContainerClassName="gap-3 px-5 pt-4"
41 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
42 >
43 <SettingsSection>
44 {options.map((option, index) => (
45 <SettingsChoiceRow
46 key={option.language}
47 label={option.label}
48 selected={preferencesReady && language === option.language}
49 separated={index > 0}
50 disabled={!preferencesReady}
51 onPress={() => savePreferences({ language: option.language })}
52 />
53 ))}
54 </SettingsSection>
55 </ScrollView>
56 </SettingsScreen>
57 );