Skip to content

Instantly share code, notes, and snippets.

@bogoslavskiy
Last active July 8, 2018 19:00
Show Gist options
  • Save bogoslavskiy/569858496005358e08d51045703a081e to your computer and use it in GitHub Desktop.
Save bogoslavskiy/569858496005358e08d51045703a081e to your computer and use it in GitHub Desktop.
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
class FlatListHelper extends React.PureComponent {
componentDidMount() {
let { tabRoute, animation, addHandlerScroll } = this.props;
addHandlerScroll(tabRoute, this.scrollToOffset);
setTimeout(() => { // Fix bug initialScroll set
this.scrollToOffset(animation.initialScroll, false)
}, 250);
}
scrollToOffset = (offset, animated = true) => {
this.flatList.getNode().scrollToOffset({offset, animated});
};
_onScrollEndDrag = e => {
[...]
};
render() {
let { scrollY, fullHeight } = this.props.animation;
let { contentContainerStyle } = this.props;
return (
<AnimatedFlatList
{...this.props}
scrollEventThrottle={1}
onScrollEndDrag={this._onScrollEndDrag}
contentContainerStyle={[
{paddingTop: fullHeight + ifIphoneX(15, 0)},
contentContainerStyle
]}
ref={component => {
this.flatList = component;
}}
onScroll={Animated.event(
[{ nativeEvent: { contentOffset: { y: scrollY } } }],
{ useNativeDriver: true }
)}
/>
);
}
}
// HOC
const withSearchBarContext = Comp => props => (
<SearchBarContext.Consumer>
{(context) =>
<Comp
{...context}
{...props}
/>
}
</SearchBarContext.Consumer>
);
export default withSearchBarContext(FlatListHelper);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment