Skip to content

Commit

Permalink
Merge pull request Expensify#36302 from suneox/36218-cached-viewport-…
Browse files Browse the repository at this point in the history
…overlap-keyboard

36218 cached viewport height conflict event
  • Loading branch information
Julesssss authored Feb 20, 2024
2 parents 52ed833 + 420edfa commit 0f372c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit 0f372c2

Please sign in to comment.