反应本机绑定动画事件

Mal*_*ing 6 javascript ecmascript-6 reactjs react-native ecmascript-next

需要一些JS的帮助.是否可以根据需要绑定动画事件?

我需要这样做:

onScroll={
    Animated.event([
        {
            nativeEvent: {
                contentOffset: {y: this.state.animTop}
            }
        }
    ])
}    
Run Code Online (Sandbox Code Playgroud)

我也需要这样做

onScroll={(e) => {
    let positionY =  e.nativeEvent.contentOffset.y;
    this._handleScroll(positionY);
    this.setState({y: positionY})

}}
Run Code Online (Sandbox Code Playgroud)

我试过像这样绑定,但它不需要做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});
    }
}
Run Code Online (Sandbox Code Playgroud)

Mal*_*ing 11

终于搞定了:

将函数绑定到Animated.event侦听器:

onScroll={Animated.event(
                    [{ nativeEvent: { contentOffset: { y: this.state.animTop } } }],
                    { listener: this._handleScroll },
                )}
Run Code Online (Sandbox Code Playgroud)