react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

BottomSheetTextInput that has multiline enabled, does not push bottom sheet up when focused and keyboard shows.

Open jonesaustindev opened this issue 5 years ago • 28 comments

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.

  1. Make one BottomSheetTextInput have multiline while the other does not.
  2. Tap the one without multiline to see it function correctly.
  3. Tap the one with multiline to see it does not slide up the bottom sheet.

Describe what you expected to happen:

  1. Keyboard should push up the bottom sheet when using BottomSheetTextInput with multiline enabled.

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,
  },

jonesaustindev avatar Apr 20 '21 17:04 jonesaustindev

I've also noticed that Android doesn't seem to scroll inside. I might be missing something though since that should work.

jonesaustindev avatar Apr 21 '21 18:04 jonesaustindev

Any news with this? :)

marcibk avatar May 14 '21 07:05 marcibk

Any update on BottomSheetTextInput with multiline?

VithuJey avatar May 14 '21 14:05 VithuJey

@jonesaustindev Did you find any way?

VithuJey avatar May 14 '21 14:05 VithuJey

@gorhom Can you please look into this?

VithuJey avatar May 14 '21 15:05 VithuJey

@gorhom Also having this issue, snack with the multiline bug https://snack.expo.io/@setjetters/excited-french-fries

theianjohnson avatar May 17 '21 20:05 theianjohnson

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.

github-actions[bot] avatar Jul 05 '21 09:07 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Jul 11 '21 09:07 github-actions[bot]

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 :(

armanian avatar Jul 24 '21 21:07 armanian

Facing the same problem. Any solutions yet guys? Thank you

anhquan291 avatar Jul 29 '21 14:07 anhquan291

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?

dickfickling avatar Aug 06 '21 19:08 dickfickling

Hi everyone, sorry for the delay, this issue is resolved for v4 and it will release on 4.0.0-alpha.25 👍

gorhom avatar Aug 06 '21 20:08 gorhom

:heart: thank you @gorhom!

dickfickling avatar Aug 06 '21 21:08 dickfickling

Awesome, thank you @gorhom!

jonesaustindev avatar Aug 06 '21 21:08 jonesaustindev

Does anybody still have an issue ? I'm on version 4.5.1 and it still doesn't work for me.

melissa07 avatar Feb 20 '24 17:02 melissa07

@gorhom It still doesn't seem to work, could you please look into this.

SyedTayyabUlMazhar avatar Apr 25 '24 16:04 SyedTayyabUlMazhar

Yes please, using 4.6.1 and it doesnt work on multiline inputs

bim-oulabi avatar May 08 '24 07:05 bim-oulabi

Same on v5, removing multiline fixes it immediately.

aldebout avatar Sep 12 '24 13:09 aldebout