monterosalondon / react-native-parallax-scroll

Parallax scroll view for react-native
MIT License
554 stars 62 forks source link

Fix forwarding `ref` #45

Open acro5piano opened 4 years ago

acro5piano commented 4 years ago

Problem

Couldn't use innerRef object at least RN 60. For example, ref.current.scrollTo({ y: 1000 }) does not work.

const App = () => {
  const ref = React.useRef()
  const scroll = React.useCallback(() => {
    ref.current && ref.current.getNode().scrollTo({ y: 10000 })
  }, [ref.current])

  return (
    <>
      <Button onPress={scroll} title="let's scroll" />
      <ParallaxScroll ref={ref}><View style={{ height: 1500 }} /></ParallaxScroll>
    </>
  )
}

causes an error ref.current.getNode is not a function

Changes

I didn't understand ref._component, but it should accept ref itself. so I've added forwarding ref if ref._component is not set.

Related Issues