Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

36218 cached viewport height conflict event #36302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks/useDebouncedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import CONST from '@src/CONST';
* @example
* const [value, debouncedValue, setValue] = useDebouncedState<string>("", 300);
*/
function useDebouncedState<T>(initialValue: T, delay = CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME): [T, T, (value: T) => void] {
function useDebouncedState<T>(initialValue: T, delay: number = CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME): [T, T, (value: T) => void] {
const [value, setValue] = useState(initialValue);
const [debouncedValue, setDebouncedValue] = useState(initialValue);
const debouncedSetDebouncedValue = useRef(debounce(setDebouncedValue, delay)).current;
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/useWindowDimensions/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {useEffect, useRef, useState} from 'react';
import {useEffect, useRef} from 'react';
// eslint-disable-next-line no-restricted-imports
import {Dimensions, useWindowDimensions} from 'react-native';
import useDebouncedState from '@hooks/useDebouncedState';
import * as Browser from '@libs/Browser';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import type WindowDimensions from './types';

const initalViewportHeight = window.visualViewport?.height ?? window.innerHeight;
Expand All @@ -26,7 +28,7 @@ export default function (useCachedViewportHeight = false): WindowDimensions {
const lowerScreenDimmension = Math.min(windowWidth, windowHeight);
const isSmallScreen = lowerScreenDimmension <= variables.mobileResponsiveWidthBreakpoint;

const [cachedViewportHeight, setCachedViewportHeight] = useState(windowHeight);
const [, cachedViewportHeight, setCachedViewportHeight] = useDebouncedState(windowHeight, CONST.TIMING.RESIZE_DEBOUNCE_TIME);

const handleFocusIn = useRef((event: FocusEvent) => {
const targetElement = event.target as HTMLElement;
Expand Down Expand Up @@ -69,6 +71,7 @@ export default function (useCachedViewportHeight = false): WindowDimensions {
return;
}
setCachedViewportHeight(windowHeight);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [windowHeight, isCachedViewportHeight]);

useEffect(() => {
Expand Down
Loading