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

RNAlert.alert causes KASV to scroll to top #482

Open jagert opened 3 years ago

jagert commented 3 years ago

I'm using KASV like this:

<View style={{flex: 1}}>
  <KeyboardAwareScrollView
    alwaysBounceVertical={false}
    showsVerticalScrollIndicator={false}
    style={{flex: 1}}
    keyboardShouldPersistTaps="handled"
    extraHeight={100}
  >
    <View style={{height: 1000}} />
    <TouchableOpacity onPress={() => Alert.alert('Hello', 'world!')}>
      <View>
        <Text>Press me</Text>
      </View>
    </TouchableOpacity>
    <TextInput placeholder={'Give me text'} />
  </KeyboardAwareScrollView>
</View>

and encountered strange behavior. Steps to reproduce:

Expected behavior:

Diving into code shows that 'keyboardWillHide' fired twice on calling Alert.alert. That causes defaultResetScrollToCoords to be nulled after first 'keyboardWillHide' and the second 'keyboardWillHide' causes scrollToPosition(0, 0, true).

So, guys, there is a way to handle this case? Looks like that it's a bug of Alert, because opening RNModal fires 'keyboardWillHide' only once, but googling gives no answer..