首页 > 其他分享 >react-native 实现环形(圆形)进度条

react-native 实现环形(圆形)进度条

时间:2022-09-23 09:56:07浏览次数:62  
标签:进度条 transform height react width let 112 100 native

废话不多说,直接上硬货:
效果图

 

 

 

安装 react-native-anchor-point 用于处理旋转中心点位置

yarn add react-native-anchor-point

github仓库地址: https://github.com/sueLan/react-native-anchor-point

圆形进度html结果样式

<View style={[styles.round]}>
                    <View style={[styles.leftCircle, styles.Circle]}>
                        <View style={[styles.leftHalfCircle, leftTransform()]}></View>
                    </View>
                    <View style={[styles.rightCircle, styles.Circle]}>
                        <Animated.View style={[styles.rightHalfCircle ,rightTransform()]}></Animated.View>
                    </View>
                    <View style={[styles.percentage]}>
                        <Text style={{color: '#121214',fontWeight:'600',fontSize:14}}>{schedule}%</Text>
                    </View>
                </View>
Circle:{
        width:'50%',
        height:112,
        position: 'absolute'
    },
    leftCircle:{
        left: 0,
        overflow: 'hidden'
    },
    rightCircle:{
        right: 0,
        overflow: 'hidden'
    },
    leftHalfCircle:{
        width: '100%',
        height: 112,
        borderTopLeftRadius: 100,
        borderBottomLeftRadius: 100,
        backgroundColor: 'rgb(65,69,255)'
    },
    rightHalfCircle:{
        width: '100%',
        height: 112,
        borderTopRightRadius: 100,
        borderBottomRightRadius: 100,
        backgroundColor: 'rgb(65,69,255)',
    },
    percentage:{
        width: 64,
        height:64,
        backgroundColor: '#fff',
        borderRadius:100,
        justifyContent:'center',
        alignItems:'center'
    },
    round:{
        marginTop: 16,
        width: 112, 
        height: 112,
        backgroundColor: '#F5F5FA',
        borderRadius: 100, 
        marginRight: 73,
        justifyContent:'center',
        alignItems: 'center'
    },


    let total = 100
    let [schedule, setschedule] = useState(22.5)
    let deg = Number((schedule/total)*360).toFixed(1)
    let [leftSchedule, setLeftSchedule] = useState(-180)
    let [rightSchedules, setRightSchedules] = useState(180)
    useEffect(()=>{
        if(deg > 180){
            setLeftSchedule(0)
            setRightSchedules(deg)
        }else{
            setLeftSchedule(180 - deg)
        }
    },[])


    const rightTransform = () => {
        let transform = {
            transform: [{ rotateZ:  -leftSchedule + 'deg' }],
        };
        return withAnchorPoint(transform, { x: 0, y: 0.5 }, { width: 56, height: 112 });
    };
    const leftTransform = () => {
        let transform = {
            transform: [{ rotateZ: rightSchedules + 'deg' }],
        };
        return withAnchorPoint(transform, { x: 1, y: 0.5 }, { width: 56, height: 112 });
    };

 



标签:进度条,transform,height,react,width,let,112,100,native
From: https://www.cnblogs.com/tlfe/p/16721657.html

相关文章

  • rxjs 在 react 下的应用
    设置一个subject,然后在组件内定义一个subscription想要发送事件就用subject.next订阅就赋值subject.asObservable().subscribe()直接看代码constsubject=ne......
  • 快速上手React编程 pdf
    高清扫描版下载链接:https://pan.baidu.com/s/1R4B-izNpESydo-yFNmU8xw点击这里获取提取码 ......
  • 教你如何实现react Scheduler(二)
    在上一篇文章中“反应调度程序(1)”中,我们使用MessageChannel来实现一个简单的任务调度功能。但是这个功能目前还是比较简单的,现在我们来改进一下,给任务增加优先级和过期......
  • 使用 PNPM 将 React App 中的磁盘空间减少 60%
    使用PNPM将ReactApp中的磁盘空间减少60%在React应用程序中使用PNPM减少磁盘空间的教程。Photoby诺德伍德主题on不飞溅您是否正在处理具有共同依赖项的......
  • React + Eartho 与 3 个简单的步骤集成
    React+Eartho与3个简单的步骤集成如果您已经关注并访问了您的第一个地球和React经验,那么我相信你会感觉很棒。它一次为开发人员提供了许多好处。如果你有地球......
  • React 组件和更好的方法
    React组件和更好的方法Credits-eduba.com想了解react.js如何帮助创建令人惊叹的用户界面?它是如何让我们如此轻松高效地执行多项任务的?在本文中,我将介绍其中一个Re......
  • vue3中watch监听ref reactive响应式数据写法及注意点
    watch函数与vue2中watch配置一致两个小坑监视reactive定义的响应式数据时,oldvalue无法正确获取,强制开启了深度监视(deep配置失败)监视reactive定义的响应式数据中某个......
  • 写给自己的react面试题总结
    解释React中render()的目的。每个React组件强制要求必须有一个render()。它返回一个React元素,是原生DOM组件的表示。如果需要渲染多个HTML元素,则必须将它们组......
  • React 面向组件编程 之 类式组件、组件实例的三大核心属性
    类式组件importReact,{Component}from"react";exportdefaultclassAppextendsComponent{render(){return<h2>我是类式组件</h2>}}......
  • JVM方法调用——native方法到java方法
    native方法到java方法最为经典的一个JNI调用Java方法就是调用Main函数,下面顺便会介绍java的启动过程。java的main函数在src/java.base/share/native/launcher/main.c,这个......