Skip to content

Commit c1efa0d

Browse files
committed
refactor: drop the orientation tracking from the window size change store
1 parent b6927a9 commit c1efa0d

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

src/libs/Navigation/PlatformStackNavigation/createPlatformStackNavigatorComponent/ScreenActivityWrapper/useIsWindowSizeChanging.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {useSyncExternalStore} from 'react';
33
import {getSnapshot, subscribe} from './windowSizeChangeStore';
44

55
/**
6-
* Reports whether the window width or the orientation is changing, on both platforms. A screen hidden by
6+
* Reports whether the window width is changing, on both platforms. A screen hidden by
77
* <Activity> has no mounted effects, so it reads this flag to become visible for the duration of the change and
88
* lay itself out while still covered. The existing useIsResizing does not fit here, because it is web only and
99
* also counts the height changes the soft keyboard causes. The hook lives apart from windowSizeChangeStore because

src/libs/Navigation/PlatformStackNavigation/createPlatformStackNavigatorComponent/ScreenActivityWrapper/windowSizeChangeStore.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const WINDOW_SIZE_CHANGE_DURATION_MS = 250;
1212

1313
let isWindowSizeChanging = false;
1414
let lastWidth = 0;
15-
let lastIsPortrait = true;
1615
let stopTimeoutID: NodeJS.Timeout | undefined;
1716
let dimensionsSubscription: EmitterSubscription | undefined;
1817

@@ -32,31 +31,23 @@ function setIsWindowSizeChanging(value: boolean) {
3231
notify();
3332
}
3433

35-
function isPortrait(size: ScaledSize) {
36-
return size.height >= size.width;
37-
}
38-
39-
function rememberWindowSize(size: ScaledSize) {
40-
lastWidth = size.width;
41-
lastIsPortrait = isPortrait(size);
42-
}
43-
4434
function handleDimensionsChange({window}: {window: ScaledSize}) {
45-
// Only width and orientation changes count, because the soft keyboard changes the window height on Android and
46-
// on mobile web, and reacting to that would remount the effects of every hidden screen on each keyboard toggle.
47-
if (window.width === lastWidth && isPortrait(window) === lastIsPortrait) {
35+
// Only width changes count, which also covers a rotation. The soft keyboard changes the window height on
36+
// Android and on mobile web, and reacting to that would remount the effects of every hidden screen on each
37+
// keyboard toggle.
38+
if (window.width === lastWidth) {
4839
return;
4940
}
5041

51-
rememberWindowSize(window);
42+
lastWidth = window.width;
5243
setIsWindowSizeChanging(true);
5344
clearTimeout(stopTimeoutID);
5445
stopTimeoutID = setTimeout(() => setIsWindowSizeChanging(false), WINDOW_SIZE_CHANGE_DURATION_MS);
5546
}
5647

5748
function subscribe(listener: () => void) {
5849
if (listeners.size === 0) {
59-
rememberWindowSize(Dimensions.get('window'));
50+
lastWidth = Dimensions.get('window').width;
6051
dimensionsSubscription = Dimensions.addEventListener('change', handleDimensionsChange);
6152
}
6253
listeners.add(listener);

0 commit comments

Comments
 (0)