【问题标题】:How to make progress bar with minute interval?如何以分钟间隔制作进度条?
【发布时间】:2021-09-16 07:22:54
【问题描述】:

库使用 react-native 进度 用于制作进度条

import * as Progress from 'react-native-progress';  

<Progress.Bar progress={0.3} width={200} />

【问题讨论】:

    标签: react-native react-native-android progress-bar setinterval react-native-ios


    【解决方案1】:

    使用这个库 react-native 进度 初始值设置为 0

     const [progressBarValue, setProgressBarValue] = useState(0) 
    
     useEffect(() => {
         const intervalId = setInterval(() => {
          setProgressBarValue((prev) => {
            if (prev >= 1.2) {
              setCongratulations('Congratulations')
              clearInterval(intervalId);
              return 1.120;
            } else {
              return prev + 0.01;
            }
          });
        }, 1000);
        return () => clearInterval(intervalId);
      }, []);
    

    渲染代码

      <Progress.Bar progress={progressBarValue} width={width-50} color={'rgba(221,196,145, 1)'}/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 2020-12-05
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多