Skip to content

Commit

Permalink
[RNMobile] Fix BottomSheet.SubSheet/TextInput Conflict (#33845)
Browse files Browse the repository at this point in the history
* Remove 'BottomSheetScreen' component

The 'BottomSheetScreen' component was introduced in the following commit in order to correct a render error related to the 'setIsFullScreen' method: d650b4f#diff-d16d37d09ff59dce57c087e978ac5536503cb1642ec2b0ecdba9536f5c695b95R20

The way the component's currently rendering is causing a conflict with the TextInput component, however.

With this commit, the component's removed, along with the 'setIsFullScreen' method (the method will be re-introduced in the following commits).

* Refactor 'setIsFullScreen' method

With this commit, the 'setIsFullScreen' method is added back to the component. This time, it's added to its own separate 'useEffect' function.

* Remove 'BottomSheetConsumer'

'BottomSheetConsumer' is no longer necessary as we're now using 'useContext' to pull in 'setIsFullScreen'.

Further discussion here: #33845 (comment)

* Refactor reference to 'children'

As 'BottomSheetConsumer' was removed in 5232398, 'children' no longer needs to be returned as part of a function. In fact, this results in an error.

With this commit, the function surrounding the reference to 'children' is removed.
  • Loading branch information
SiobhyB authored and Siobhan committed Aug 4, 2021
1 parent 98d9830 commit 1b88f23
Showing 1 changed file with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { SafeAreaView } from 'react-native';
/**
* WordPress dependencies
*/
import { Children, useEffect } from '@wordpress/element';
import { createSlotFill, BottomSheetConsumer } from '@wordpress/components';
import { Children, useEffect, useContext } from '@wordpress/element';
import { createSlotFill, BottomSheetContext } from '@wordpress/components';

const { Fill, Slot } = createSlotFill( 'BottomSheetSubSheet' );

Expand All @@ -17,26 +17,19 @@ const BottomSheetSubSheet = ( {
showSheet,
isFullScreen,
} ) => {
const BottomSheetScreen = ( { onMount } ) => {
useEffect( onMount, [] );
return children ?? null;
};
const { setIsFullScreen } = useContext( BottomSheetContext );

useEffect( () => {
if ( showSheet ) {
setIsFullScreen( isFullScreen );
}
}, [ showSheet, isFullScreen ] );

return (
<>
{ showSheet && (
<Fill>
<SafeAreaView>
<BottomSheetConsumer>
{ ( { setIsFullScreen } ) => (
<BottomSheetScreen
onMount={ () =>
setIsFullScreen( isFullScreen )
}
/>
) }
</BottomSheetConsumer>
</SafeAreaView>
<SafeAreaView>{ children }</SafeAreaView>
</Fill>
) }
{ Children.count( children ) > 0 && navigationButton }
Expand Down

0 comments on commit 1b88f23

Please sign in to comment.