Skip to content

Commit 45531d7

Browse files
authored
Merge pull request #88519 from software-mansion-labs/@GCyganek/landscape-mode/suggestions-list-left-offset-android
2 parents 7428c53 + a5cf540 commit 45531d7

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type {EdgeInsets} from 'react-native-safe-area-context';
2+
3+
function getLeftOffset(
4+
x: number,
5+
insets: EdgeInsets,
6+
bigScreenLeftOffset: number,
7+
shouldUseNarrowLayout: boolean,
8+
menuWidth: number,
9+
windowWidth: number,
10+
isInLandscapeMode: boolean,
11+
): number {
12+
if (isInLandscapeMode) {
13+
// On Android devices, sometimes x takes into consideration the insets.left value, sometimes not
14+
// so in case it does we want to subtract it to get the correct left offset.
15+
if (x - insets.left >= 0) {
16+
return x - insets.left;
17+
}
18+
19+
return x;
20+
}
21+
22+
if (shouldUseNarrowLayout) {
23+
return x;
24+
}
25+
26+
return bigScreenLeftOffset;
27+
}
28+
29+
export default getLeftOffset;

src/components/AutoCompleteSuggestions/index.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import useWindowDimensionsForAutoCompleteSuggestions from '@hooks/useWindowDimen
77
import {hasHoverSupport} from '@libs/DeviceCapabilities';
88
import CONST from '@src/CONST';
99
import AutoCompleteSuggestionsPortal from './AutoCompleteSuggestionsPortal';
10+
import getLeftOffset from './getSuggestionsLeftOffset';
1011
import type {AutoCompleteSuggestionsProps, MeasureParentContainerAndCursor} from './types';
1112

1213
const measureHeightOfSuggestionRows = (numRows: number, canBeBig: boolean, isInLandscapeMode: boolean): number => {
@@ -50,13 +51,6 @@ const initialContainerState = {
5051
cursorCoordinates: {x: 0, y: 0},
5152
};
5253

53-
function getLeftOffset(x: number, leftInset: number, bigScreenLeftOffset: number, shouldUseNarrowLayout: boolean, isInLandscapeMode: boolean): number {
54-
if (shouldUseNarrowLayout) {
55-
return isInLandscapeMode ? x - leftInset : x;
56-
}
57-
return bigScreenLeftOffset;
58-
}
59-
6054
/**
6155
* On the mobile-web platform, when long-pressing on auto-complete suggestions,
6256
* we need to prevent focus shifting to avoid blurring the main input (which makes the suggestions picker close and fires the onSelect callback).
@@ -78,7 +72,6 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainerAndReportCu
7872
const insets = useSafeAreaInsets();
7973
const {keyboardHeight, isKeyboardAnimatingRef} = useKeyboardState();
8074
const {paddingBottom: bottomInset, paddingTop: topInset} = StyleUtils.getPlatformSafeAreaPadding(insets ?? undefined);
81-
const {left: leftInset} = insets;
8275

8376
useEffect(() => {
8477
const container = containerRef.current;
@@ -136,7 +129,7 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainerAndReportCu
136129
topInset,
137130
});
138131

139-
const newLeftOffset = getLeftOffset(x, leftInset, bigScreenLeftOffset, shouldUseNarrowLayout, isInLandscapeMode);
132+
const newLeftOffset = getLeftOffset(x, insets, bigScreenLeftOffset, shouldUseNarrowLayout, width, windowWidth, isInLandscapeMode);
140133
// If the suggested word is longer than 150 (approximately half the width of the suggestion popup), then adjust a new position of popup
141134
const isAdjustmentNeeded = Math.abs(prevLeftValue.current - bigScreenLeftOffset) > 150;
142135
if (isInitialRender.current || isAdjustmentNeeded || prevIsInLandscapeModeValue.current !== isInLandscapeMode) {
@@ -179,7 +172,7 @@ function AutoCompleteSuggestions<TSuggestion>({measureParentContainerAndReportCu
179172
topInset,
180173
isKeyboardAnimatingRef,
181174
isInLandscapeMode,
182-
leftInset,
175+
insets,
183176
]);
184177

185178
// Prevent rendering if container dimensions are not set or if we have no suggestions

0 commit comments

Comments
 (0)