简体   繁体   English

React Native:重置动画值?

[英]React Native: reset animated value?

In my react native app I made a very simple animated progressbar, problem is I don't know how to reset the animation.在我的 react native 应用程序中,我制作了一个非常简单的动画进度条,问题是我不知道如何重置 animation。

I tried doing the bellow but it didn't work我试着做下面的,但它没有用

progressValue = 0;

How can I reset animation?如何重置 animation? also why if I do something like const animation = null it says variable its read only (see commented line on my example).还有为什么如果我做类似 const animation = null 之类的事情,它说变量是只读的(参见我的示例中的注释行)。

This is whatI have (works except no way to reset animation):这就是我所拥有的(除了无法重置动画之外的作品):

const width = Math.round(Dimensions.get('window').width)-30;

    const progressValue = new Animated.Value(0);
    //const animation = null;

    const onStart = (duration ) => 
    {
        const animation = Animated.timing(progressValue, {
            duration: duration,
            toValue: width,
            easing: Easing.linear,
            useNativeDriver: true,
        }).start();

        
    };

    const onReset = () => 
    {
        //WHAT DO?
    };

Thanks in advance提前致谢

If by reseting to you mean to reset the progress bar, then you can just call如果通过重置你的意思是重置进度条,那么你可以打电话

progressValue.setValue(0);

If you want to restart it, then just just call onStart after the upper line.如果要重新启动它,只需在上线之后调用onStart即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM