2022-05-03 20:29:00 +00:00
|
|
|
import isEmpty from 'lodash/isEmpty';
|
2020-05-08 17:04:37 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2022-05-03 20:29:00 +00:00
|
|
|
import { StyleSheet } from 'react-native';
|
2020-05-08 17:04:37 +00:00
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
import Orientation from 'react-native-orientation-locker';
|
2022-05-03 20:29:00 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
import useDeepCompareEffect from 'use-deep-compare-effect';
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
import { PasscodeEnter } from '../containers/Passcode';
|
2022-05-03 20:29:00 +00:00
|
|
|
import { LOCAL_AUTHENTICATE_EMITTER } from '../lib/constants';
|
|
|
|
import { CustomIcon } from '../containers/CustomIcon';
|
|
|
|
import { useTheme } from '../theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { hasNotch, isTablet } from '../lib/methods/helpers';
|
|
|
|
import EventEmitter from '../lib/methods/helpers/events';
|
2020-05-08 17:04:37 +00:00
|
|
|
|
2021-12-02 13:26:02 +00:00
|
|
|
interface IData {
|
|
|
|
submit?: () => void;
|
2022-05-03 20:29:00 +00:00
|
|
|
cancel?: () => void;
|
2021-12-02 13:26:02 +00:00
|
|
|
hasBiometry?: boolean;
|
2022-05-03 20:29:00 +00:00
|
|
|
force?: boolean;
|
2021-12-02 13:26:02 +00:00
|
|
|
}
|
|
|
|
|
2022-05-03 20:29:00 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
close: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: hasNotch ? 50 : 30,
|
|
|
|
left: 15
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-02 13:26:02 +00:00
|
|
|
const ScreenLockedView = (): JSX.Element => {
|
2020-05-08 17:04:37 +00:00
|
|
|
const [visible, setVisible] = useState(false);
|
2021-12-02 13:26:02 +00:00
|
|
|
const [data, setData] = useState<IData>({});
|
2022-05-03 20:29:00 +00:00
|
|
|
const { colors } = useTheme();
|
2021-12-02 13:26:02 +00:00
|
|
|
|
2020-05-08 17:04:37 +00:00
|
|
|
useDeepCompareEffect(() => {
|
2021-02-01 17:18:55 +00:00
|
|
|
if (!isEmpty(data)) {
|
2020-05-08 17:04:37 +00:00
|
|
|
setVisible(true);
|
|
|
|
} else {
|
|
|
|
setVisible(false);
|
|
|
|
}
|
|
|
|
}, [data]);
|
|
|
|
|
2021-12-02 13:26:02 +00:00
|
|
|
const showScreenLock = (args: IData) => {
|
2020-05-08 17:04:37 +00:00
|
|
|
setData(args);
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isTablet) {
|
|
|
|
Orientation.lockToPortrait();
|
|
|
|
}
|
2021-02-23 19:00:39 +00:00
|
|
|
const listener = EventEmitter.addEventListener(LOCAL_AUTHENTICATE_EMITTER, showScreenLock);
|
2021-09-13 20:41:05 +00:00
|
|
|
return () => {
|
2020-05-08 17:04:37 +00:00
|
|
|
if (!isTablet) {
|
|
|
|
Orientation.unlockAllOrientations();
|
|
|
|
}
|
2021-02-23 19:00:39 +00:00
|
|
|
EventEmitter.removeListener(LOCAL_AUTHENTICATE_EMITTER, listener);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-05-08 17:04:37 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onSubmit = () => {
|
|
|
|
const { submit } = data;
|
|
|
|
if (submit) {
|
|
|
|
submit();
|
|
|
|
}
|
|
|
|
setData({});
|
|
|
|
};
|
|
|
|
|
2022-05-03 20:29:00 +00:00
|
|
|
const onCancel = () => {
|
|
|
|
const { cancel } = data;
|
|
|
|
if (cancel) {
|
|
|
|
cancel();
|
|
|
|
}
|
|
|
|
setData({});
|
|
|
|
};
|
|
|
|
|
2020-05-08 17:04:37 +00:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
useNativeDriver
|
|
|
|
isVisible={visible}
|
|
|
|
hideModalContentWhileAnimating
|
|
|
|
style={{ margin: 0 }}
|
|
|
|
animationIn='fadeIn'
|
2022-08-08 21:02:08 +00:00
|
|
|
animationOut='fadeOut'
|
|
|
|
>
|
2022-03-23 00:43:59 +00:00
|
|
|
<PasscodeEnter hasBiometry={!!data?.hasBiometry} finishProcess={onSubmit} />
|
2022-05-03 20:29:00 +00:00
|
|
|
{data?.force ? (
|
|
|
|
<Touchable onPress={onCancel} style={styles.close}>
|
|
|
|
<CustomIcon name='close' color={colors.passcodePrimary} size={30} />
|
|
|
|
</Touchable>
|
|
|
|
) : null}
|
2020-05-08 17:04:37 +00:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-12-02 13:26:02 +00:00
|
|
|
export default ScreenLockedView;
|