-
-
Notifications
You must be signed in to change notification settings - Fork 643
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
ChatScreen: Fix blank strip between compose box and keyboard on iOS #5564
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ import React from 'react'; | |
import type { Node } from 'react'; | ||
import { Platform, View } from 'react-native'; | ||
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet'; | ||
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
|
||
import KeyboardAvoidingView from '../third/react-native/KeyboardAvoidingView'; | ||
|
||
|
@@ -12,8 +13,9 @@ type Props = $ReadOnly<{| | |
style?: ViewStyleProp, | ||
contentContainerStyle?: ViewStyleProp, | ||
|
||
/** How much the top of `KeyboardAvoider`'s layout *parent* is | ||
* displaced downward from the top of the screen. | ||
/** | ||
* How much the top of `KeyboardAvoider`'s layout *parent* is | ||
* displaced downward from the top of the screen. | ||
* | ||
* If this isn't set correctly, the keyboard will hide some of | ||
* the bottom of the screen (an area whose height is what this | ||
|
@@ -30,6 +32,19 @@ type Props = $ReadOnly<{| | |
* we can use to balance the equation if we need to. | ||
*/ | ||
keyboardVerticalOffset?: number, | ||
|
||
/** | ||
* Whether to shorten the excursion by the height of the bottom inset. | ||
* | ||
* Use this when a child component uses SafeAreaView to pad the bottom | ||
* inset, and you want the open keyboard to cover that padding. | ||
* | ||
* (SafeAreaView has a bug where it applies a constant padding no matter | ||
* where it's positioned onscreen -- so in particular, if you ask for | ||
* bottom padding, you'll get bottom padding even when KeyboardAvoider | ||
* pushes the SafeAreaView up and out of the bottom inset.) | ||
Comment on lines
+39
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems very clear, thanks! |
||
*/ | ||
compensateOverpadding?: boolean, | ||
|}>; | ||
|
||
/** | ||
|
@@ -40,7 +55,16 @@ type Props = $ReadOnly<{| | |
* to that component. | ||
*/ | ||
export default function KeyboardAvoider(props: Props): Node { | ||
const { behavior, children, style, contentContainerStyle, keyboardVerticalOffset } = props; | ||
const { | ||
behavior, | ||
children, | ||
style, | ||
contentContainerStyle, | ||
keyboardVerticalOffset = 0, // Same default value as KeyboardAvoidingView | ||
compensateOverpadding = false, | ||
} = props; | ||
|
||
const bottomInsetHeight = useSafeAreaInsets().bottom; | ||
|
||
if (Platform.OS === 'android') { | ||
return <View style={style}>{children}</View>; | ||
|
@@ -51,7 +75,13 @@ export default function KeyboardAvoider(props: Props): Node { | |
behavior={behavior} | ||
contentContainerStyle={contentContainerStyle} | ||
// See comment on this prop in the jsdoc. | ||
keyboardVerticalOffset={keyboardVerticalOffset} | ||
keyboardVerticalOffset={ | ||
keyboardVerticalOffset | ||
// A negative term here reduces the bottom inset we use for the | ||
// child, when the keyboard is open, so that the keyboard covers its | ||
// bottom padding. | ||
+ (compensateOverpadding ? -bottomInsetHeight : 0) | ||
} | ||
style={style} | ||
> | ||
{children} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's have a comment at the use of
SafeAreaView
inComposeBox
, too, saying that when the keyboard is open it's compensated for here.