BottomSheetTextInput that has multiline enabled, does not push bottom sheet up when focused and keyboard shows.
Bug
BottomSheetTextInput that has multiline enabled, does not push bottom sheet up when focused and keyboard shows. If I remove the ability to have multiline enabled, it works as expected with no issue.
https://user-images.githubusercontent.com/36755092/115439911-b662d080-a1d4-11eb-96e7-8a5fad951076.mov
Environment info
| Library | Version |
|---|---|
| @gorhom/bottom-sheet | "^3.6.3" |
| react-native | "0.63.4" |
| react-native-reanimated | "^2.0.0" |
| react-native-gesture-handler | "^1.9.0" |
Steps To Reproduce
Setting up a simple implementation of the BottomSheetModal will show how it behaves.
- Make one
BottomSheetTextInputhave multiline while the other does not. - Tap the one without
multilineto see it function correctly. - Tap the one with
multilineto see it does not slide up the bottom sheet.
Describe what you expected to happen:
- Keyboard should push up the bottom sheet when using
BottomSheetTextInputwithmultilineenabled.
Reproducible sample code
Note: This is inside a wrapper component that just has data/state management with a View with the style {{ flex: 1, justifyContent: 'center', alignItems: 'center' }}.
import React, { useContext, useMemo, useRef } from 'react';
import { StyleSheet, ScrollView, TouchableOpacity, Platform } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useNavigation } from '@react-navigation/core';
import {
BottomSheetModal,
BottomSheetModalProvider,
BottomSheetBackdrop,
BottomSheetTextInput,
BottomSheetScrollView,
} from '@gorhom/bottom-sheet';
import { Text } from '../components/common/Text';
import { View } from '../components/common/View';
import { Button } from '../components/common/Button';
import { ReorderIcon } from '../assets/svg/ReorderIcon';
import { ACTIVE_OPACITY } from '../constants';
import { localizedStrings } from '../localization/localizedStrings';
import { colors, globalStyles, SCREEN_HEIGHT, SCREEN_WIDTH } from '../styles/globalStyles';
import { GradientFooter } from '../components/common/GradientFooter';
import { HorizontalLine } from '../components/common/HorizontalLine';
export const ListScreen: React.FC<{}> = () => {
const { top, bottom } = useSafeAreaInsets();
const { goBack } = useNavigation();
const buttonMargin = Platform.OS === 'ios' ? bottom - 8 : bottom + 16;
const sheetRef = useRef<BottomSheetModal>(null);
const snapPoints = useMemo(() => ['35%'], []);
const handleShowPress = () => {
sheetRef.current && sheetRef.current.present();
};
return (
<>
<ScrollView
style={[styles.container, { paddingTop: top + globalStyles.standardPadding * 2 }]}
>
<View style={styles.header}>
<TouchableOpacity
// TODO re-order feature
onPress={() => {}}
activeOpacity={ACTIVE_OPACITY}
style={styles.rightAlign}
>
<ReorderIcon />
</TouchableOpacity>
<View style={styles.center}>
<View style={styles.button} marginVertical={globalStyles.screenPadding}>
<Button
fontSize={14}
title={'+ Add to List'}
onPress={handleShowPress}
/>
</View>
</View>
</View>
</ScrollView>
<GradientFooter style={styles.center}>
<TouchableOpacity
hitSlop={{ left: 30, right: 30 }}
activeOpacity={ACTIVE_OPACITY}
onPress={goBack}
>
<Text fontSize={14} style={{ marginTop: buttonMargin }} fontFamily="americaBold">
{localizedStrings.labels.back}
</Text>
</TouchableOpacity>
</GradientFooter>
<BottomSheetModalProvider>
<BottomSheetModal
ref={sheetRef}
snapPoints={snapPoints}
keyboardBehavior="interactive"
keyboardBlurBehavior="restore"
handleComponent={null}
backdropComponent={BottomSheetBackdrop}
style={{ ...globalStyles.shadow }}
>
<BottomSheetScrollView style={[styles.cardContent, { paddingBottom: bottom * 4 }]}>
<BottomSheetTextInput
placeholder="Add title"
placeholderTextColor={colors.grey}
style={styles.text}
accessibilityComponentType
accessibilityTraits
/>
<HorizontalLine width={'100%'} />
<BottomSheetTextInput
placeholder="Add more details"
placeholderTextColor={colors.grey}
style={styles.text}
multiline
accessibilityComponentType
accessibilityTraits
/>
</BottomSheetScrollView>
</BottomSheetModal>
</BottomSheetModalProvider>
</>
);
};
const styles = StyleSheet.create({
absolute: {
position: 'absolute',
},
bottom: {
...globalStyles.shadow,
paddingTop: globalStyles.standardPadding,
padding: globalStyles.screenPadding,
},
button: {
width: 170,
},
cardContent: {
padding: globalStyles.screenPadding,
},
center: {
alignItems: 'center',
justifyContent: 'center',
},
container: {
flex: 1,
},
header: {
paddingHorizontal: globalStyles.screenPadding,
},
image: {
width: '100%',
position: 'absolute',
},
rightAlign: {
alignSelf: 'flex-end',
},
text: {
paddingVertical: globalStyles.standardPadding * 2,
},
I've also noticed that Android doesn't seem to scroll inside. I might be missing something though since that should work.
Any news with this? :)
Any update on BottomSheetTextInput with multiline?
@jonesaustindev Did you find any way?
@gorhom Can you please look into this?
@gorhom Also having this issue, snack with the multiline bug https://snack.expo.io/@setjetters/excited-french-fries
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
Same here. Can confirm that the issue is caused by multiline={true} and as soon as I disable it, keyboard starts working as expected. The issues is that the inner implementation of BottomSheetTextInput is pretty straightforward and it just sets whether bottom sheet should handle keyboard events or not. I'm really confused and it is a good question, where to fix it, because it doesn't really look like we can blame BottomSheetTextInput here
It would be great to reopen the issue, because it is clearly there and needs fixing
Same here :(
Facing the same problem. Any solutions yet guys? Thank you
I don't have a solution, but I've narrowed it down. With single line text inputs, the onFocus handler is reliably called before the keyboardWillShow event. In handleKeyboardEvent, the code expects that shouldHandleKeyboardEvents has been set to true by the onFocus handler. If it's false, it doesn't update the keyboard height/visibility state, and therefore doesn't move the view.
When multiline is set to true, the keyboardWillShow handler executes before onFocus, so shouldHandleKeyboardEvents is false, and none of the views are updated.
I'm not really sure why shouldHandleKeyboardEvents is needed in the first place. Perhaps it's a performance tweak? Removing all references to it fixes this bug and everything else seems to continue working, but maybe there's an edge case I'm missing.
@gorhom would you mind reopening this issue?
Hi everyone, sorry for the delay, this issue is resolved for v4 and it will release on 4.0.0-alpha.25 👍
:heart: thank you @gorhom!
Awesome, thank you @gorhom!
Does anybody still have an issue ? I'm on version 4.5.1 and it still doesn't work for me.
@gorhom It still doesn't seem to work, could you please look into this.
Yes please, using 4.6.1 and it doesnt work on multiline inputs
Same on v5, removing multiline fixes it immediately.