React-native-keyboard-aware-scroll-view: Methods missing from innerRef

Created on 18 Oct 2020  路  4Comments  路  Source: APSL/react-native-keyboard-aware-scroll-view

The approach used in the documentation returns a reference in which this.scroll.props results in undefined meaning that we cannot use the scrollToPosition, scrollIntoView or, getScrollResponder methods.

scrollToEnd however can in fact be accessed directly from the reference i.e this.scroll.scrollToEnd()

Most helpful comment

I found a little workaround. So instead of this:

const myRef = useRef(null);

useEffect(() => {
  myRef.current.props.scrollToPosition(x, y, true);
}, [x, y])

return (
  <KeyboardAwareScrollView innerRef={myRef} />
);

You can use

const myRef = useRef(null);

useEffect(() => {
  myRef.current.scrollToPosition(x, y, true);
}, [x, y])

return (
  <KeyboardAwareScrollView ref={myRef} />
);

However it's not documented so I have no clue what's going to be supported in the future

All 4 comments

I found a little workaround. So instead of this:

const myRef = useRef(null);

useEffect(() => {
  myRef.current.props.scrollToPosition(x, y, true);
}, [x, y])

return (
  <KeyboardAwareScrollView innerRef={myRef} />
);

You can use

const myRef = useRef(null);

useEffect(() => {
  myRef.current.scrollToPosition(x, y, true);
}, [x, y])

return (
  <KeyboardAwareScrollView ref={myRef} />
);

However it's not documented so I have no clue what's going to be supported in the future

I have the same issue

I have the same issue when using scrollToIndex in KeyboardAwareFlatList.

Biggest problem is TypeScript yells about: Property 'scrollIntoView' does not exist on type 'KeyboardAwareScrollView'.

Was this page helpful?
0 / 5 - 0 ratings