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

86 lines
2.8 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';
2020-04-20 19:49:09 +00:00
import PINCode, { PinStatus } from '@haskkor/react-native-pincode';
2020-04-20 13:09:19 +00:00
import RNUserDefaults from 'rn-user-defaults';
import Orientation from 'react-native-orientation-locker';
2020-04-20 13:09:19 +00:00
import I18n from '../i18n';
import { themedHeader } from '../utils/navigation';
import { withTheme } from '../theme';
import { themes } from '../constants/colors';
import sharedStyles from './Styles';
2020-04-22 19:58:19 +00:00
import { PASSCODE_KEY, PASSCODE_LENGTH } from '../constants/localAuthentication';
import { isTablet } from '../utils/deviceInfo';
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 }]}
>
<PINCode
2020-04-20 19:49:09 +00:00
status={PinStatus.choose}
2020-04-20 13:09:19 +00:00
passwordLength={PASSCODE_LENGTH}
customBackSpaceIcon={() => null}
storePin={savePasscode}
2020-04-20 19:49:09 +00:00
touchIDDisabled
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}
stylePinCodeButtonCircle={{ borderWidth: 1, borderColor: themes[theme].borderColor }}
stylePinCodeTextTitle={{ ...sharedStyles.textRegular, fontWeight: '400' }}
stylePinCodeTextSubtitle={{ ...sharedStyles.textRegular, fontWeight: '300' }}
stylePinCodeTextButtonCircle={{ ...sharedStyles.textRegular, fontWeight: '100' }}
stylePinCodeHiddenPasswordSizeEmpty={8}
stylePinCodeHiddenPasswordSizeFull={12}
titleChoose='Enter your new passcode'
titleConfirm='Confirm your passcode'
subtitleChoose=''
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);