react-native-keyboard-aware-scroll-view: scrollToPosition does not work on Android

scrollToPosition works fine on iOS but does not work on Android. I’ve set windowSoftInputMode to adjustPan Any idea how to make it work on android?

let scroll;
const scrollPosition = 200;
const SignupForm = (props: Props) => (
  <KeyboardAwareScrollView
    contentContainerStyle={styles.container}
    keyboardShouldPersistTaps="always"
    enableOnAndroid
    enableAutomaticScroll={false}
    innerRef={(ref) => { scroll = ref; }}
  >
    <View style={styles.row}>
      <TextField
        title={props.intl.formatMessage({ id: 'SignupForm.field.email' })}
        value={props.signupForm.email}
        onFocus={() => scroll.props.scrollToPosition(0, scrollPosition)}
      />
    </View>
    {/* ....More TextFields here.... */}
    <View style={styles.row}>
      <TextField
        title={props.intl.formatMessage({ id: 'SignupForm.field.password' })}
        value={props.signupForm.password}
        onFocus={() => scroll.props.scrollToPosition(0, scrollPosition)}
      />
    </View>
    <View style={styles.row}>
      <Button
        onPress={props.onSubmitForm}
        label={props.intl.formatMessage({ id: 'SignupForm.createAccount' })}
      />
    </View>
  </KeyboardAwareScrollView>
);

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19

Most upvoted comments

v"^0.7.2", scrollTo({x: X, y: Y}) does not working for android

it does not work for me either! using react-native 0.59.8 and react-native-keyboard-aware-scroll-view 0.8.0

change MainActivity android:windowSoftInputMode="adjustResize" to android:windowSoftInputMode="adjustPan" solve my problem

I fixed that by changing the following function in KeyboardAwareHOC.js:

scrollToPosition = (x: number, y: number, animated: boolean = true) => {
      const responder = this.getScrollResponder()
       responder && responder.scrollResponderScrollTo({ x, y, animated })
}

to

scrollToPosition = (x: number, y: number, animated: boolean = true) => {
     const responder = this.getScrollResponder()
     responder && responder.scrollTo({ x, y, animated })
}

scrollResponderScrollTo is deprecated now.

@Moreno97 It will give me this error

undefined is not a function (evaluating 'scroll.scrollToPosition(0, scrollPosition)')