Skip to content
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

[v4] | BottomSheetTextInput does not avoid Keyboard on Android #1817

Open
salahbm opened this issue Apr 27, 2024 · 1 comment
Open

[v4] | BottomSheetTextInput does not avoid Keyboard on Android #1817

salahbm opened this issue Apr 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@salahbm
Copy link

salahbm commented Apr 27, 2024

Bug

1. Using BottomSheetScrollView inside the BottomSheetModal which is perfectly working on Ios but Android.
2.BottomSheetTextInput should avoid keyboard fully

Environment info

Library Version
"@gorhom/bottom-sheet": "^4.6.1"
"react-native" : "0.73.6"
"react-native-reanimated": "~3.6.2"
react-native-gesture-handler ~2.14.0

Reproducible sample code

export const BottomSheetLayout = ({
  bottomSheetModalLayoutRef,
  children,
  snapPoints,
  index,
  ...options
}: Props) => {
  const [updateIndex, setUpdateIndex] = useState(0);

  const backdropComponent = useCallback(
    () => (
      <TouchableOpacity
        onPress={() => {
          bottomSheetModalLayoutRef?.current?.close();
          setUpdateIndex(0);
        }}
        style={{
          ...StyleSheet.absoluteFillObject,
        }}
      />
    ),
    [],
  );


  useEffect(() => {
    // only needed for Android because
    // keyboardBehavior="extend" is not working properly
    // on Android, it leaves a gap between the keyboard and the bottom sheet
    // when the keyboard is visible
    const showSubscription = Keyboard.addListener('keyboardDidShow', () => {
      if (Platform.OS === 'android') {
        bottomSheetModalLayoutRef.current?.snapToIndex(2);
      }
    });
    return () => {
      showSubscription.remove();
    };
  }, []);

  return (
    <BlurView intensity={100} tint="dark">
      <BottomSheetModal
        ref={bottomSheetModalLayoutRef}
        snapPoints={snapPoints}
        index={updateIndex}
        stackBehavior="push"
        handleStyle={{
          backgroundColor: COLORS.grey900,
          borderTopLeftRadius: updateIndex === 2 ? 0 : 12,
          borderTopRightRadius: updateIndex === 2 ? 0 : 12,
        }}
        backgroundComponent={() => (
          <View
            style={{
              ...StyleSheet.absoluteFillObject,
              backgroundColor: COLORS.grey900,
              borderTopLeftRadius: updateIndex === 2 ? 0 : 12,
              borderTopRightRadius: updateIndex === 2 ? 0 : 12,
            }}
          />
        )}
        handleIndicatorStyle={{ backgroundColor: COLORS.grey700 }}
        containerStyle={{ backgroundColor: 'rgba(0, 0, 0, 0.5)' }}
        keyboardBehavior={Platform.OS === 'ios' ? 'extend' : 'interactive'}
        keyboardBlurBehavior="restore"
        android_keyboardInputMode="adjustResize"
        enableHandlePanningGesture={false}
        backdropComponent={backdropComponent}
        onChange={(index: number) => {
          setUpdateIndex(index);
        }}
        onDismiss={() => {
          bottomSheetModalLayoutRef?.current?.close();
          setUpdateIndex(0);
        }}
        enableContentPanningGesture
        {...options}
      >
        {children}
      </BottomSheetModal>
    </BlurView>
  );
};


<BottomSheetTextInput
          placeholderTextColor={COLORS.grey600}
          {...options}
          onBlur={onBlurHandler}
          onFocus={onFocusHandler}
          style={{
            ...FONTS.bodyS,
            flex: 1,
          }}
          value={value}
          onChangeText={onChangeText}
        />

THERE ARE IMAGES:
Screenshot_1714190703
Screenshot_1714190722

@salahbm salahbm added the bug Something isn't working label Apr 27, 2024
@romainchkr
Copy link

Same problem here. Did you find a workaround ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants