2020-05-08 17:04:37 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
import useDeepCompareEffect from 'use-deep-compare-effect';
|
2021-02-01 17:18:55 +00:00
|
|
|
import isEmpty from 'lodash/isEmpty';
|
2020-05-08 17:04:37 +00:00
|
|
|
import Orientation from 'react-native-orientation-locker';
|
|
|
|
|
|
|
|
import { withTheme } from '../theme';
|
|
|
|
import EventEmitter from '../utils/events';
|
|
|
|
import { LOCAL_AUTHENTICATE_EMITTER } from '../constants/localAuthentication';
|
|
|
|
import { isTablet } from '../utils/deviceInfo';
|
|
|
|
import { PasscodeEnter } from '../containers/Passcode';
|
|
|
|
|
|
|
|
const ScreenLockedView = ({ theme }) => {
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const [data, setData] = useState({});
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
|
|
|
const showScreenLock = (args) => {
|
|
|
|
setData(args);
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isTablet) {
|
|
|
|
Orientation.lockToPortrait();
|
|
|
|
}
|
2021-02-23 19:00:39 +00:00
|
|
|
const listener = EventEmitter.addEventListener(LOCAL_AUTHENTICATE_EMITTER, showScreenLock);
|
2020-05-08 17:04:37 +00:00
|
|
|
return (() => {
|
|
|
|
if (!isTablet) {
|
|
|
|
Orientation.unlockAllOrientations();
|
|
|
|
}
|
2021-02-23 19:00:39 +00:00
|
|
|
EventEmitter.removeListener(LOCAL_AUTHENTICATE_EMITTER, listener);
|
2020-05-08 17:04:37 +00:00
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const onSubmit = () => {
|
|
|
|
const { submit } = data;
|
|
|
|
if (submit) {
|
|
|
|
submit();
|
|
|
|
}
|
|
|
|
setData({});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
useNativeDriver
|
|
|
|
isVisible={visible}
|
|
|
|
hideModalContentWhileAnimating
|
|
|
|
style={{ margin: 0 }}
|
|
|
|
animationIn='fadeIn'
|
|
|
|
animationOut='fadeOut'
|
|
|
|
>
|
|
|
|
<PasscodeEnter theme={theme} hasBiometry={data?.hasBiometry} finishProcess={onSubmit} />
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ScreenLockedView.propTypes = {
|
|
|
|
theme: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withTheme(ScreenLockedView);
|