-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51318 from truph01/fix/50663
fix: Submit button hang in middle page
- Loading branch information
Showing
3 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {useCallback, useEffect, useState} from 'react'; | ||
import usePrevious from '@hooks/usePrevious'; | ||
import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
|
||
const useIsWindowHeightReducedByKeyboard = () => { | ||
const [isWindowHeightReducedByKeyboard, setIsWindowHeightReducedByKeyboard] = useState(false); | ||
const {windowHeight} = useWindowDimensions(); | ||
const prevWindowHeight = usePrevious(windowHeight); | ||
const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
const toggleKeyboardOnSmallScreens = useCallback( | ||
(isKBOpen: boolean) => { | ||
if (!shouldUseNarrowLayout) { | ||
return; | ||
} | ||
setIsWindowHeightReducedByKeyboard(isKBOpen); | ||
}, | ||
[shouldUseNarrowLayout], | ||
); | ||
useEffect(() => { | ||
// Use window height changes to toggle the keyboard. To maintain keyboard state | ||
// on all platforms we also use focus/blur events. So we need to make sure here | ||
// that we avoid redundant keyboard toggling. | ||
// Minus 100px is needed to make sure that when the internet connection is | ||
// disabled in android chrome and a small 'No internet connection' text box appears, | ||
// we do not take it as a sign to open the keyboard | ||
if (!isWindowHeightReducedByKeyboard && windowHeight < prevWindowHeight - 100) { | ||
toggleKeyboardOnSmallScreens(true); | ||
} else if (isWindowHeightReducedByKeyboard && windowHeight > prevWindowHeight) { | ||
toggleKeyboardOnSmallScreens(false); | ||
} | ||
}, [isWindowHeightReducedByKeyboard, prevWindowHeight, toggleKeyboardOnSmallScreens, windowHeight]); | ||
|
||
return isWindowHeightReducedByKeyboard; | ||
}; | ||
|
||
export default useIsWindowHeightReducedByKeyboard; |