Lock orientation portrait when not on tablet

This commit is contained in:
Diego Mello 2020-04-22 17:05:45 -03:00
parent 788b0ddf9a
commit eee8ea09a2
3 changed files with 20 additions and 2 deletions

View File

@ -1,8 +1,9 @@
import React from 'react';
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { SafeAreaView } from 'react-navigation';
import PINCode, { PinStatus } from '@haskkor/react-native-pincode';
import RNUserDefaults from 'rn-user-defaults';
import Orientation from 'react-native-orientation-locker';
import I18n from '../i18n';
import { themedHeader } from '../utils/navigation';
@ -10,6 +11,7 @@ import { withTheme } from '../theme';
import { themes } from '../constants/colors';
import sharedStyles from './Styles';
import { PASSCODE_KEY, PASSCODE_LENGTH } from '../constants/localAuthentication';
import { isTablet } from '../utils/deviceInfo';
const ScreenLockConfigView = React.memo(({ navigation, theme }) => {
const savePasscode = async(passcode) => {
@ -17,6 +19,17 @@ const ScreenLockConfigView = React.memo(({ navigation, theme }) => {
navigation.pop();
};
useEffect(() => {
if (!isTablet) {
Orientation.lockToPortrait();
}
return (() => {
if (!isTablet) {
Orientation.unlockAllOrientations();
}
});
}, []);
return (
<SafeAreaView
style={[sharedStyles.container, { backgroundColor: themes[theme].auxiliaryBackground }]}

View File

@ -208,7 +208,6 @@ class RoomsListView extends React.Component {
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
}
Dimensions.addEventListener('change', this.onDimensionsChange);
Orientation.unlockAllOrientations();
this.willFocusListener = navigation.addListener('willFocus', () => {
// Check if there were changes while not focused (it's set on sCU)
if (this.shouldUpdate) {
@ -218,6 +217,7 @@ class RoomsListView extends React.Component {
}
});
this.didFocusListener = navigation.addListener('didFocus', () => {
Orientation.unlockAllOrientations();
this.animated = true;
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
});

View File

@ -21,6 +21,8 @@ import {
PASSCODE_KEY, PASSCODE_LENGTH, LOCAL_AUTHENTICATE_EMITTER, LOCKED_OUT_TIMER_KEY, ATTEMPTS_KEY
} from '../constants/localAuthentication';
import { resetAttempts } from '../utils/localAuthentication';
import { isTablet } from '../utils/deviceInfo';
import Orientation from 'react-native-orientation-locker';
const MAX_ATTEMPTS = 6;
const TIME_TO_LOCK = 30000;
@ -130,6 +132,9 @@ const ScreenLockedView = ({ theme }) => {
const showScreenLock = (args) => {
setData(args);
fetchPasscode();
if (!isTablet) {
Orientation.lockToPortrait();
}
};
const checkOldSession = async() => {