2020-05-08 17:04:37 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { StyleSheet } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Orientation from 'react-native-orientation-locker';
|
|
|
|
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 Modal from 'react-native-modal';
|
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
|
|
|
|
import { withTheme } from '../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { hasNotch, isTablet } from '../utils/deviceInfo';
|
2020-05-08 17:04:37 +00:00
|
|
|
import { TYPE } from '../containers/Passcode/constants';
|
|
|
|
import { PasscodeChoose } from '../containers/Passcode';
|
|
|
|
import EventEmitter from '../utils/events';
|
|
|
|
import { CustomIcon } from '../lib/Icons';
|
|
|
|
import { CHANGE_PASSCODE_EMITTER } from '../constants/localAuthentication';
|
|
|
|
import { themes } from '../constants/colors';
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
modal: {
|
|
|
|
margin: 0
|
|
|
|
},
|
|
|
|
close: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: hasNotch ? 50 : 30,
|
|
|
|
left: 15
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const ChangePasscodeView = React.memo(({ 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]);
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const showChangePasscode = args => {
|
2020-05-08 17:04:37 +00:00
|
|
|
setData(args);
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const onSubmit = passcode => {
|
2020-05-08 17:04:37 +00:00
|
|
|
const { submit } = data;
|
|
|
|
if (submit) {
|
|
|
|
submit(passcode);
|
|
|
|
}
|
|
|
|
setData({});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onCancel = () => {
|
|
|
|
const { cancel } = data;
|
|
|
|
if (cancel) {
|
|
|
|
cancel();
|
|
|
|
}
|
|
|
|
setData({});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isTablet) {
|
|
|
|
Orientation.lockToPortrait();
|
|
|
|
}
|
2021-02-23 19:00:39 +00:00
|
|
|
const listener = EventEmitter.addEventListener(CHANGE_PASSCODE_EMITTER, showChangePasscode);
|
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(CHANGE_PASSCODE_EMITTER, listener);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-05-08 17:04:37 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<Modal useNativeDriver isVisible={visible} hideModalContentWhileAnimating style={styles.modal}>
|
2020-05-08 17:04:37 +00:00
|
|
|
<PasscodeChoose theme={theme} type={TYPE.choose} finishProcess={onSubmit} force={data?.force} />
|
2021-09-13 20:41:05 +00:00
|
|
|
{!data?.force ? (
|
|
|
|
<Touchable onPress={onCancel} style={styles.close}>
|
|
|
|
<CustomIcon name='close' color={themes[theme].passcodePrimary} size={30} />
|
|
|
|
</Touchable>
|
|
|
|
) : null}
|
2020-05-08 17:04:37 +00:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
ChangePasscodeView.propTypes = {
|
|
|
|
theme: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withTheme(ChangePasscodeView);
|