feat: Remove landscape support from smartphones (#5203)

This commit is contained in:
Diego Mello 2023-09-08 10:51:12 -03:00 committed by GitHub
parent 79bc539773
commit 6a610a956f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 22 additions and 89 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Text, View, useWindowDimensions } from 'react-native'; import { Text, View } from 'react-native';
import Touchable from 'react-native-platform-touchable'; import Touchable from 'react-native-platform-touchable';
import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
@ -37,21 +37,16 @@ const IncomingCallHeader = React.memo(
const [mic, setMic] = useState(true); const [mic, setMic] = useState(true);
const [cam, setCam] = useState(false); const [cam, setCam] = useState(false);
const dispatch = useDispatch(); const dispatch = useDispatch();
const isMasterDetail = useAppSelector(state => state.app.isMasterDetail); const isMasterDetail = useAppSelector(state => state.app.isMasterDetail);
const styles = useStyle(); const styles = useStyle();
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
const { height, width } = useWindowDimensions();
const isLandscape = width > height;
const { colors } = useTheme(); const { colors } = useTheme();
return ( return (
<View <View
style={[ style={[
styles.container, styles.container,
(isMasterDetail || isLandscape) && styles.small, isMasterDetail && styles.small,
{ {
marginTop: insets.top marginTop: insets.top
} }

View File

@ -11,7 +11,6 @@ import { themes } from '../../lib/constants';
import { useTheme } from '../../theme'; import { useTheme } from '../../theme';
import { ROW_HEIGHT } from '../RoomItem'; import { ROW_HEIGHT } from '../RoomItem';
import { goRoom } from '../../lib/methods/helpers/goRoom'; import { goRoom } from '../../lib/methods/helpers/goRoom';
import { useOrientation } from '../../dimensions';
import { IApplicationState, ISubscription, SubscriptionType } from '../../definitions'; import { IApplicationState, ISubscription, SubscriptionType } from '../../definitions';
import { hideNotification } from '../../lib/methods/helpers/notifications'; import { hideNotification } from '../../lib/methods/helpers/notifications';
@ -76,8 +75,6 @@ const styles = StyleSheet.create({
const NotifierComponent = React.memo(({ notification, isMasterDetail }: INotifierComponent) => { const NotifierComponent = React.memo(({ notification, isMasterDetail }: INotifierComponent) => {
const { theme } = useTheme(); const { theme } = useTheme();
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
const { isLandscape } = useOrientation();
const { text, payload } = notification; const { text, payload } = notification;
const { type, rid } = payload; const { type, rid } = payload;
const name = type === 'd' ? payload.sender.username : payload.name; const name = type === 'd' ? payload.sender.username : payload.name;
@ -104,7 +101,7 @@ const NotifierComponent = React.memo(({ notification, isMasterDetail }: INotifie
<View <View
style={[ style={[
styles.container, styles.container,
(isMasterDetail || isLandscape) && styles.small, isMasterDetail && styles.small,
{ {
backgroundColor: themes[theme].focusedBackground, backgroundColor: themes[theme].focusedBackground,
borderColor: themes[theme].separatorColor, borderColor: themes[theme].separatorColor,

View File

@ -84,11 +84,10 @@ const HeaderFooter = ({ onReaction, theme }: THeaderFooter) => (
); );
const Header = React.memo(({ handleReaction, message, isMasterDetail }: IHeader) => { const Header = React.memo(({ handleReaction, message, isMasterDetail }: IHeader) => {
const { width, height } = useWindowDimensions(); const { width } = useWindowDimensions();
const { theme } = useTheme(); const { theme } = useTheme();
const { frequentlyUsed, loaded } = useFrequentlyUsedEmoji(true); const { frequentlyUsed, loaded } = useFrequentlyUsedEmoji(true);
const isLandscape = width > height; const size = (isMasterDetail ? width / 2 : width) - CONTAINER_MARGIN * 2;
const size = (isLandscape || isMasterDetail ? width / 2 : width) - CONTAINER_MARGIN * 2;
const quantity = Math.trunc(size / (ITEM_SIZE + ITEM_MARGIN * 2) - 1); const quantity = Math.trunc(size / (ITEM_SIZE + ITEM_MARGIN * 2) - 1);
const onReaction: TOnReaction = ({ emoji }) => { const onReaction: TOnReaction = ({ emoji }) => {

View File

@ -1,10 +1,9 @@
import React, { forwardRef, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react'; import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
import { Col, Grid, Row } from 'react-native-easy-grid'; import { Col, Grid, Row } from 'react-native-easy-grid';
import range from 'lodash/range'; import range from 'lodash/range';
import { View } from 'react-native'; import { View } from 'react-native';
import * as Animatable from 'react-native-animatable'; import * as Animatable from 'react-native-animatable';
import * as Haptics from 'expo-haptics'; import * as Haptics from 'expo-haptics';
import Orientation from 'react-native-orientation-locker';
import styles from './styles'; import styles from './styles';
import Button from './Button'; import Button from './Button';
@ -16,7 +15,6 @@ import LockIcon from './LockIcon';
import Title from './Title'; import Title from './Title';
import Subtitle from './Subtitle'; import Subtitle from './Subtitle';
import { useDimensions } from '../../../dimensions'; import { useDimensions } from '../../../dimensions';
import { isTablet } from '../../../lib/methods/helpers';
interface IPasscodeBase { interface IPasscodeBase {
type: string; type: string;
@ -37,18 +35,6 @@ export interface IBase {
const Base = forwardRef<IBase, IPasscodeBase>( const Base = forwardRef<IBase, IPasscodeBase>(
({ type, onEndProcess, previousPasscode, title, subtitle, onError, showBiometry, onBiometryPress }, ref) => { ({ type, onEndProcess, previousPasscode, title, subtitle, onError, showBiometry, onBiometryPress }, ref) => {
useLayoutEffect(() => {
if (!isTablet) {
Orientation.lockToPortrait();
}
return () => {
if (!isTablet) {
Orientation.unlockAllOrientations();
}
};
}, []);
const { theme } = useTheme(); const { theme } = useTheme();
const { height } = useDimensions(); const { height } = useDimensions();

View File

@ -7,7 +7,7 @@ import { IReaction } from '../../definitions';
import { TGetCustomEmoji } from '../../definitions/IEmoji'; import { TGetCustomEmoji } from '../../definitions/IEmoji';
import I18n from '../../i18n'; import I18n from '../../i18n';
import styles, { MIN_TAB_WIDTH } from './styles'; import styles, { MIN_TAB_WIDTH } from './styles';
import { useDimensions, useOrientation } from '../../dimensions'; import { useDimensions } from '../../dimensions';
interface ITabBarItem { interface ITabBarItem {
getCustomEmoji: TGetCustomEmoji; getCustomEmoji: TGetCustomEmoji;
@ -55,10 +55,8 @@ const TabBarItem = ({ tab, index, goToPage, getCustomEmoji }: ITabBarItem) => {
}; };
const ReactionsTabBar = ({ tabs, activeTab, goToPage, getCustomEmoji }: IReactionsTabBar): React.ReactElement => { const ReactionsTabBar = ({ tabs, activeTab, goToPage, getCustomEmoji }: IReactionsTabBar): React.ReactElement => {
const { isLandscape } = useOrientation();
const { width } = useDimensions(); const { width } = useDimensions();
const reactionsListWidth = isLandscape ? width / 2 : width; const tabWidth = tabs && Math.max(width / tabs.length, MIN_TAB_WIDTH);
const tabWidth = tabs && Math.max(reactionsListWidth / tabs.length, MIN_TAB_WIDTH);
const { colors } = useTheme(); const { colors } = useTheme();
return ( return (
<View testID='reactionsTabBar'> <View testID='reactionsTabBar'>

View File

@ -66,14 +66,6 @@ export const Typing = () => (
</> </>
); );
export const Landscape = () => (
<>
<HeaderExample title={() => <RoomHeader width={height} height={width} />} />
<HeaderExample title={() => <RoomHeader width={height} height={width} subtitle='subtitle' />} />
<HeaderExample title={() => <RoomHeader width={height} height={width} title={longText} subtitle={longText} />} />
</>
);
export const Thread = () => ( export const Thread = () => (
<> <>
<HeaderExample title={() => <RoomHeader tmid='123' parentTitle='parent title' />} /> <HeaderExample title={() => <RoomHeader tmid='123' parentTitle='parent title' />} />

View File

@ -6,8 +6,6 @@ import { useTheme } from '../theme';
import sharedStyles from '../views/Styles'; import sharedStyles from '../views/Styles';
import { themes } from '../lib/constants'; import { themes } from '../lib/constants';
import { TextInput } from './TextInput'; import { TextInput } from './TextInput';
import { isIOS, isTablet } from '../lib/methods/helpers';
import { useOrientation } from '../dimensions';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@ -16,7 +14,8 @@ const styles = StyleSheet.create({
marginLeft: 0 marginLeft: 0
}, },
title: { title: {
...sharedStyles.textSemibold ...sharedStyles.textSemibold,
fontSize: 16
} }
}); });
@ -28,15 +27,12 @@ interface ISearchHeaderProps {
const SearchHeader = ({ onSearchChangeText, testID }: ISearchHeaderProps): JSX.Element => { const SearchHeader = ({ onSearchChangeText, testID }: ISearchHeaderProps): JSX.Element => {
const { theme } = useTheme(); const { theme } = useTheme();
const isLight = theme === 'light'; const isLight = theme === 'light';
const { isLandscape } = useOrientation();
const scale = isIOS && isLandscape && !isTablet ? 0.8 : 1;
const titleFontSize = 16 * scale;
return ( return (
<View style={styles.container}> <View style={styles.container}>
<TextInput <TextInput
autoFocus autoFocus
style={[styles.title, isLight && { color: themes[theme].headerTitleColor }, { fontSize: titleFontSize }]} style={[styles.title, isLight && { color: themes[theme].headerTitleColor }]}
placeholder={I18n.t('Search')} placeholder={I18n.t('Search')}
onChangeText={onSearchChangeText} onChangeText={onSearchChangeText}
testID={testID} testID={testID}

View File

@ -5,6 +5,7 @@ import { initialWindowMetrics, SafeAreaProvider } from 'react-native-safe-area-c
import RNScreens from 'react-native-screens'; import RNScreens from 'react-native-screens';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { GestureHandlerRootView } from 'react-native-gesture-handler'; import { GestureHandlerRootView } from 'react-native-gesture-handler';
import Orientation from 'react-native-orientation-locker';
import { appInit, appInitLocalSettings, setMasterDetail as setMasterDetailAction } from './actions/app'; import { appInit, appInitLocalSettings, setMasterDetail as setMasterDetailAction } from './actions/app';
import { deepLinkingOpen } from './actions/deepLinking'; import { deepLinkingOpen } from './actions/deepLinking';
@ -104,6 +105,9 @@ export default class Root extends React.Component<{}, IState> {
}; };
if (isTablet) { if (isTablet) {
this.initTablet(); this.initTablet();
Orientation.unlockAllOrientations();
} else {
Orientation.lockToPortrait();
} }
setNativeTheme(theme); setNativeTheme(theme);
} }

View File

@ -1,13 +1,12 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { StyleSheet } from 'react-native'; import { StyleSheet } from 'react-native';
import Orientation from 'react-native-orientation-locker';
import useDeepCompareEffect from 'use-deep-compare-effect'; import useDeepCompareEffect from 'use-deep-compare-effect';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import Modal from 'react-native-modal'; import Modal from 'react-native-modal';
import Touchable from 'react-native-platform-touchable'; import Touchable from 'react-native-platform-touchable';
import { useTheme } from '../theme'; import { useTheme } from '../theme';
import { hasNotch, isTablet } from '../lib/methods/helpers'; import { hasNotch } from '../lib/methods/helpers';
import { PasscodeChoose } from '../containers/Passcode'; import { PasscodeChoose } from '../containers/Passcode';
import EventEmitter from '../lib/methods/helpers/events'; import EventEmitter from '../lib/methods/helpers/events';
import { CustomIcon } from '../containers/CustomIcon'; import { CustomIcon } from '../containers/CustomIcon';
@ -65,14 +64,8 @@ const ChangePasscodeView = React.memo(() => {
}; };
useEffect(() => { useEffect(() => {
if (!isTablet) {
Orientation.lockToPortrait();
}
const listener = EventEmitter.addEventListener(CHANGE_PASSCODE_EMITTER, showChangePasscode); const listener = EventEmitter.addEventListener(CHANGE_PASSCODE_EMITTER, showChangePasscode);
return () => { return () => {
if (!isTablet) {
Orientation.unlockAllOrientations();
}
EventEmitter.removeListener(CHANGE_PASSCODE_EMITTER, listener); EventEmitter.removeListener(CHANGE_PASSCODE_EMITTER, listener);
}; };
}, []); }, []);

View File

@ -3,7 +3,6 @@ import { Base64 } from 'js-base64';
import React from 'react'; import React from 'react';
import { BackHandler, Image, Keyboard, StyleSheet, Text, View } from 'react-native'; import { BackHandler, Image, Keyboard, StyleSheet, Text, View } from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler'; import { TouchableOpacity } from 'react-native-gesture-handler';
import Orientation from 'react-native-orientation-locker';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import parse from 'url-parse'; import parse from 'url-parse';
@ -88,9 +87,6 @@ interface ISubmitParams {
class NewServerView extends React.Component<INewServerViewProps, INewServerViewState> { class NewServerView extends React.Component<INewServerViewProps, INewServerViewState> {
constructor(props: INewServerViewProps) { constructor(props: INewServerViewProps) {
super(props); super(props);
if (!isTablet) {
Orientation.lockToPortrait();
}
this.setHeader(); this.setHeader();
this.state = { this.state = {

View File

@ -4,8 +4,6 @@ import { StyleSheet, Text, TextInputProps, TouchableOpacity, TouchableOpacityPro
import I18n from '../../../i18n'; import I18n from '../../../i18n';
import sharedStyles from '../../Styles'; import sharedStyles from '../../Styles';
import { CustomIcon } from '../../../containers/CustomIcon'; import { CustomIcon } from '../../../containers/CustomIcon';
import { isIOS, isTablet } from '../../../lib/methods/helpers';
import { useOrientation } from '../../../dimensions';
import { useTheme } from '../../../theme'; import { useTheme } from '../../../theme';
import SearchHeader from '../../../containers/SearchHeader'; import SearchHeader from '../../../containers/SearchHeader';
@ -20,9 +18,11 @@ const styles = StyleSheet.create({
}, },
title: { title: {
flexShrink: 1, flexShrink: 1,
fontSize: 16,
...sharedStyles.textSemibold ...sharedStyles.textSemibold
}, },
subtitle: { subtitle: {
fontSize: 14,
...sharedStyles.textRegular ...sharedStyles.textRegular
}, },
upsideDown: { upsideDown: {
@ -55,10 +55,6 @@ const Header = React.memo(
onPress onPress
}: IRoomHeader) => { }: IRoomHeader) => {
const { colors } = useTheme(); const { colors } = useTheme();
const { isLandscape } = useOrientation();
const scale = isIOS && isLandscape && !isTablet ? 0.8 : 1;
const titleFontSize = 16 * scale;
const subTitleFontSize = 14 * scale;
if (showSearchHeader) { if (showSearchHeader) {
return <SearchHeader onSearchChangeText={onSearchChangeText} testID='rooms-list-view-search-input' />; return <SearchHeader onSearchChangeText={onSearchChangeText} testID='rooms-list-view-search-input' />;
@ -77,7 +73,7 @@ const Header = React.memo(
<View style={styles.container}> <View style={styles.container}>
<TouchableOpacity onPress={onPress} testID='rooms-list-header-server-dropdown-button'> <TouchableOpacity onPress={onPress} testID='rooms-list-header-server-dropdown-button'>
<View style={styles.button}> <View style={styles.button}>
<Text style={[styles.title, { fontSize: titleFontSize, color: colors.headerTitleColor }]} numberOfLines={1}> <Text style={[styles.title, { color: colors.headerTitleColor }]} numberOfLines={1}>
{serverName} {serverName}
</Text> </Text>
<CustomIcon <CustomIcon
@ -90,7 +86,7 @@ const Header = React.memo(
{subtitle ? ( {subtitle ? (
<Text <Text
testID='rooms-list-header-server-subtitle' testID='rooms-list-header-server-subtitle'
style={[styles.subtitle, { color: colors.auxiliaryText, fontSize: subTitleFontSize }]} style={[styles.subtitle, { color: colors.auxiliaryText }]}
numberOfLines={1} numberOfLines={1}
> >
{subtitle} {subtitle}

View File

@ -2,7 +2,6 @@ import React from 'react';
import { BackHandler, FlatList, Keyboard, NativeEventSubscription, RefreshControl, Text, View } from 'react-native'; import { BackHandler, FlatList, Keyboard, NativeEventSubscription, RefreshControl, Text, View } from 'react-native';
import { batch, connect } from 'react-redux'; import { batch, connect } from 'react-redux';
import { dequal } from 'dequal'; import { dequal } from 'dequal';
import Orientation from 'react-native-orientation-locker';
import { Q } from '@nozbe/watermelondb'; import { Q } from '@nozbe/watermelondb';
import { withSafeAreaInsets } from 'react-native-safe-area-context'; import { withSafeAreaInsets } from 'react-native-safe-area-context';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
@ -217,7 +216,6 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands); EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
} }
this.unsubscribeFocus = navigation.addListener('focus', () => { this.unsubscribeFocus = navigation.addListener('focus', () => {
Orientation.unlockAllOrientations();
this.animated = true; this.animated = true;
// Check if there were changes with sort preference, then call getSubscription to remount the list // Check if there were changes with sort preference, then call getSubscription to remount the list
if (this.sortPreferencesChanged) { if (this.sortPreferencesChanged) {

View File

@ -2,7 +2,6 @@ import isEmpty from 'lodash/isEmpty';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { StyleSheet } from 'react-native'; import { StyleSheet } from 'react-native';
import Modal from 'react-native-modal'; import Modal from 'react-native-modal';
import Orientation from 'react-native-orientation-locker';
import Touchable from 'react-native-platform-touchable'; import Touchable from 'react-native-platform-touchable';
import useDeepCompareEffect from 'use-deep-compare-effect'; import useDeepCompareEffect from 'use-deep-compare-effect';
@ -10,7 +9,7 @@ import { PasscodeEnter } from '../containers/Passcode';
import { LOCAL_AUTHENTICATE_EMITTER } from '../lib/constants'; import { LOCAL_AUTHENTICATE_EMITTER } from '../lib/constants';
import { CustomIcon } from '../containers/CustomIcon'; import { CustomIcon } from '../containers/CustomIcon';
import { useTheme } from '../theme'; import { useTheme } from '../theme';
import { hasNotch, isTablet } from '../lib/methods/helpers'; import { hasNotch } from '../lib/methods/helpers';
import EventEmitter from '../lib/methods/helpers/events'; import EventEmitter from '../lib/methods/helpers/events';
interface IData { interface IData {
@ -46,14 +45,8 @@ const ScreenLockedView = (): JSX.Element => {
}; };
useEffect(() => { useEffect(() => {
if (!isTablet) {
Orientation.lockToPortrait();
}
const listener = EventEmitter.addEventListener(LOCAL_AUTHENTICATE_EMITTER, showScreenLock); const listener = EventEmitter.addEventListener(LOCAL_AUTHENTICATE_EMITTER, showScreenLock);
return () => { return () => {
if (!isTablet) {
Orientation.unlockAllOrientations();
}
EventEmitter.removeListener(LOCAL_AUTHENTICATE_EMITTER, listener); EventEmitter.removeListener(LOCAL_AUTHENTICATE_EMITTER, listener);
}; };
}, []); }, []);

View File

@ -2,7 +2,6 @@ import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack'; import { StackNavigationProp } from '@react-navigation/stack';
import React, { useEffect, useLayoutEffect, useState } from 'react'; import React, { useEffect, useLayoutEffect, useState } from 'react';
import { ScrollView, StyleSheet, Text } from 'react-native'; import { ScrollView, StyleSheet, Text } from 'react-native';
import Orientation from 'react-native-orientation-locker';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import * as yup from 'yup'; import * as yup from 'yup';
@ -18,7 +17,7 @@ import I18n from '../i18n';
import KeyboardView from '../containers/KeyboardView'; import KeyboardView from '../containers/KeyboardView';
import { getUserSelector } from '../selectors/login'; import { getUserSelector } from '../selectors/login';
import { useTheme } from '../theme'; import { useTheme } from '../theme';
import { isTablet, showErrorAlert } from '../lib/methods/helpers'; import { showErrorAlert } from '../lib/methods/helpers';
import scrollPersistTaps from '../lib/methods/helpers/scrollPersistTaps'; import scrollPersistTaps from '../lib/methods/helpers/scrollPersistTaps';
import sharedStyles from './Styles'; import sharedStyles from './Styles';
import { Services } from '../lib/services'; import { Services } from '../lib/services';
@ -56,9 +55,6 @@ const SetUsernameView = () => {
useLayoutEffect(() => { useLayoutEffect(() => {
navigation.setOptions({ title: server }); navigation.setOptions({ title: server });
if (!isTablet) {
Orientation.lockToPortrait();
}
}, [navigation, server]); }, [navigation, server]);
useEffect(() => { useEffect(() => {

View File

@ -122,9 +122,5 @@ export default StyleSheet.create({
}, },
inputLastChild: { inputLastChild: {
marginBottom: 15 marginBottom: 15
},
notchLandscapeContainer: {
marginTop: -34,
paddingHorizontal: 30
} }
}); });