Skip to content

Commit e1e043b

Browse files
authored
Merge pull request Expensify#87656 from software-mansion-labs/@GCyganek/landscape-mode/number-with-symbol-form-fixes
2 parents 3c9788c + c80e876 commit e1e043b

6 files changed

Lines changed: 85 additions & 7 deletions

File tree

src/components/BigNumberPad.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i
3434

3535
const styles = useThemeStyles();
3636
const [timer, setTimer] = useState<NodeJS.Timeout | null>(null);
37-
const {isExtraSmallScreenHeight} = useResponsiveLayout();
37+
const {isExtraSmallScreenHeight, isInLandscapeMode} = useResponsiveLayout();
3838
const numberPressedRef = useRef(numberPressed);
3939

4040
useEffect(() => {
@@ -64,10 +64,10 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i
6464
style={[styles.flexColumn, styles.w100]}
6565
id={id}
6666
>
67-
{padNumbers.map((row) => (
67+
{padNumbers.map((row, index) => (
6868
<View
6969
key={`NumberPadRow-${row[0]}`}
70-
style={[styles.flexRow, styles.mt3]}
70+
style={[styles.flexRow, index === 0 && isInLandscapeMode ? undefined : styles.mt3]}
7171
>
7272
{row.map((column, columnIndex) => {
7373
// Adding margin between buttons except first column to
@@ -77,8 +77,9 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i
7777
return (
7878
<Button
7979
key={column}
80-
medium={isExtraSmallScreenHeight}
81-
large={!isExtraSmallScreenHeight}
80+
small={isInLandscapeMode}
81+
medium={isExtraSmallScreenHeight && !isInLandscapeMode}
82+
large={!isExtraSmallScreenHeight && !isInLandscapeMode}
8283
shouldEnableHapticFeedback
8384
style={[styles.flex1, marginLeft]}
8485
text={column === '<' ? undefined : toLocaleDigit(column)}

src/components/NumberWithSymbolForm.tsx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {ForwardedRef} from 'react';
33
import React, {useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
44
import type {KeyboardTypeOptions, NativeSyntheticEvent} from 'react-native';
55
import {View} from 'react-native';
6+
import useIsInLandscapeMode from '@hooks/useIsInLandscapeMode';
67
import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
78
import useLocalize from '@hooks/useLocalize';
89
import {useMouseActions} from '@hooks/useMouseContext';
@@ -186,6 +187,7 @@ function NumberWithSymbolForm({
186187
...props
187188
}: NumberWithSymbolFormProps) {
188189
const icons = useMemoizedLazyExpensifyIcons(['DownArrow', 'PlusMinus']);
190+
const isInLandscapeMode = useIsInLandscapeMode();
189191

190192
const styles = useThemeStyles();
191193
const StyleUtils = useStyleUtils();
@@ -571,9 +573,75 @@ function NumberWithSymbolForm({
571573
onFocus={props.onFocus}
572574
accessibilityLabel={props.accessibilityLabel}
573575
keyboardType={props.keyboardType}
576+
shouldAllowFocusInLandscapeMode
574577
/>
575578
);
576579

580+
if (isInLandscapeMode) {
581+
return (
582+
<>
583+
<ScrollView
584+
contentContainerStyle={[styles.flexGrow1, styles.flexRow]}
585+
style={[styles.flex1, styles.ph5]}
586+
>
587+
<View style={[styles.justifyContentCenter, styles.alignItemsCenter, styles.numberWithSymbolFormInputContainerLandscape]}>
588+
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentCenter]}>{textInputComponent}</View>
589+
<View style={[styles.flexRow, styles.justifyContentCenter, styles.gap2]}>
590+
{isSymbolPressable && (
591+
<Button
592+
shouldShowRightIcon
593+
small
594+
iconRight={icons.DownArrow}
595+
onPress={onSymbolButtonPress}
596+
style={styles.minWidth18}
597+
isContentCentered
598+
text={currency}
599+
accessibilityLabel={`${translate('common.selectCurrency')}, ${currency}`}
600+
/>
601+
)}
602+
{allowFlippingAmount && (
603+
<Button
604+
shouldShowRightIcon
605+
small
606+
iconRight={icons.PlusMinus}
607+
onPress={toggleNegative}
608+
style={styles.minWidth18}
609+
isContentCentered
610+
text={translate('iou.flip')}
611+
accessibilityLabel={translate('iou.flip')}
612+
/>
613+
)}
614+
</View>
615+
{!!errorText && (
616+
<FormHelpMessage
617+
style={[styles.ph5, styles.w100]}
618+
isError
619+
message={errorText}
620+
/>
621+
)}
622+
</View>
623+
624+
{shouldShowBigNumberPad ? (
625+
<View
626+
style={[styles.flex1, styles.justifyContentCenter]}
627+
id={NUM_PAD_CONTAINER_VIEW_ID}
628+
>
629+
{shouldShowBigNumberPad ? (
630+
<BigNumberPad
631+
id={NUM_PAD_VIEW_ID}
632+
numberPressed={updateValueNumberPad}
633+
longPressHandlerStateChanged={updateLongPressHandlerState}
634+
/>
635+
) : null}
636+
</View>
637+
) : null}
638+
</ScrollView>
639+
640+
{!!footer && <View style={[styles.w100, styles.justifyContentEnd, styles.pageWrapper, styles.pt0]}>{footer}</View>}
641+
</>
642+
);
643+
}
644+
577645
return (
578646
<ScrollView
579647
contentContainerStyle={styles.flexGrow1}

src/components/TextInput/BaseTextInput/implementation/index.native.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function BaseTextInput({
8484
ref,
8585
sentryLabel,
8686
rightHandSideComponent,
87+
shouldAllowFocusInLandscapeMode = false,
8788
...props
8889
}: BaseTextInputProps) {
8990
const InputComponent = InputComponentMap.get(type) ?? RNTextInput;
@@ -374,7 +375,7 @@ function BaseTextInput({
374375
)}
375376
<InputComponent
376377
ref={(element: BaseTextInputRef | null): void => {
377-
const baseTextInputRef = isInLandscapeMode ? getLandscapeTextInputRefProxy(element) : element;
378+
const baseTextInputRef = isInLandscapeMode && !shouldAllowFocusInLandscapeMode ? getLandscapeTextInputRefProxy(element) : element;
378379

379380
if (typeof ref === 'function') {
380381
ref(baseTextInputRef);
@@ -388,7 +389,7 @@ function BaseTextInput({
388389
}}
389390
// eslint-disable-next-line
390391
{...inputProps}
391-
autoFocus={isInLandscapeMode ? false : inputProps.autoFocus}
392+
autoFocus={isInLandscapeMode && !shouldAllowFocusInLandscapeMode ? false : inputProps.autoFocus}
392393
accessibilityLabel={inputProps.accessibilityLabel ?? accessibilityLabel}
393394
accessibilityValue={accessibilityValue}
394395
accessibilityHint={errorText || inputProps.accessibilityHint}

src/components/TextInput/BaseTextInput/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ type CustomBaseTextInputProps = ForwardedFSClassProps &
208208
navigation?: Omit<NavigationProp<ReactNavigation.RootParamList>, 'getState'> & {
209209
getState(): NavigationState | undefined;
210210
};
211+
212+
/** Whether the input should be allowed to be focused in landscape mode */
213+
shouldAllowFocusInLandscapeMode?: boolean;
211214
};
212215

213216
type BaseTextInputRef = HTMLFormElement | AnimatedTextInputRef;

src/components/TextInputWithSymbol/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type BaseTextInputWithSymbolProps = {
110110
| 'disabled'
111111
| 'ref'
112112
| 'accessibilityLabel'
113+
| 'shouldAllowFocusInLandscapeMode'
113114
>;
114115

115116
type TextInputWithSymbolProps = Omit<BaseTextInputWithSymbolProps, 'onSelectionChange'> & {

src/styles/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,6 +2802,10 @@ const staticStyles = (theme: ThemeColors) =>
28022802
paddingHorizontal: 20,
28032803
},
28042804

2805+
numberWithSymbolFormInputContainerLandscape: {
2806+
width: 400,
2807+
},
2808+
28052809
avatarSectionWrapper: {
28062810
width: '100%',
28072811
alignItems: 'center',

0 commit comments

Comments
 (0)