Skip to content

Instantly share code, notes, and snippets.

@loganpowell
Created January 17, 2018 14:02
Show Gist options
  • Save loganpowell/5d706c4275d85d46f1f2b345cd10e15d to your computer and use it in GitHub Desktop.
Save loganpowell/5d706c4275d85d46f1f2b345cd10e15d to your computer and use it in GitHub Desktop.
Use Recompose with Animated
// from: https://github.com/acdlite/recompose/issues/427#issuecomment-320080852
compose(
withState(
'interaction',
'setInteraction',
// Props get passed in here, but we're ignoring them.
() => {
const interaction = {
scrollPositionY: new Animated.Value(0),
};
interaction.scrollEventY = Animated.event(
[{ nativeEvent: { contentOffset: { y: interaction.scrollPositionY } } }],
{ useNativeDriver: true },
);
return interaction;
},
)
)((props) => (
<Animated.ScrollView
onScroll={props.interaction.scrollEventY}
scrollEventThrottle={1}
>
<View>
{console.log(props.interaction.scrollPositionY)}
</View>
</Animated.ScrollView>
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment