Skip to content

[v4] animatedKeyboardHeightInContainer is 0 when Keyboard is open #1119

Open
@dNadiia

Description

@dNadiia

Bug

In some random cases, BottomSheetModal doesn't open correctly when it contains a text field. In such buggy cases animatedKeyboardHeightInContainer.value is rewriting to 0 after a keyboard was opened, because of true for !isAnimatedOnMount.value condition in src/components/bottomSheet/BottomSheet.tsx:

image

Note: bug is reproduced for any value of keyboardBehavior

Logs

LOG  =========WITHOUT BUG===========
LOG  
LOG  _keyboardState 0
LOG  _keyboardHeight 0
LOG  animatedKeyboardHeightInContainer 0
LOG  
LOG  !isAnimatedOnMount true
LOG  set animatedKeyboardHeightInContainer to zero 0
LOG  

LOG  _keyboardState 1
LOG  _keyboardHeight 291
LOG  animatedKeyboardHeightInContainer 291
LOG  

LOG  _keyboardState 2
LOG  _keyboardHeight 291
LOG  animatedKeyboardHeightInContainer 291
LOG  
LOG  !isAnimatedOnMount false
LOG  set animatedKeyboardHeightInContainer to zero 0
LOG  



LOG  =========WITH BUG===========
LOG  
LOG  _keyboardState 0
LOG  _keyboardHeight 0
LOG  animatedKeyboardHeightInContainer 0
LOG  
LOG  !isAnimatedOnMount true
LOG  set animatedKeyboardHeightInContainer to zero 0
LOG  

LOG  _keyboardState 1
LOG  _keyboardHeight 291
LOG  animatedKeyboardHeightInContainer 291
LOG  
LOG  !isAnimatedOnMount true
LOG  set animatedKeyboardHeightInContainer to zero 0 
LOG  

LOG  _keyboardState 2
LOG  _keyboardHeight 291
LOG  animatedKeyboardHeightInContainer 291
LOG  
LOG  !isAnimatedOnMount false
LOG  set animatedKeyboardHeightInContainer to zero 0

Video

bottomsheet_bug.mp4

Environment info

Library Version
@gorhom/bottom-sheet 4.4.5
react-native 0.68.2
react-native-reanimated 2.10.0
react-native-gesture-handler 2.6.2

Steps To Reproduce

  1. Open BottomSheetModal which contains a text field by tapping on Present Modal button.
  2. If the bug doesn’t reproduce, close BottomSheetModal by clicking on done keyboard button and repeat point 1.
  3. If you didn't catch the bug after 10-15 consecutive attempts, try to reload the app and start one more time from point 1.

Describe what you expected to happen:

The BottomSheetModal with a text field inside is opened according to the keyboardBehavior parameter every time the present method of the modal is called.

Reproducible sample code

import React, { useCallback, useMemo, useRef } from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';
import { BottomSheetModal, BottomSheetTextInput } from '@gorhom/bottom-sheet';

const App = () => {
  // ref
  const bottomSheetModalRef = useRef(null);

  // variables
  const snapPoints = useMemo(() => ['50%', '90%'], []);

  // callbacks
  const openModal = useCallback(() => {
    bottomSheetModalRef.current?.present();
  }, []);

  const dismissModal = useCallback(() => {
    bottomSheetModalRef.current?.dismiss();
  }, []);

  // renders
  return (
    <View style={styles.container}>
      <Button onPress={openModal} title="Present Modal" color="black" />
      <BottomSheetModal
        ref={bottomSheetModalRef}
        snapPoints={snapPoints}
        enablePanDownToClose={true}
        keyboardBehavior={'extend'}
        android_keyboardInputMode={'adjustResize'}
      >
        <View style={styles.contentContainer}>
          <BottomSheetTextInput
            autoFocus={true}
            returnKeyType={'done'}
            style={styles.input}
            onSubmitEditing={dismissModal}
          />
          <Text>{'Item 1'}</Text>
          <Text>{'Item 2'}</Text>
          <Text>{'Item 3'}</Text>
        </View>
      </BottomSheetModal>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
    justifyContent: 'center',
    backgroundColor: 'yellow',
  },
  contentContainer: {
    flex: 1,
    padding: 20,
  },
  input: {
    marginTop: 8,
    marginBottom: 10,
    borderRadius: 10,
    fontSize: 16,
    lineHeight: 20,
    height: 50,
    padding: 8,
    backgroundColor: 'pink',
  },
});

export default App;

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingv5

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions