Last active
July 8, 2018 19:00
-
-
Save bogoslavskiy/569858496005358e08d51045703a081e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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