-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #40562 from software-mansion-labs/fix/notification…
…-preferences-animation [CP Staging] Fix selecting items and animating Pages with SelectionList (cherry picked from commit 2c15ccc)
- Loading branch information
1 parent
8e59b84
commit 00520bb
Showing
3 changed files
with
12 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import {useLayoutEffect} from 'react'; | ||
import type {RefObject} from 'react'; | ||
import type {View} from 'react-native'; | ||
import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus'; | ||
|
||
/** | ||
* Custom React hook created to handle sync of focus on an element when the user navigates through the app with keyboard. | ||
* When the user navigates through the app using the arrows and then the tab button, the focus on the element and the native focus of the browser differs. | ||
* To maintain consistency when an element is focused in the app, the focus() method is additionally called on the focused element to eliminate the difference between native browser focus and application focus. | ||
*/ | ||
const useSyncFocus = (ref: RefObject<HTMLDivElement | View>, isFocused: boolean) => { | ||
const useSyncFocus = (ref: RefObject<HTMLDivElement | View>, isFocused: boolean, shouldSyncFocus = true) => { | ||
const {didScreenTransitionEnd} = useScreenWrapperTranstionStatus(); | ||
|
||
useLayoutEffect(() => { | ||
if (!isFocused) { | ||
if (!isFocused || !shouldSyncFocus || !didScreenTransitionEnd) { | ||
return; | ||
} | ||
|
||
ref.current?.focus(); | ||
}, [isFocused, ref]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [didScreenTransitionEnd, isFocused, ref]); | ||
}; | ||
|
||
export default useSyncFocus; |
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