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

Fix BottomSheet navigation hardware back button support #37426

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ const BottomSheetNavigationScreen = ( {
onHandleHardwareButtonPress( null );
return false;
} );
/**
* TODO: onHandleHardwareButtonPress stores a single value, which means
* future invocations from sibling screens can replace the callback for
* the currently active screen. Currently, the empty dependency array
* passed to useCallback here is what prevents erroneous callback
* replacements, but leveraging memoization to achieve this is brittle and
* explicitly discouraged in the React documentation.
* https://reactjs.org/docs/hooks-reference.html#usememo
*
* Ideally, we refactor onHandleHardwareButtonPress to manage multiple
* callbacks triggered based upon which screen is currently active.
*
* Related: https://git.io/JD2no
*/
}, [] )
);

useFocusEffect(
useCallback( () => {
if ( fullScreen ) {
setHeight( '100%' );
setIsFullScreen( true );
Expand All @@ -67,6 +86,7 @@ const BottomSheetNavigationScreen = ( {
return () => {};
}, [ setHeight ] )
);

const onLayout = ( { nativeEvent } ) => {
if ( fullScreen ) {
return;
Expand All @@ -78,6 +98,7 @@ const BottomSheetNavigationScreen = ( {
setHeightDebounce( height );
}
};

return useMemo( () => {
return isScrollable || isNested ? (
<View
Expand Down