2020-05-08 17:04:37 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { StyleSheet } from 'react-native';
|
|
|
|
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';
|
|
|
|
|
2021-11-10 20:50:38 +00:00
|
|
|
import { useTheme } from '../theme';
|
2023-09-08 13:51:12 +00:00
|
|
|
import { hasNotch } from '../lib/methods/helpers';
|
2020-05-08 17:04:37 +00:00
|
|
|
import { PasscodeChoose } from '../containers/Passcode';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../lib/methods/helpers/events';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../containers/CustomIcon';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { CHANGE_PASSCODE_EMITTER, themes } from '../lib/constants';
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
modal: {
|
|
|
|
margin: 0
|
|
|
|
},
|
|
|
|
close: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: hasNotch ? 50 : 30,
|
|
|
|
left: 15
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-10 20:50:38 +00:00
|
|
|
interface IArgs {
|
|
|
|
submit(passcode: string): void;
|
|
|
|
cancel(): void;
|
|
|
|
force: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChangePasscodeView = React.memo(() => {
|
2020-05-08 17:04:37 +00:00
|
|
|
const [visible, setVisible] = useState(false);
|
2021-11-10 20:50:38 +00:00
|
|
|
const [data, setData] = useState<Partial<IArgs>>({});
|
|
|
|
|
|
|
|
const { theme } = useTheme();
|
2020-05-08 17:04:37 +00:00
|
|
|
|
|
|
|
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-11-10 20:50:38 +00:00
|
|
|
const showChangePasscode = (args: IArgs) => {
|
2020-05-08 17:04:37 +00:00
|
|
|
setData(args);
|
|
|
|
};
|
|
|
|
|
2021-11-10 20:50:38 +00:00
|
|
|
const onSubmit = (passcode: string) => {
|
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(() => {
|
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 () => {
|
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}>
|
2022-03-23 00:43:59 +00:00
|
|
|
<PasscodeChoose 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>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-11-10 20:50:38 +00:00
|
|
|
export default ChangePasscodeView;
|