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

115 lines
3.5 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-22 16:34:53 +00:00
View, StyleSheet, Text
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-23 19:37:00 +00:00
// import PINCode, { PinStatus } from '@haskkor/react-native-pincode';
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 16:08:50 +00:00
{/* <PINCode
2020-04-20 19:49:09 +00:00
status={PinStatus.enter}
2020-04-20 13:09:19 +00:00
passwordLength={PASSCODE_LENGTH}
2020-04-17 19:11:06 +00:00
customBackSpaceIcon={() => null}
finishProcess={onSubmit}
2020-04-20 13:09:19 +00:00
storedPin={passcode}
2020-04-22 16:34:53 +00:00
maxAttempts={MAX_ATTEMPTS}
2020-04-20 19:49:09 +00:00
touchIDDisabled
2020-04-20 20:59:51 +00:00
vibrationEnabled={false}
2020-04-22 16:34:53 +00:00
timeLocked={TIME_TO_LOCK}
2020-04-20 22:03:56 +00:00
colorCircleButtons={themes[theme].backgroundColor}
colorPassword={themes[theme].titleText}
colorPasswordEmpty={themes[theme].titleText}
colorPasswordError={themes[theme].dangerColor}
numbersButtonOverlayColor={themes[theme].bannerBackground}
stylePinCodeButtonNumber={themes[theme].bodyText}
stylePinCodeButtonNumberPressed={themes[theme].bodyText}
stylePinCodeColorTitle={themes[theme].titleText}
stylePinCodeColorSubtitle={themes[theme].titleText}
stylePinCodeColorSubtitleError={themes[theme].dangerColor}
2020-04-22 16:34:53 +00:00
stylePinCodeButtonCircle={[styles.circleButton, { borderColor: themes[theme].borderColor }]}
stylePinCodeTextTitle={styles.title}
stylePinCodeTextSubtitle={styles.subtitle}
stylePinCodeTextButtonCircle={styles.circleButtonText}
2020-04-20 22:03:56 +00:00
stylePinCodeHiddenPasswordSizeEmpty={8}
stylePinCodeHiddenPasswordSizeFull={12}
titleEnter='Enter your passcode'
2020-04-22 16:34:53 +00:00
timePinLockedAsyncStorageName={LOCKED_OUT_TIMER_KEY}
pinAttemptsAsyncStorageName={ATTEMPTS_KEY}
lockedPage={<AppLocked />}
2020-04-23 16:08:50 +00:00
/> */}
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));