-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathChangePasscodeView.tsx
More file actions
88 lines (77 loc) · 2.11 KB
/
ChangePasscodeView.tsx
File metadata and controls
88 lines (77 loc) · 2.11 KB
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
import React, { useEffect, useState } from 'react';
import { StyleSheet } from 'react-native';
import useDeepCompareEffect from 'use-deep-compare-effect';
import isEmpty from 'lodash/isEmpty';
import Modal from 'react-native-modal';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { hasNotch } from '../lib/methods/helpers';
import { PasscodeChoose } from '../containers/Passcode';
import EventEmitter from '../lib/methods/helpers/events';
import { CustomIcon } from '../containers/CustomIcon';
import { CHANGE_PASSCODE_EMITTER } from '../lib/constants/localAuthentication';
import Touch from '../containers/Touch';
const styles = StyleSheet.create({
container: {
flex: 1
},
modal: {
margin: 0
},
close: {
position: 'absolute',
top: hasNotch ? 50 : 30,
left: 15
}
});
interface IArgs {
submit(passcode: string): void;
cancel(): void;
force: boolean;
}
const ChangePasscodeView = React.memo(() => {
const [visible, setVisible] = useState(false);
const [data, setData] = useState<Partial<IArgs>>({});
useDeepCompareEffect(() => {
if (!isEmpty(data)) {
setVisible(true);
} else {
setVisible(false);
}
}, [data]);
const showChangePasscode = (args: IArgs) => {
setData(args);
};
const onSubmit = (passcode: string) => {
const { submit } = data;
if (submit) {
submit(passcode);
}
setData({});
};
const onCancel = () => {
const { cancel } = data;
if (cancel) {
cancel();
}
setData({});
};
useEffect(() => {
const listener = EventEmitter.addEventListener(CHANGE_PASSCODE_EMITTER, showChangePasscode);
return () => {
EventEmitter.removeListener(CHANGE_PASSCODE_EMITTER, listener);
};
}, []);
return (
<Modal useNativeDriver isVisible={visible} hideModalContentWhileAnimating style={styles.modal}>
<GestureHandlerRootView style={styles.container}>
<PasscodeChoose finishProcess={onSubmit} force={data?.force} />
{!data?.force ? (
<Touch onPress={onCancel} style={styles.close}>
<CustomIcon name='close' size={30} />
</Touch>
) : null}
</GestureHandlerRootView>
</Modal>
);
});
export default ChangePasscodeView;