Need a little help with some JS. Is it possible to bind an animated event as needed below?
I need to do this:
onScroll={
Animated.event([
{
nativeEvent: {
contentOffset: {y: this.state.animTop}
}
}
])
}
I also need to do this
onScroll={(e) => {
let positionY = e.nativeEvent.contentOffset.y;
this._handleScroll(positionY);
this.setState({y: positionY})
}}
I have tried binding both like this, but it not take doing the Animated.event
componentDidMount() {
this._handleScroll = this._handleScroll.bind(this);
}
onScroll={
this._handleScroll
}
_handleScroll(e) {
Animated.event([
{
nativeEvent: {
contentOffset: {y: this.state.animTop}
}
}
]);
if(e > 30) {
this.setState({statusBarHidden: true});
} else {
this.setState({statusBarHidden: false});
}
}
Animated.event
has the capability touseNativeDriver
, whereas.setValue
uses the JS thread for animations. – Dithionite