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

91 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-17 19:11:06 +00:00
View, Text, StyleSheet, TextInput
2020-04-13 20:36:39 +00:00
} from 'react-native';
import { connect } from 'react-redux';
2020-04-17 19:11:06 +00:00
import PINCode from '@haskkor/react-native-pincode';
import Modal from 'react-native-modal';
import useDeepCompareEffect from 'use-deep-compare-effect';
import _ from 'lodash';
2020-04-13 20:36:39 +00:00
import { appInit as appInitAction } from '../actions';
import I18n from '../i18n';
import StatusBar from '../containers/StatusBar';
import { withTheme } from '../theme';
import { themes } from '../constants/colors';
2020-04-17 19:11:06 +00:00
import EventEmitter from '../utils/events';
2020-04-13 20:36:39 +00:00
import sharedStyles from './Styles';
2020-04-17 19:11:06 +00:00
import { withSplit } from '../split';
export const LOCAL_AUTHENTICATE = 'LOCAL_AUTHENTICATE';
2020-04-13 20:36:39 +00:00
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
text: {
fontSize: 16,
paddingTop: 10,
...sharedStyles.textRegular,
...sharedStyles.textAlignCenter
}
});
2020-04-17 19:11:06 +00:00
const ScreenLockedView = React.memo(withTheme(({ theme, split }) => {
const [visible, setVisible] = useState(false);
const [data, setData] = useState({});
useDeepCompareEffect(() => {
if (!_.isEmpty(data)) {
setVisible(true);
} else {
setVisible(false);
}
}, [data]);
const showScreenLock = args => setData(args);
useEffect(() => {
EventEmitter.addEventListener(LOCAL_AUTHENTICATE, showScreenLock);
return () => EventEmitter.removeListener(LOCAL_AUTHENTICATE);
}, []);
const onSubmit = () => {
const { submit } = data;
if (submit) {
submit()
}
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 }}
>
<View style={[styles.container, { backgroundColor: themes[theme].backgroundColor }]}>
<PINCode
status={'enter'}
passwordLength={6}
customBackSpaceIcon={() => null}
// endProcessFunction={console.log}
finishProcess={onSubmit}
// onFail={() => alert('fail')}
storedPin='111111'
maxAttempts={3}
/>
{/* <Text onPress={onSubmit}>VAI</Text> */}
</View>
</Modal>
2020-04-13 20:36:39 +00:00
);
}));
2020-04-17 19:11:06 +00:00
export default withSplit(withTheme(ScreenLockedView));