kirillzyusko / react-native-keyboard-controller

Keyboard manager which works in identical way on both iOS and Android
https://kirillzyusko.github.io/react-native-keyboard-controller/
MIT License
1.4k stars 55 forks source link

The KeyboardToolbar misbehaves on iPhones when wrapped by SafeAreaView #415

Closed Kreshnik closed 2 months ago

Kreshnik commented 3 months ago

Describe the bug There are two issues: the KeyboardToolbar is visible at the bottom of the view when the keyboard is closed, which I assume is caused by the SafeAreaView. Additionally, when the keyboard opens, the KeyboardToolbar is not completely docked to the keyboard but has an empty space in between.

Code snippet

  return (
    <SafeAreaView>
      <FlatList
          renderItem={({ item }) => {
            return (
              <Box w="100%">
                <item.component {...item.props} />
              </Box>
          )}}
          renderScrollComponent={(props) => (
            <KeyboardAwareScrollView {...props} style={{flex: 1}} />
          )}
        />
      <KeyboardToolbar doneText="Done" />
    </SafeAreaView>
  );

Repo for reproducing N/A

To Reproduce N/A

Expected behavior The KeyboardToolbar should not be visible when the keyboard is closed, and there should be no space between the KeyboardToolbar and the Keyboard.

Screenshots

Screenshot 2024-04-18 at 23 35 28 Screenshot 2024-04-18 at 23 36 29

Smartphone (please complete the following information):

kirillzyusko commented 2 months ago

@Kreshnik hello 👋

Can you try to render KeyboardToolbar outside of SafeAreaView? Something like this:

return (
  <>
    <SafeAreaView>
      <FlatList
          renderItem={({ item }) => {
            return (
              <Box w="100%">
                <item.component {...item.props} />
              </Box>
          )}}
          renderScrollComponent={(props) => (
            <KeyboardAwareScrollView {...props} style={{flex: 1}} />
          )}
        />
    </SafeAreaView>
    <KeyboardToolbar doneText="Done" />
  </>
);
kirillzyusko commented 2 months ago

I'm going to close the issue.

KeyboardToolbar uses relative positioning, so it always must be in the end of the screen. If you can not put it in the end of the screen, then you can apply additional styles and wrap it within a view:

  return (
    <SafeAreaView>
      <FlatList
          renderItem={({ item }) => {
            return (
              <Box w="100%">
                <item.component {...item.props} />
              </Box>
          )}}
          renderScrollComponent={(props) => (
            <KeyboardAwareScrollView {...props} style={{flex: 1}} />
          )}
        />
      <View style={{paddingTop: 30 /* or any other value, like bottom tab bar height */}}>
        <KeyboardToolbar doneText="Done" />
      </View>
    </SafeAreaView>
  );