/
ShakeForSupport.tsx
112 lines (104 loc) · 2.93 KB
/
ShakeForSupport.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text } from 'react-native'
import Modal from 'react-native-modal'
import { SafeAreaView } from 'react-native-safe-area-context'
import RNShake from 'react-native-shake'
import { AppState } from 'src/app/actions'
import { appStateSelector } from 'src/app/selectors'
import Button, { BtnTypes } from 'src/components/Button'
import Touchable from 'src/components/Touchable'
import Times from 'src/icons/Times'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { useSelector } from 'src/redux/hooks'
import colors from 'src/styles/colors'
import fontStyles from 'src/styles/fonts'
import variables from 'src/styles/variables'
import Logger from 'src/utils/Logger'
export default function ShakeForSupport() {
const { t } = useTranslation()
const appState = useSelector(appStateSelector)
const [isVisible, setIsVisible] = React.useState(false)
React.useEffect(() => {
if (appState !== AppState.Active) {
// Don't listen to the shake event if the app is not in the foreground
return
}
const subscription = RNShake.addListener(() => {
Logger.info('NavigatorWrapper', 'Shake Event')
// TODO: Cancel all modals before this
setIsVisible(true)
})
return () => {
subscription?.remove()
}
}, [appState])
const onCancelSupport = () => {
setIsVisible(false)
}
const onContactSupport = () => {
setIsVisible(false)
navigate(Screens.SupportContact)
}
return (
<Modal
isVisible={isVisible}
backdropOpacity={0.5}
style={styles.modal}
useNativeDriverForBackdrop={true}
>
<SafeAreaView style={styles.shakeForSupport}>
<Touchable
style={styles.closeButton}
onPress={onCancelSupport}
borderless={true}
hitSlop={variables.iconHitslop}
>
<Times />
</Touchable>
<Text testID="HavingTrouble" style={styles.supportTitle}>
{t('havingTrouble')}
</Text>
<Text testID="ShakeForSupport" style={styles.supportSubtitle}>
{t('shakeForSupport')}
</Text>
<Button
onPress={onContactSupport}
text={t('contactSupport')}
type={BtnTypes.PRIMARY}
testID="ContactSupportFromShake"
/>
</SafeAreaView>
</Modal>
)
}
const styles = StyleSheet.create({
modal: {
margin: 0,
},
shakeForSupport: {
position: 'absolute',
bottom: 0,
width: '100%',
backgroundColor: colors.white,
borderTopLeftRadius: 16,
borderTopRightRadius: 16,
padding: 24,
alignItems: 'center',
},
closeButton: {
alignSelf: 'flex-end',
margin: 2,
},
supportTitle: {
...fontStyles.h2,
marginTop: 16,
},
supportSubtitle: {
...fontStyles.regular,
marginTop: 8,
marginBottom: 16,
textAlign: 'center',
},
})