forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useCallback, useLayoutEffect, useState} from 'react'
2import {LayoutAnimationConfig} from 'react-native-reanimated'
3import {msg} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5import {usePreventRemove} from '@react-navigation/native'
6
7import {useEnableKeyboardControllerScreen} from '#/lib/hooks/useEnableKeyboardController'
8import {
9 type AllNavigatorParams,
10 type NativeStackScreenProps,
11} from '#/lib/routes/types'
12import {useSetMinimalShellMode} from '#/state/shell'
13import {ErrorScreen} from '#/view/com/util/error/ErrorScreen'
14import {FindContactsFlow} from '#/components/contacts/FindContactsFlow'
15import {useFindContactsFlowState} from '#/components/contacts/state'
16import * as Layout from '#/components/Layout'
17import {ScreenTransition} from '#/components/ScreenTransition'
18import {IS_NATIVE} from '#/env'
19
20type Props = NativeStackScreenProps<AllNavigatorParams, 'FindContactsFlow'>
21export function FindContactsFlowScreen({navigation}: Props) {
22 const {_} = useLingui()
23
24 const [state, dispatch] = useFindContactsFlowState()
25
26 const [transitionDirection, setTransitionDirection] = useState<
27 'Forward' | 'Backward'
28 >('Forward')
29
30 const overrideGoBack = state.step === '2: verify number'
31
32 usePreventRemove(overrideGoBack, () => {
33 setTransitionDirection('Backward')
34 dispatch({type: 'BACK'})
35 setTimeout(() => {
36 setTransitionDirection('Forward')
37 })
38 })
39
40 useEnableKeyboardControllerScreen(true)
41
42 const setMinimalShellMode = useSetMinimalShellMode()
43 const effect = useCallback(() => {
44 setMinimalShellMode(true)
45 return () => setMinimalShellMode(false)
46 }, [setMinimalShellMode])
47 useLayoutEffect(effect)
48
49 return (
50 <Layout.Screen>
51 {IS_NATIVE ? (
52 <LayoutAnimationConfig skipEntering skipExiting>
53 <ScreenTransition key={state.step} direction={transitionDirection}>
54 <FindContactsFlow
55 state={state}
56 dispatch={dispatch}
57 onCancel={() =>
58 navigation.canGoBack()
59 ? navigation.goBack()
60 : navigation.navigate('FindContactsFlow', undefined, {
61 pop: true,
62 })
63 }
64 context="Standalone"
65 />
66 </ScreenTransition>
67 </LayoutAnimationConfig>
68 ) : (
69 <ErrorScreen
70 title={_(msg`Not available on this platform.`)}
71 message={_(msg`Please use the native app to sync your contacts.`)}
72 showHeader
73 />
74 )}
75 </Layout.Screen>
76 )
77}