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

Created on 15 Aug 2018  路  18Comments  路  Source: APSL/react-native-keyboard-aware-scroll-view

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>
);
android

Most helpful comment

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

All 18 comments

Do you resolve this problem?I have this problem too.

@dreamHeroK Still having this issue.
Currently using different approach using keyboardAvoidingView with keyboardVerticalOffset

Ok guys, you should use this in order to scroll to a certain position, here is working as expected:

this._scroll.scrollToPosition(0, scrollPosition)

It seems that documentation part is deprecated, we will update it as soon as possible.

@Moreno97 That should be equivalent with the code that I'm using I suppose, scroll.props.scrollToPosition(0, scrollPosition) there's no this because it's a pure function.

@rizkyario Can you try the follows?
scroll.scrollToPosition(0, scrollPosition)
Without the props.

@Moreno97 It will give me this error

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

@rizkyario which version are you using?

@Moreno97 "react-native-keyboard-aware-scroll-view": "^0.6.0",

The last version is 0.7.2, you should update to the latest, because maybe the API has changed along the versions.

@Moreno97 Still having the same problem.
@dreamHeroK Did you try to do @Moreno97's suggestions?

@rizkyario does not scroll with the last version? We can't reproduce the issue, since it works as expected (we have a React class instead of a pure function, but this should not affect). As I said before, calling scroll.scrollToPosition() works without problems.

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

@tmwd few minutes ago I also facing same issue. I solved it by using scrollToPosition method provided by this library.
Don't forget to set enableOnAndroid props to true and use innerRef method to get valid ref.

Please try @anjar10 solution, forget to mention that you should use innerRef and also scrollToPosition as before.

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

Thanks @dreamHeroK
For more detail check below:

screenshot at jan 04 18-55-02

scrollToPosition doesn't work on android. I've applied android:windowSoftInputMode="adjustPan" and enableOnAndroid props to true

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

Was this page helpful?
0 / 5 - 0 ratings