-
Notifications
You must be signed in to change notification settings - Fork 24k
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
Empty Space added at the end when we use KeyboardAvoidingView with ScrollView #35639
Comments
try not to include <ScrollView
contentContainerStyle={{flexGrow: 1}}
keyboardShouldPersistTaps={'handled'}
style={backgroundStyle}>
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
keyboardVerticalOffset={70}
style={{flex: 1, justifyContent: 'space-between'}}>
<View style={{flex: 1, marginHorizontal: 10}}>
<Text style={{fontSize: 22, marginVertical: 20}}>Label 1</Text>
<Text style={{fontSize: 22, marginVertical: 20}}>Label 2</Text>
<Text style={{fontSize: 22, marginVertical: 20}}>Label 3</Text>
<Text style={{fontSize: 22, marginVertical: 20}}>Label 4</Text>
<Text style={{fontSize: 22, marginVertical: 20}}>Label 5</Text>
<Input placeHolder={'Input 1'} />
<Input placeHolder={'Input 2'} />
<Input placeHolder={'Input 3'} />
</View>
</KeyboardAvoidingView>
<TouchableOpacity style={{marginVertical: 20}}>
<View
style={{
backgroundColor: '#3498db',
marginHorizontal: 20,
alignItems: 'center',
borderRadius: 10,
}}>
<Text style={{fontSize: 22, marginVertical: 20}}>Button</Text>
</View>
</TouchableOpacity>
</ScrollView> |
That just moves the Button out of the visible area. The empty space still keeps on adding. Untitled.mov |
I hope the sample code is sufficient to regenerate the issue. Let me know if you need any other info. |
Any updates on this or do we have a workaround available? |
as you replied, a solution I wrote did not fix this issue, I'm trying to fix this issue by updating Libraries/Components/Keyboard/KeyboardAvoidingView I'll comment in this issue, if any updates confirmed |
Solution1. Open KeyboardAvoidingView.jsOpen 2. import Dimensions libraryimport Diemensions lib in import Dimensions from '../../Utilities/Dimensions' 3. find _relativeKeyboardHeight function and edit as follows async _relativeKeyboardHeight(
keyboardFrame: KeyboardMetrics,
): Promise<number> {
const frame = this._frame;
if (!frame || !keyboardFrame) {
return 0;
}
// On iOS when Prefer Cross-Fade Transitions is enabled, the keyboard position
// & height is reported differently (0 instead of Y position value matching height of frame)
if (
Platform.OS === 'ios' &&
keyboardFrame.screenY === 0 &&
(await AccessibilityInfo.prefersCrossFadeTransitions())
) {
return 0;
}
const keyboardY =
keyboardFrame.screenY - (this.props.keyboardVerticalOffset ?? 0);
if (this.props.behavior === 'height') {
return Math.max(
this.state.bottom + frame.y + frame.height - keyboardY,
0,
);
}
const deviceY = Dimensions.get('screen').height // <-- INSERT THIS CODE
return Math.max(frame.y + deviceY - keyboardY, 0); // <-- EDIT frame.height TO deviceY
} It works!Simulator.Screen.Recording.-.iPhone.14.-.2023-02-07.at.19.35.32.mp4Tip: recommend to use ReasonThe problem was As a result, it was maintaining and increasing the paddingBottom even after disabling the keyboard was deactivated. Therefore, I modified the code in a different way without using in case of keyboardVerticalOffset is 0, Therefore, additional paddingBottom is set to (keyboard height) when the keyboard is activated, and paddingBottom is set to zero when the keyboard is disabled. If you have any feedback such as knowing the exact calculation method for frame.height, please let me know anytime. Well.. I hope it helps. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Description
When I use
KeyboardAvoidingView
inside aScrollView
with behaviour set topadding
. Empty space gets added to the end of the screen each time I switch between theInputText
.Version
0.70.6
Output of
npx react-native info
Steps to reproduce
I am using the
KeyboardAvoidingView
within theScrollView
. The idea is to have the Button in the footer.Empty Space is added at the end of the screen when we use KeyboardAvoidingView with ScrollView. For iOS, I am using behaviour as
padding
and have set akeyboardVerticalOffset
value of70
.I have attached the sample code with which I am able to regenerate the issue.
Video showing what the issue is:
Screen.Recording.2022-12-14.at.2.55.43.PM.mov
Snack, code example, screenshot, or link to a repository
Attaching the sample code with which I am getting the issue.
The text was updated successfully, but these errors were encountered: