Rocket.Chat.ReactNative/app/views/ScreenLockedView.js

83 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-04-17 19:11:06 +00:00
import React, { useEffect, useState } from 'react';
2020-04-13 20:36:39 +00:00
import {
2020-04-23 21:50:49 +00:00
View, StyleSheet
2020-04-13 20:36:39 +00:00
} from 'react-native';
2020-04-22 16:34:53 +00:00
import PropTypes from 'prop-types';
2020-04-17 19:11:06 +00:00
import Modal from 'react-native-modal';
import useDeepCompareEffect from 'use-deep-compare-effect';
import _ from 'lodash';
2020-04-23 19:37:00 +00:00
import Orientation from 'react-native-orientation-locker';
2020-04-13 20:36:39 +00:00
2020-04-23 19:37:00 +00:00
// import I18n from '../i18n';
2020-04-13 20:36:39 +00:00
import { withTheme } from '../theme';
import { themes } from '../constants/colors';
2020-04-17 19:11:06 +00:00
import EventEmitter from '../utils/events';
2020-04-23 19:37:00 +00:00
// import sharedStyles from './Styles';
2020-04-17 19:11:06 +00:00
import { withSplit } from '../split';
2020-04-23 19:37:00 +00:00
import { LOCAL_AUTHENTICATE_EMITTER } from '../constants/localAuthentication';
import { isTablet } from '../utils/deviceInfo';
2020-04-23 20:11:17 +00:00
import { PasscodeEnter } from '../containers/Passcode';
2020-04-23 18:28:40 +00:00
import { TYPE } from '../containers/Passcode/constants';
2020-04-13 20:36:39 +00:00
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
2020-04-22 16:34:53 +00:00
width: '100%'
2020-04-13 20:36:39 +00:00
}
});
2020-04-22 16:34:53 +00:00
const ScreenLockedView = ({ theme }) => {
2020-04-17 19:11:06 +00:00
const [visible, setVisible] = useState(false);
const [data, setData] = useState({});
useDeepCompareEffect(() => {
if (!_.isEmpty(data)) {
setVisible(true);
} else {
setVisible(false);
}
}, [data]);
2020-04-20 13:09:19 +00:00
const showScreenLock = (args) => {
setData(args);
if (!isTablet) {
Orientation.lockToPortrait();
}
2020-04-20 13:09:19 +00:00
};
2020-04-17 19:11:06 +00:00
useEffect(() => {
2020-04-22 19:58:19 +00:00
EventEmitter.addEventListener(LOCAL_AUTHENTICATE_EMITTER, showScreenLock);
return () => EventEmitter.removeListener(LOCAL_AUTHENTICATE_EMITTER);
2020-04-17 19:11:06 +00:00
}, []);
const onSubmit = () => {
const { submit } = data;
if (submit) {
2020-04-20 13:09:19 +00:00
submit();
2020-04-17 19:11:06 +00:00
}
setData({});
};
2020-04-13 20:36:39 +00:00
return (
2020-04-17 19:11:06 +00:00
<Modal
useNativeDriver
isVisible={visible}
hideModalContentWhileAnimating
style={{ margin: 0 }}
>
2020-04-20 22:03:56 +00:00
<View style={[styles.container, { backgroundColor: themes[theme].auxiliaryBackground }]}>
2020-04-23 20:11:17 +00:00
<PasscodeEnter theme={theme} type={TYPE.ENTER} finishProcess={onSubmit} />
2020-04-17 19:11:06 +00:00
</View>
</Modal>
2020-04-13 20:36:39 +00:00
);
2020-04-22 16:34:53 +00:00
};
ScreenLockedView.propTypes = {
theme: PropTypes.string,
// eslint-disable-next-line react/no-unused-prop-types
split: PropTypes.bool // TODO: need it?
};
2020-04-13 20:36:39 +00:00
2020-04-17 19:11:06 +00:00
export default withSplit(withTheme(ScreenLockedView));