摘要:最近在項(xiàng)目中要用到組件實(shí)現(xiàn)進(jìn)度條和畫圓環(huán)。最后,本人決定是否可以通過修改源碼實(shí)現(xiàn)旋轉(zhuǎn)效果,對(duì)組件的研究發(fā)現(xiàn)可以對(duì)組件加上一個(gè)屬性,實(shí)現(xiàn)圓環(huán)旋轉(zhuǎn)效果。最后附上本人在上的的評(píng)論,以及代碼定義旋轉(zhuǎn)角度初始化值初始化值
最近在項(xiàng)目中要用到[react-native-percentage-circle][1]組件實(shí)現(xiàn)進(jìn)度條和畫圓環(huán)。UI界面要實(shí)現(xiàn)如下效果
可以看出要實(shí)現(xiàn)兩個(gè)圓環(huán)嵌套,實(shí)現(xiàn)同心圓還是比較簡(jiǎn)單的,react-native-percentage-circle組件支持子元素,所以,在外面圓環(huán)里面嵌套一個(gè)同心圓環(huán),然后設(shè)置樣式就行了。具體代碼如下:
1990筆
然而要實(shí)現(xiàn)里面圓環(huán)旋轉(zhuǎn)就有點(diǎn)難度了,首先目前該組件最新版本v1.0.6并不支持直接旋轉(zhuǎn)
因此,首先我們想到可能要用的transform來實(shí)現(xiàn),但實(shí)踐發(fā)現(xiàn)有各種問題。最后,本人決定是否可以通過修改源碼實(shí)現(xiàn)旋轉(zhuǎn)效果,對(duì)組件的index.js研究發(fā)現(xiàn)可以對(duì)組件加上一個(gè)props屬性rotate,實(shí)現(xiàn)圓環(huán)旋轉(zhuǎn)效果。
第一步:在PercentageCircle類propTypes中添加一個(gè)rotate屬性。
第二步:在constructor中定義一個(gè)新的變量rotate。
第三步:對(duì)if進(jìn)行修改,要同時(shí)修改constructor函數(shù)和componentWillReceiveProps()函數(shù)
NOTE:這里rotate本人未設(shè)定值范圍,但建議0-50,如果大于50,失去了意義,可以通過背景顏色改變,大家在代碼中可以自己設(shè)定rotate的取值范圍。
最后附上本人在git上的Issues的評(píng)論,以及index.js代碼
/** React Native Percentage Circle ** @github https://github.com/JackPu/react-native-percentage-circle ** React Native Version >=0.25 ** to fixed react native version **/ import React, { Component } from "react"; import { StyleSheet, View, Text, } from "react-native"; const styles = StyleSheet.create({ circle: { overflow: "hidden", position: "relative", justifyContent: "center", alignItems: "center", backgroundColor: "#e3e3e3", }, leftWrap: { overflow: "hidden", position: "absolute", top: 0, }, rightWrap: { position: "absolute", }, loader: { position: "absolute", left: 0, top: 0, borderRadius: 1000, }, innerCircle: { overflow: "hidden", position: "relative", justifyContent: "center", alignItems: "center", }, text: { fontSize: 11, color: "#888", }, }); class PercentageCircle extends Component { propTypes: { color: React.PropTypes.string, bgcolor: React.PropTypes.string, innerColor: React.PropTypes.string, radius: React.PropTypes.number, percent: React.PropTypes.number, borderWidth: React.Proptypes.number, textStyle: React.Proptypes.array, disabled: React.PropTypes.bool, rotate: React.Proptypes.number, //定義旋轉(zhuǎn)角度 } constructor(props) { super(props); let percent = this.props.percent; let leftTransformerDegree = "0deg"; let rightTransformerDegree = "0deg"; //初始化值 let rotate = this.props.rotate; if (typeof rotate == "undefined") { rotate = 0; } if (percent >= 50) { //rightTransformerDegree = "180deg"; //leftTransformerDegree = (percent - 50) * 3.6 + "deg"; rightTransformerDegree = 180 + rotate * 3.6 + "deg"; leftTransformerDegree = (percent + rotate - 50) * 3.6 + "deg"; } else { //rightTransformerDegree = percent * 3.6 + "deg"; rightTransformerDegree = (percent + rotate - 50) * 3.6 + "deg"; leftTransformerDegree = rotate * 3.6 + "deg"; } this.state = { percent: this.props.percent, borderWidth: this.props.borderWidth < 2 || !this.props.borderWidth ? 2 : this.props.borderWidth, leftTransformerDegree: leftTransformerDegree, rightTransformerDegree: rightTransformerDegree, textStyle: this.props.textStyle ? this.props.textStyle : null }; } componentWillReceiveProps(nextProps) { let percent = nextProps.percent; let leftTransformerDegree = "0deg"; let rightTransformerDegree = "0deg"; /* if (percent >= 50) { rightTransformerDegree = "180deg"; leftTransformerDegree = (percent - 50) * 3.6 + "deg"; } else { rightTransformerDegree = "0deg"; leftTransformerDegree = -(50 - percent) * 3.6 + "deg"; } */ //初始化值 let rotate = this.props.rotate; if (typeof rotate == "undefined") { rotate = 0; } if (percent >= 50) { //rightTransformerDegree = "180deg"; //leftTransformerDegree = (percent - 50) * 3.6 + "deg"; rightTransformerDegree = 180 + rotate * 3.6 + "deg"; leftTransformerDegree = (percent + rotate - 50) * 3.6 + "deg"; } else { //rightTransformerDegree = percent * 3.6 + "deg"; rightTransformerDegree = (percent + rotate - 50) * 3.6 + "deg"; leftTransformerDegree = rotate * 3.6 + "deg"; } this.setState({ percent: this.props.percent, borderWidth: this.props.borderWidth < 2 || !this.props.borderWidth ? 2 : this.props.borderWidth, leftTransformerDegree: leftTransformerDegree, rightTransformerDegree: rightTransformerDegree }); } render() { if (this.props.disabled) { return (); } return ( {this.props.disabledText} ); } } // set some attributes default value PercentageCircle.defaultProps = { bgcolor: "#e3e3e3", innerColor: "#fff" }; module.exports = PercentageCircle; {this.props.children ? this.props.children : {this.props.percent}% }
s://github.com/JackPu/react-native-percentage-circle
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/92226.html
摘要:最近在項(xiàng)目中要用到組件實(shí)現(xiàn)進(jìn)度條和畫圓環(huán)。最后,本人決定是否可以通過修改源碼實(shí)現(xiàn)旋轉(zhuǎn)效果,對(duì)組件的研究發(fā)現(xiàn)可以對(duì)組件加上一個(gè)屬性,實(shí)現(xiàn)圓環(huán)旋轉(zhuǎn)效果。最后附上本人在上的的評(píng)論,以及代碼定義旋轉(zhuǎn)角度初始化值初始化值 最近在項(xiàng)目中要用到[react-native-percentage-circle][1]組件實(shí)現(xiàn)進(jìn)度條和畫圓環(huán)。UI界面要實(shí)現(xiàn)如下效果 showImg(https://segm...
摘要:前言前些天看了阿麗塔感嘆酷炫特效的同時(shí),不得不說這個(gè)片子灰常之熱血重新點(diǎn)燃了我糞斗的基情有那么幾個(gè)瞬間仿佛自己回到了,下面進(jìn)入正題在依德醫(yī)生剛撿回阿麗塔的那一段,有木有發(fā)現(xiàn)醫(yī)生家的設(shè)備都很有意思比如那個(gè)人皮縫紉機(jī),其靈活程度堪比織網(wǎng)的蜘蛛說 前言 前些天看了《阿麗塔》感嘆酷炫特效的同時(shí),不得不說這個(gè)片子灰常之熱血!重新點(diǎn)燃了我糞斗的基情!!有那么幾個(gè)瞬間仿佛自己回到了…… showIm...
摘要:前言前些天看了阿麗塔感嘆酷炫特效的同時(shí),不得不說這個(gè)片子灰常之熱血重新點(diǎn)燃了我糞斗的基情有那么幾個(gè)瞬間仿佛自己回到了,下面進(jìn)入正題在依德醫(yī)生剛撿回阿麗塔的那一段,有木有發(fā)現(xiàn)醫(yī)生家的設(shè)備都很有意思比如那個(gè)人皮縫紉機(jī),其靈活程度堪比織網(wǎng)的蜘蛛說 前言 前些天看了《阿麗塔》感嘆酷炫特效的同時(shí),不得不說這個(gè)片子灰常之熱血!重新點(diǎn)燃了我糞斗的基情!!有那么幾個(gè)瞬間仿佛自己回到了…… showIm...
摘要:前端常規(guī)制作進(jìn)度條方法前端實(shí)現(xiàn)相對(duì)容易點(diǎn),我們可以用去繪制圓,也可以用去繪制使用主要是用進(jìn)行繪制,關(guān)于使用可以看這里。 showImg(https://segmentfault.com/img/bVCkNJ); 先放運(yùn)行截圖說明做什么吧, showImg(https://segmentfault.com/img/bVCkND); react-native-percentage-circ...
摘要:效果圖怎么實(shí)現(xiàn)這樣一個(gè)圓環(huán)進(jìn)度條的效果呢,可以使用等等方式,今天我們來說下使用怎么來實(shí)現(xiàn)。使用才實(shí)現(xiàn)圓環(huán)進(jìn)度還是很簡(jiǎn)單的,還不需要考慮兼容性,關(guān)于可以看張?chǎng)涡翊笊竦娜罩? 效果圖 showImg(https://segmentfault.com/img/bV3DbY?w=315&h=300); 怎么實(shí)現(xiàn)這樣一個(gè)圓環(huán)進(jìn)度條的效果呢,可以使用canvas、svg、GIF等等方式,今天我們來說...
閱讀 3224·2023-04-25 18:43
閱讀 905·2021-11-24 09:39
閱讀 1372·2021-10-14 09:43
閱讀 3905·2021-09-22 15:58
閱讀 1931·2019-08-29 17:18
閱讀 426·2019-08-29 14:14
閱讀 3087·2019-08-29 13:01
閱讀 1628·2019-08-29 12:33