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

62 lines
1.7 KiB
JavaScript
Raw Normal View History

import React, { useEffect } from 'react';
2020-04-20 13:09:19 +00:00
import PropTypes from 'prop-types';
import { SafeAreaView } from 'react-navigation';
import RNUserDefaults from 'rn-user-defaults';
import Orientation from 'react-native-orientation-locker';
2020-04-20 13:09:19 +00:00
2020-04-24 12:17:38 +00:00
// import I18n from '../i18n';
2020-04-20 13:09:19 +00:00
import { themedHeader } from '../utils/navigation';
import { withTheme } from '../theme';
import { themes } from '../constants/colors';
import sharedStyles from './Styles';
2020-04-23 21:50:49 +00:00
import { PASSCODE_KEY } from '../constants/localAuthentication';
import { isTablet } from '../utils/deviceInfo';
2020-04-23 20:11:17 +00:00
import { TYPE } from '../containers/Passcode/constants';
import { PasscodeChoose } from '../containers/Passcode';
2020-04-20 13:09:19 +00:00
const ScreenLockConfigView = React.memo(({ navigation, theme }) => {
const savePasscode = async(passcode) => {
await RNUserDefaults.set(PASSCODE_KEY, passcode);
navigation.pop();
};
useEffect(() => {
if (!isTablet) {
Orientation.lockToPortrait();
}
return (() => {
if (!isTablet) {
Orientation.unlockAllOrientations();
}
});
}, []);
2020-04-20 13:09:19 +00:00
return (
<SafeAreaView
style={[sharedStyles.container, { backgroundColor: themes[theme].auxiliaryBackground }]}
>
2020-04-23 20:11:17 +00:00
<PasscodeChoose theme={theme} type={TYPE.choose} finishProcess={savePasscode} />
2020-04-20 13:09:19 +00:00
</SafeAreaView>
);
});
ScreenLockConfigView.navigationOptions = ({ screenProps, navigation }) => {
const forceSetPasscode = navigation.getParam('forceSetPasscode', false);
if (forceSetPasscode) {
return {
header: null
};
}
return {
title: 'Change Passcode',
...themedHeader(screenProps.theme)
};
};
ScreenLockConfigView.propTypes = {
navigation: PropTypes.object,
theme: PropTypes.string
};
export default withTheme(ScreenLockConfigView);