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

Methods missing from innerRef #461

Open FraserHamilton opened 3 years ago

FraserHamilton commented 3 years ago

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()

peternoordijk commented 3 years ago

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

caogenyin commented 3 years ago

I have the same issue

knycornelius commented 3 years ago

I have the same issue when using scrollToIndex in KeyboardAwareFlatList.

tonycoco commented 3 years ago

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