react native - How do you add refs to functional components using withHandlers in Recompose and call ScrollTo on a ScrollView? -
my specific goal use scrollto method of scrollview maintain functional component structure.
more requires getting ref current component isn't possible naked react native.
in dec 2016 recompose added allows handlers property of withhandlers factory function can't quite figure out how use correctly.
how add refs functional components using withhandlers in recompose , call scrollto on scrollview?
you can try this:
/* ... */ const myview = ({ onref, children }) => ( <view> <scrollview ref={onref} /* ... */> {children} </scrollview> </view> ) export default compose( withhandlers(() => { let myscroll = null; return { onref: () => (ref) => (myscroll = ref), scrollto: () => (value) => myscroll.scrollto(value) } }, lifecycle({ componentdidmount() { this.props.scrollto({ x: 0, y: 100, animated: true }) } }) )(myview)
Comments
Post a Comment