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