APSL / react-native-keyboard-aware-scroll-view

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput.
MIT License
5.24k stars 643 forks source link

Inverted sticky header (i.e. footer) not keyboard aware #437

Open msageryd opened 4 years ago

msageryd commented 4 years ago

I have sticky buttons at the bottom of my scrollview. When the keyboard shows these are stuck to the bottom of the screen, i.e. they are not moved up as the rest of the keyboard-aware-scroll-view.

The buttons are unreachable whenever the keyboard is shown. Any tips on solving this?

Code: There are two childs in the scrollView, one Form and one View with buttons. By inverting stickyHeaders and appointing child 1 (i.e. the second component) as sticky my buttons are sticky at the bottom. (Button is from react-native-paper)

      <SafeAreaView style={{flex: 1}}>
        <KeyboardAwareScrollView
          style={{flex: 1}}
          behavior={Platform.OS == 'ios' ? 'padding' : 'height'}
          enableResetScrollToCoords={false}
          keyboardOpeningTime={0}
          keyboardShouldPersistTaps="handled"
          keyboardDismissMode="interactive"
          stickyHeaderIndices={[1]}
          invertStickyHeaders={true}
        >
          <Form formDef={formDef} />
          <View style={{flex: 1}}>
            <View style={{flexDirection: 'row', justifyContent: 'space-around', flex: 1}}>
              <Button
                mode="contained"
                style={{marginHorizontal: 12, marginVertical: 20, flex: 1}}
                onPress={() => null}
              >
                Save
              </Button>
              <Button
                mode="contained"
                style={{marginHorizontal: 12, marginVertical: 20, flex: 1}}
                color="red"
                onPress={() => null}
              >
                Cancel
              </Button>
            </View>
          </View>
        </KeyboardAwareScrollView>
      </SafeAreaView>
marvinPlasmatic commented 3 years ago

Also on the same issue.

wolfag commented 3 years ago

You can try this trick.

<KeyboardAvoidingView style={{ flex: 1, backgroundColor: '#fff' }} behavior={Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={80}> ...your code here </KeyboardAvoidingView>

There is a small problem, your screen height will larger a bit if you look at the bottom of the screen (I tested on simulator iPhone6s, iPhone7, 8).