mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {View} from 'react-native'
3import RNPickerSelect, {PickerSelectProps} from 'react-native-picker-select'
4import {useSafeAreaInsets} from 'react-native-safe-area-context'
5import {msg, Trans} from '@lingui/macro'
6import {useLingui} from '@lingui/react'
7
8import {sanitizeAppLanguageSetting} from '#/locale/helpers'
9import {APP_LANGUAGES} from '#/locale/languages'
10import {useLanguagePrefs, useLanguagePrefsApi} from '#/state/preferences'
11import {Logo} from '#/view/icons/Logo'
12import {Logotype} from '#/view/icons/Logotype'
13import {ErrorBoundary} from 'view/com/util/ErrorBoundary'
14import {atoms as a, useTheme} from '#/alf'
15import {Button, ButtonText} from '#/components/Button'
16import {ChevronBottom_Stroke2_Corner0_Rounded as ChevronDown} from '#/components/icons/Chevron'
17import {Text} from '#/components/Typography'
18import {CenteredView} from '../util/Views'
19
20export const SplashScreen = ({
21 onPressSignin,
22 onPressCreateAccount,
23}: {
24 onPressSignin: () => void
25 onPressCreateAccount: () => void
26}) => {
27 const t = useTheme()
28 const {_} = useLingui()
29
30 const langPrefs = useLanguagePrefs()
31 const setLangPrefs = useLanguagePrefsApi()
32 const insets = useSafeAreaInsets()
33
34 const sanitizedLang = sanitizeAppLanguageSetting(langPrefs.appLanguage)
35
36 const onChangeAppLanguage = React.useCallback(
37 (value: Parameters<PickerSelectProps['onValueChange']>[0]) => {
38 if (!value) return
39 if (sanitizedLang !== value) {
40 setLangPrefs.setAppLanguage(sanitizeAppLanguageSetting(value))
41 }
42 },
43 [sanitizedLang, setLangPrefs],
44 )
45
46 return (
47 <CenteredView style={[a.h_full, a.flex_1]}>
48 <ErrorBoundary>
49 <View style={[{flex: 1}, a.justify_center, a.align_center]}>
50 <Logo width={92} fill="sky" />
51
52 <View style={[a.pb_sm, a.pt_5xl]}>
53 <Logotype width={161} fill={t.atoms.text.color} />
54 </View>
55
56 <Text
57 style={[a.text_md, a.font_semibold, t.atoms.text_contrast_medium]}>
58 <Trans>What's up?</Trans>
59 </Text>
60 </View>
61 <View testID="signinOrCreateAccount">
62 <Button
63 testID="createAccountButton"
64 onPress={onPressCreateAccount}
65 accessibilityRole="button"
66 label={_(msg`Create new account`)}
67 accessibilityHint={_(
68 msg`Opens flow to create a new Bluesky account`,
69 )}
70 style={[a.mx_xl, a.mb_xl]}
71 size="large"
72 variant="solid"
73 color="primary">
74 <ButtonText>
75 <Trans>Create a new account</Trans>
76 </ButtonText>
77 </Button>
78 <Button
79 testID="signInButton"
80 onPress={onPressSignin}
81 label={_(msg`Sign in`)}
82 accessibilityHint={_(
83 msg`Opens flow to sign into your existing Bluesky account`,
84 )}
85 style={[a.mx_xl, a.mb_xl]}
86 size="large"
87 variant="solid"
88 color="secondary">
89 <ButtonText>
90 <Trans>Sign in</Trans>
91 </ButtonText>
92 </Button>
93 </View>
94 <View
95 style={[
96 a.px_lg,
97 a.pt_md,
98 a.pb_2xl,
99 a.justify_center,
100 a.align_center,
101 ]}>
102 <View style={a.relative}>
103 <RNPickerSelect
104 placeholder={{}}
105 value={sanitizedLang}
106 onValueChange={onChangeAppLanguage}
107 items={APP_LANGUAGES.filter(l => Boolean(l.code2)).map(l => ({
108 label: l.name,
109 value: l.code2,
110 key: l.code2,
111 }))}
112 useNativeAndroidPickerStyle={false}
113 style={{
114 inputAndroid: {
115 color: t.atoms.text_contrast_medium.color,
116 fontSize: 16,
117 paddingRight: 12 + 4,
118 },
119 inputIOS: {
120 color: t.atoms.text.color,
121 fontSize: 16,
122 paddingRight: 12 + 4,
123 },
124 }}
125 />
126
127 <View
128 style={[
129 a.absolute,
130 a.inset_0,
131 {left: 'auto'},
132 {pointerEvents: 'none'},
133 a.align_center,
134 a.justify_center,
135 ]}>
136 <ChevronDown fill={t.atoms.text.color} size="xs" />
137 </View>
138 </View>
139 </View>
140 <View style={{height: insets.bottom}} />
141 </ErrorBoundary>
142 </CenteredView>
143 )
144}