-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[RNMobile] Bottom-sheet: Add custom header #30291
Conversation
Size Change: 0 B Total Size: 1.31 MB ℹ️ View Unchanged
|
( safeAreaBottomInset || | ||
styles.list.paddingBottom ) + searchFormHeight, | ||
safeAreaBottomInset || styles.list.paddingBottom, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer need to add the search form height here because this value is now included in the calculations of the maxHeight
, which is part of the style prop contentContainerStyle
.
if ( ! this.props.isVisible ) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to prevent executing any logic related to keyboard show/hide events for non-visible bottom-sheets. Not sure if there would be a case that would require this but at least we should prevent triggering layout animations because they're global.
This value that was being used for calculating the padding bottom of the search results view is no longer needed.
this.keyboardWillShowListener = Keyboard.addListener( | ||
'keyboardWillShow', | ||
this.keyboardWillShow | ||
this.keyboardShowListener = Keyboard.addListener( | ||
Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow', | ||
this.keyboardShow | ||
); | ||
|
||
this.keyboardDidHideListener = Keyboard.addListener( | ||
'keyboardDidHide', | ||
this.keyboardDidHide | ||
this.keyboardHideListener = Keyboard.addListener( | ||
Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', | ||
this.keyboardHide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will
keyboard events are not available on Android (documentation reference).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worthwhile leaving a code comment inline stating this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I've added the comment in this commit.
d30efdb
to
e35bff5
Compare
this.keyboardHeight = height; | ||
this.performKeyboardLayoutAnimation( e ); | ||
this.onSetMaxHeight(); | ||
this.props.onKeyboardShow?.(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This callback and onKeyboardHide
will allow us to sync potential changes in the layout with the layout animations triggered from performKeyboardLayoutAnimation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Tested on an iPhone SE and Samsung Galaxy S20.
The supplied patch did not work for me as changes were made after the patch creation. So, I created a new patch below if anyone needs it for future use.
Add header to inserter diff
diff --cc packages/block-editor/src/components/inserter/menu.native.js
index a81cfbd184,3032d0b39d..0000000000
--- a/packages/block-editor/src/components/inserter/menu.native.js
+++ b/packages/block-editor/src/components/inserter/menu.native.js
@@@ -39,8 -39,10 +39,9 @@@ function InserterMenu(
insertionIndex,
} ) {
const [ filterValue, setFilterValue ] = useState( '' );
- const [ searchFormHeight, setSearchFormHeight ] = useState( 0 );
// eslint-disable-next-line no-undef
const [ showSearchForm, setShowSearchForm ] = useState( __DEV__ );
+ const [ showExtraHeader, setShowExtraHeader ] = useState( true );
const {
showInsertionPoint,
@@@ -180,14 -182,33 +181,29 @@@
<BottomSheet
isVisible={ true }
onClose={ onClose }
+ onKeyboardShow={ () => setShowExtraHeader( false ) }
+ onKeyboardHide={ () => setShowExtraHeader( true ) }
header={
showSearchForm && (
- <InserterSearchForm
- onChange={ ( value ) => {
- setFilterValue( value );
- } }
- value={ filterValue }
- />
+ <>
+ <InserterSearchForm
+ onChange={ ( value ) => {
+ setFilterValue( value );
+ } }
+ value={ filterValue }
- onLayout={ ( event ) => {
- const { height } = event.nativeEvent.layout;
- setSearchFormHeight( height );
- } }
+ />
+ { showExtraHeader && (
+ <View
+ style={ {
+ marginHorizontal: 8,
+ marginBottom: 20,
+ height: 40,
+ borderRadius: 8,
+ backgroundColor: 'black',
+ } }
+ />
+ ) }
+ </>
)
}
hasNavigation
if ( duration && easing ) { | ||
const animationConfig = { | ||
// We have to pass the duration equal to minimal accepted duration defined here: RCTLayoutAnimation.m | ||
duration: duration > 10 ? duration : 10, | ||
type: LayoutAnimation.Types[ easing ] || 'keyboard', | ||
}; | ||
const layoutAnimation = { | ||
duration: animationConfig.duration, | ||
update: animationConfig, | ||
create: { | ||
...animationConfig, | ||
property: LayoutAnimation.Properties.opacity, | ||
}, | ||
delete: { | ||
...animationConfig, | ||
property: LayoutAnimation.Properties.opacity, | ||
}, | ||
}; | ||
LayoutAnimation.configureNext( layoutAnimation ); | ||
this.lastLayoutAnimation = layoutAnimation; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the original note in your other branch that this code came form React Native's internal KeyboardAvoidingView
was helpful, personally. It may be worth adding the comment that is the origin of this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to remove it because I wasn't really applying the same code but I agree that it would be helpful to keep the reference 👍 , I reverted the change in this commit.
this.keyboardWillShowListener = Keyboard.addListener( | ||
'keyboardWillShow', | ||
this.keyboardWillShow | ||
this.keyboardShowListener = Keyboard.addListener( | ||
Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow', | ||
this.keyboardShow | ||
); | ||
|
||
this.keyboardDidHideListener = Keyboard.addListener( | ||
'keyboardDidHide', | ||
this.keyboardDidHide | ||
this.keyboardHideListener = Keyboard.addListener( | ||
Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide', | ||
this.keyboardHide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worthwhile leaving a code comment inline stating this.
@dcalhoun Heads up that I introduced a fix for preventing running multiple layout animations on Android (commit), I'd appreciate it if you could do a second review, thanks 🙇 ! This fix is related to the erroneous opacity issue we're discussing in #31151 (comment). |
Yep, sorry for that, and thanks for providing a new version 🙇 . I've updated the patch diff in the PR's description with a newer version due to the changes from recent commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest changes LGTM. I was unable to test on my iPhone SE due to builds issues unrelated to this PR. I tested on a Samsung Galaxy S20.
Android still has some animation jumping (matches current video in PR description), but my understanding is that is the current target. I did not experience any issues on Android regarding to the opacity of the block types within the inserter. 🎉
Thank you very much @dcalhoun for the review ❤️ !
Yeah, the jump that happens right after the keyboard is shown/hide is caused by the lack of the |
Description
Add a
header
prop for rendering a custom header in the bottom-sheet component. This PR also introduces fixes to address the issue related to the bottom-sheet component and the keyboard show/hide animation.Additionally, it also modifies how the inserter search form is rendered in the inserter menu, now it's rendered via the new
header
prop.How has this been tested?
Check header changes upon keyboard show/hide
As an additional test, I applied the changes from the patch diff to verify if making changes in the header when the keyboard is shown/hide could produce visual glitches.
Patch diff
Screenshots
bottom-sheet-header-ios.mp4
bottom-sheet-header-extra-ios.mp4
bottom-sheet-header-android.mp4
bottom-sheet-header-extra-android.mp4
As you can see on the videos, on Android the animation is different because we can't listen to the
will
events of the keyboard.Types of changes
Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).