@ledvance/group-ui-biz-bundle 1.0.121 → 1.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/biorhythm/BiorhythmActions.ts +7 -2
- package/src/modules/biorhythm/BiorhythmPage.tsx +51 -16
- package/src/modules/biorhythm/circular/RhythmsCircle.tsx +488 -0
- package/src/modules/biorhythm/circular/conical-gradient/Android.tsx +63 -0
- package/src/modules/biorhythm/circular/conical-gradient/Ios.tsx +26 -0
- package/src/modules/biorhythm/circular/conical-gradient/Normal.tsx +187 -0
- package/src/modules/biorhythm/circular/conical-gradient/index.android.tsx +164 -0
- package/src/modules/biorhythm/circular/conical-gradient/index.ios.tsx +124 -0
- package/src/modules/biorhythm/circular/conical-gradient/index.tsx +3 -0
- package/src/modules/biorhythm/circular/conical-gradient/index.web.tsx +94 -0
- package/src/modules/biorhythm/circular/conical-gradient/interface.ts +19 -0
- package/src/modules/biorhythm/circular/conical-gradient/utils.ts +25 -0
- package/src/modules/biorhythm/circular/interface.ts +114 -0
- package/src/modules/energyConsumption/component/EnergyModal.tsx +3 -0
- package/src/modules/lightMode/LightModePage.tsx +50 -144
- package/src/modules/mood/DynamicMoodEditorPage.tsx +1 -1
- package/src/modules/mood/StaticMoodEditorPage.tsx +1 -1
- package/src/modules/mood_new/DynamicMoodEditorPage.tsx +1 -1
- package/src/modules/mood_new/MixDynamicMoodEditor.tsx +1 -1
- package/src/modules/mood_new/MoodInfo.ts +1 -1
- package/src/modules/mood_new/StaticMoodEditorPage.tsx +1 -1
- package/src/modules/powerOnBehavior/LightBehaviorPage.tsx +208 -0
- package/src/modules/powerOnBehavior/PlugBehaviorPage.tsx +99 -0
- package/src/modules/powerOnBehavior/PowerOnBehaviorActions.ts +131 -0
- package/src/modules/powerOnBehavior/Router.ts +27 -0
- package/src/navigation/Routers.ts +3 -1
- package/src/modules/biorhythm/circular/ItemIcon.d.ts +0 -22
- package/src/modules/biorhythm/circular/ItemIcon.tsx +0 -173
- package/src/modules/biorhythm/circular/Progress.d.ts +0 -24
- package/src/modules/biorhythm/circular/Progress.tsx +0 -372
- package/src/modules/biorhythm/circular/TimeCircular.d.ts +0 -11
- package/src/modules/biorhythm/circular/TimeCircular.tsx +0 -64
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import extractGradient from 'react-native-svg/lib/extract/extractGradient';
|
|
3
|
+
import createReactNativeComponentClass from 'react-native-svg/lib/createReactNativeComponentClass';
|
|
4
|
+
import { ClipPathAttributes } from 'react-native-svg/lib/attributes';
|
|
5
|
+
|
|
6
|
+
function arrayDiffer(a: number[], b: number[]) {
|
|
7
|
+
if (a == null || b == null) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
if (a.length !== b.length) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
for (let i = 0; i < a.length; i++) {
|
|
14
|
+
if (a[i] !== b[i]) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const GradientAttributes = {
|
|
22
|
+
gradient: {
|
|
23
|
+
diff: arrayDiffer,
|
|
24
|
+
},
|
|
25
|
+
gradientUnits: true,
|
|
26
|
+
gradientTransform: {
|
|
27
|
+
diff: arrayDiffer,
|
|
28
|
+
},
|
|
29
|
+
cx: true,
|
|
30
|
+
cy: true,
|
|
31
|
+
...ClipPathAttributes,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
interface Props {
|
|
35
|
+
cx?: number | string;
|
|
36
|
+
cy?: number | string;
|
|
37
|
+
gradientUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
|
|
38
|
+
id?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default class ConicalGradient extends PureComponent<Props> {
|
|
42
|
+
static defaultProps = {
|
|
43
|
+
cx: '50%',
|
|
44
|
+
cy: '50%',
|
|
45
|
+
gradientUnits: 'objectBoundingBox',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
render() {
|
|
49
|
+
const { cx, cy } = this.props;
|
|
50
|
+
return (
|
|
51
|
+
<RNSVGConicalGradient
|
|
52
|
+
cx={cx.toString()}
|
|
53
|
+
cy={cy.toString()}
|
|
54
|
+
{...extractGradient(this.props)}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const RNSVGConicalGradient = createReactNativeComponentClass('CustomRNSVGConicalGradient', () => ({
|
|
61
|
+
validAttributes: GradientAttributes,
|
|
62
|
+
uiViewClassName: 'RNSVGConicalGradient',
|
|
63
|
+
}));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
import { processColor, requireNativeComponent, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
fromDegree: number;
|
|
6
|
+
colors: number[];
|
|
7
|
+
stops: number[];
|
|
8
|
+
innerRadius: number;
|
|
9
|
+
style: StyleProp<ViewStyle>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const TYRCTConicGradientComp = requireNativeComponent('CustomTYRCTConicGradientView');
|
|
13
|
+
|
|
14
|
+
export default class ConicalGradent extends PureComponent<Props> {
|
|
15
|
+
static defaultProps = {
|
|
16
|
+
fromDegree: 0,
|
|
17
|
+
colors: [processColor('red'), processColor('green')],
|
|
18
|
+
stops: [0, 1],
|
|
19
|
+
innerRadius: 0,
|
|
20
|
+
style: null,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
render() {
|
|
24
|
+
return <TYRCTConicGradientComp {...this.props} />;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import Svg, { G, LinearGradient, Path, Defs, Stop } from 'react-native-svg';
|
|
4
|
+
import { interpolateHcl as interpolateGradient } from 'd3-interpolate';
|
|
5
|
+
import { Coordinate, ColorItem } from './interface';
|
|
6
|
+
|
|
7
|
+
const fullDeg = Math.PI * 2;
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
outerRadius: number;
|
|
11
|
+
innerRadius: number;
|
|
12
|
+
segmentAngle: number;
|
|
13
|
+
offsetAngle: number; // 偏移角度
|
|
14
|
+
colors: ColorItem[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class RingBackground extends React.Component<Props> {
|
|
18
|
+
static defaultProps = {
|
|
19
|
+
outerRadius: 120,
|
|
20
|
+
innerRadius: 80,
|
|
21
|
+
offsetAngle: 0,
|
|
22
|
+
colors: [],
|
|
23
|
+
segmentAngle: fullDeg / 360, // 每隔多少度切一个颜色
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
constructor(props: Props) {
|
|
27
|
+
super(props);
|
|
28
|
+
|
|
29
|
+
const { outerRadius, innerRadius, colors, segmentAngle, offsetAngle } = this.props;
|
|
30
|
+
this.handleSize(outerRadius, innerRadius, offsetAngle);
|
|
31
|
+
this.handleColors(colors, segmentAngle);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line react/no-deprecated
|
|
35
|
+
componentWillReceiveProps(nextProps: Props) {
|
|
36
|
+
if (!_.isEqual(nextProps, this.props)) {
|
|
37
|
+
this.setNativeProps(nextProps);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setNativeProps(props: Props) {
|
|
42
|
+
const {
|
|
43
|
+
outerRadius: oldOuterRadius,
|
|
44
|
+
innerRadius: oldInnerRadius,
|
|
45
|
+
colors: oldColors,
|
|
46
|
+
segmentAngle: oldSegmentAngle,
|
|
47
|
+
offsetAngle: oldOffsetAngle,
|
|
48
|
+
} = this.props;
|
|
49
|
+
|
|
50
|
+
const {
|
|
51
|
+
outerRadius = oldOuterRadius,
|
|
52
|
+
innerRadius = oldInnerRadius,
|
|
53
|
+
colors = oldColors,
|
|
54
|
+
segmentAngle = oldSegmentAngle,
|
|
55
|
+
offsetAngle = oldOffsetAngle,
|
|
56
|
+
} = props;
|
|
57
|
+
|
|
58
|
+
this.handleSize(outerRadius, innerRadius, offsetAngle);
|
|
59
|
+
this.handleColors(colors, segmentAngle);
|
|
60
|
+
|
|
61
|
+
this.forceUpdate();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getPoint(angle: number, radius: number) {
|
|
65
|
+
const { offsetAngle, outerRadius } = this;
|
|
66
|
+
// 精度过高,有些安卓手机会出现有角的现象,这里降低下精度
|
|
67
|
+
const deg = Math.round(10000 * (angle + offsetAngle)) / 10000;
|
|
68
|
+
return {
|
|
69
|
+
x: radius * Math.cos(deg) + outerRadius,
|
|
70
|
+
y: radius * Math.sin(deg) + outerRadius,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getPath(start: Coordinate, end: Coordinate) {
|
|
75
|
+
const { radius } = this;
|
|
76
|
+
const { x: x1, y: y1 } = start;
|
|
77
|
+
const { x: x2, y: y2 } = end;
|
|
78
|
+
return `M${x1} ${y1} A${radius} ${radius} 0 0 1 ${x2} ${y2}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private offsetAngle = 0;
|
|
82
|
+
|
|
83
|
+
private size = 0;
|
|
84
|
+
|
|
85
|
+
private radius = 0;
|
|
86
|
+
|
|
87
|
+
private innerRadius = 0;
|
|
88
|
+
|
|
89
|
+
private outerRadius = 0;
|
|
90
|
+
|
|
91
|
+
private colors: ColorItem[] = [];
|
|
92
|
+
|
|
93
|
+
handleColors(colors: ColorItem[], segmentAngle: number) {
|
|
94
|
+
let prev = colors[colors.length - 1];
|
|
95
|
+
// 按分隔的角度,插入数据
|
|
96
|
+
const list: ColorItem[] = [];
|
|
97
|
+
colors.forEach((item: ColorItem) => {
|
|
98
|
+
const { angle: start, color: startColor } = prev;
|
|
99
|
+
// eslint-disable-next-line
|
|
100
|
+
let { angle: end, color: endColor } = item;
|
|
101
|
+
if (end <= start) {
|
|
102
|
+
end += fullDeg;
|
|
103
|
+
}
|
|
104
|
+
const steps = Math.floor((end - start) / segmentAngle);
|
|
105
|
+
const interpolate = interpolateGradient(startColor, endColor);
|
|
106
|
+
const startDeg = Math.ceil(start / segmentAngle) * segmentAngle;
|
|
107
|
+
for (let i = 0; i < steps; i++) {
|
|
108
|
+
const deg = startDeg + segmentAngle * i;
|
|
109
|
+
const percent = (deg - start) / (end - start);
|
|
110
|
+
const stepColor = interpolate(percent);
|
|
111
|
+
list.push({
|
|
112
|
+
angle: deg > fullDeg ? deg % fullDeg : deg,
|
|
113
|
+
color: stepColor,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
prev = item;
|
|
117
|
+
list.push({
|
|
118
|
+
angle: item.angle,
|
|
119
|
+
color: interpolate(1),
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
prev = list[list.length - 1];
|
|
124
|
+
this.colors = list.map(current => {
|
|
125
|
+
// 计算渐变方向
|
|
126
|
+
const { angle: startAngle, color: startColor } = prev;
|
|
127
|
+
const { angle: endAngle, color: endColor } = current;
|
|
128
|
+
const point1 = this.getPoint(startAngle, this.radius);
|
|
129
|
+
// 加 0.005 使用每条线段有重叠,保证圆圆滑
|
|
130
|
+
const point2 = this.getPoint(endAngle + 0.005, this.radius);
|
|
131
|
+
prev = current;
|
|
132
|
+
return {
|
|
133
|
+
path: this.getPath(point1, point2),
|
|
134
|
+
from: point1,
|
|
135
|
+
to: point2,
|
|
136
|
+
startColor,
|
|
137
|
+
endColor,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
handleSize(outerRadius: number, innerRadius: number, offsetAngle: number) {
|
|
143
|
+
this.size = outerRadius * 2;
|
|
144
|
+
this.radius = (outerRadius + innerRadius) / 2;
|
|
145
|
+
this.outerRadius = outerRadius;
|
|
146
|
+
this.innerRadius = innerRadius;
|
|
147
|
+
this.offsetAngle = offsetAngle;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
render() {
|
|
151
|
+
const { size, outerRadius, innerRadius } = this;
|
|
152
|
+
return (
|
|
153
|
+
<Svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
|
|
154
|
+
<Defs>
|
|
155
|
+
{this.colors.map(({ from, to, startColor, endColor }, index) => (
|
|
156
|
+
<LinearGradient
|
|
157
|
+
// eslint-disable-next-line
|
|
158
|
+
key={index}
|
|
159
|
+
id={`linear${index}`}
|
|
160
|
+
x1={from.x.toFixed(2)}
|
|
161
|
+
y1={from.y.toFixed(2)}
|
|
162
|
+
x2={to.x.toFixed(2)}
|
|
163
|
+
y2={to.y.toFixed(2)}
|
|
164
|
+
>
|
|
165
|
+
<Stop offset="0" stopColor={startColor} />
|
|
166
|
+
<Stop offset="1" stopColor={endColor} />
|
|
167
|
+
</LinearGradient>
|
|
168
|
+
))}
|
|
169
|
+
</Defs>
|
|
170
|
+
<G>
|
|
171
|
+
{this.colors.map(({ path }: ColorItem, index) => {
|
|
172
|
+
return (
|
|
173
|
+
<Path
|
|
174
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
175
|
+
key={index}
|
|
176
|
+
d={path}
|
|
177
|
+
fill="transparent"
|
|
178
|
+
stroke={`url(#linear${index})`}
|
|
179
|
+
strokeWidth={`${outerRadius - innerRadius}`}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
})}
|
|
183
|
+
</G>
|
|
184
|
+
</Svg>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import { Svg, Circle, Defs, Stop, G } from 'react-native-svg';
|
|
5
|
+
import { interpolateHcl as interpolateGradient } from 'd3-interpolate';
|
|
6
|
+
import Normal from './Normal';
|
|
7
|
+
import AndroidConicalGradent from './Android';
|
|
8
|
+
import { isLargeAppRnVersion } from './utils';
|
|
9
|
+
import { StopItem } from './interface';
|
|
10
|
+
|
|
11
|
+
const fullDeg = Math.PI * 2;
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
/**
|
|
15
|
+
* 外圈半径
|
|
16
|
+
*/
|
|
17
|
+
outerRadius: number;
|
|
18
|
+
/**
|
|
19
|
+
* 内圈半径
|
|
20
|
+
*/
|
|
21
|
+
innerRadius: number;
|
|
22
|
+
/**
|
|
23
|
+
* 切分角度
|
|
24
|
+
*/
|
|
25
|
+
segmentAngle: number;
|
|
26
|
+
/**
|
|
27
|
+
* 偏移角度
|
|
28
|
+
*/
|
|
29
|
+
offsetAngle: number;
|
|
30
|
+
/**
|
|
31
|
+
* 渐变颜色配置
|
|
32
|
+
*/
|
|
33
|
+
colors: StopItem[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface State {
|
|
37
|
+
colors: StopItem[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default class ConicalGradent extends Component<Props, State> {
|
|
41
|
+
static defaultProps = {
|
|
42
|
+
outerRadius: 120,
|
|
43
|
+
innerRadius: 80,
|
|
44
|
+
offsetAngle: 0,
|
|
45
|
+
colors: [
|
|
46
|
+
{ angle: 0, color: 'red' },
|
|
47
|
+
{ angle: fullDeg, color: 'green' },
|
|
48
|
+
],
|
|
49
|
+
segmentAngle: fullDeg / 360, // 每隔多少度切一个颜色
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
constructor(props: Props) {
|
|
53
|
+
super(props);
|
|
54
|
+
this.state = {
|
|
55
|
+
colors: this.getColors(this.props.colors),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// eslint-disable-next-line react/no-deprecated
|
|
60
|
+
componentWillReceiveProps(nextProps: Props) {
|
|
61
|
+
if (!_.isEqual(nextProps.colors, this.props.colors)) {
|
|
62
|
+
this.setState({ colors: [...nextProps.colors] });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
shouldComponentUpdate(nextProps: Props, nextState: State) {
|
|
67
|
+
const { outerRadius, innerRadius, segmentAngle, offsetAngle, colors } = nextProps;
|
|
68
|
+
const {
|
|
69
|
+
outerRadius: oldOuterRadius,
|
|
70
|
+
innerRadius: oldinnerRadius,
|
|
71
|
+
segmentAngle: oldSegmentAngle,
|
|
72
|
+
offsetAngle: oldOffsetAngle,
|
|
73
|
+
colors: oldColors,
|
|
74
|
+
} = nextProps;
|
|
75
|
+
return (
|
|
76
|
+
!_.isEqual(outerRadius, oldOuterRadius) ||
|
|
77
|
+
!_.isEqual(innerRadius, oldinnerRadius) ||
|
|
78
|
+
!_.isEqual(segmentAngle, oldSegmentAngle) ||
|
|
79
|
+
!_.isEqual(offsetAngle, oldOffsetAngle) ||
|
|
80
|
+
!_.isEqual(colors, oldColors) ||
|
|
81
|
+
!_.isEqual(this.state.colors, nextState.colors)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getColors(colors: StopItem[]) {
|
|
86
|
+
return [...colors].sort((a: StopItem, b: StopItem) => {
|
|
87
|
+
return a.angle > b.angle ? 1 : -1;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setColors(colors: StopItem[]) {
|
|
92
|
+
this.setState({ colors: this.getColors(colors) });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
renderStops() {
|
|
96
|
+
const { offsetAngle } = this.props;
|
|
97
|
+
const { colors } = this.state;
|
|
98
|
+
// 转换角度
|
|
99
|
+
const list: StopItem[] = colors
|
|
100
|
+
.map(item => ({
|
|
101
|
+
angle: (item.angle + offsetAngle) % fullDeg,
|
|
102
|
+
color: item.color,
|
|
103
|
+
}))
|
|
104
|
+
.sort((item1, item2) => (item1.angle > item2.angle ? 1 : -1));
|
|
105
|
+
|
|
106
|
+
// 第一个是否为0
|
|
107
|
+
if (list[0].angle !== 0) {
|
|
108
|
+
// 加入 0 角度的颜色
|
|
109
|
+
// 上一个颜色
|
|
110
|
+
const { color: startColor, angle: startAngle } = list[list.length - 1];
|
|
111
|
+
const { color: endColor, angle: endAngle } = list[0];
|
|
112
|
+
// 补帧
|
|
113
|
+
const interpolate = interpolateGradient(startColor, endColor);
|
|
114
|
+
// 0 角度的位置百分比
|
|
115
|
+
const percent = (fullDeg - startAngle) / (endAngle + fullDeg - startAngle);
|
|
116
|
+
// 0 角度的颜色
|
|
117
|
+
const zeroColor = interpolate(percent);
|
|
118
|
+
list.splice(0, 0, { angle: 0, color: zeroColor });
|
|
119
|
+
}
|
|
120
|
+
// 最后是否有颜色
|
|
121
|
+
list.push({ angle: fullDeg, color: list[0].color });
|
|
122
|
+
return list.map((item: StopItem, index: number) => {
|
|
123
|
+
const offset = `${Math.round((item.angle * 100) / fullDeg)}%`;
|
|
124
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
125
|
+
return <Stop offset={offset} stopColor={item.color} key={index} />;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
render() {
|
|
130
|
+
const { colors } = this.state;
|
|
131
|
+
if (isLargeAppRnVersion([5, 20])) {
|
|
132
|
+
const { outerRadius, innerRadius } = this.props;
|
|
133
|
+
const size = outerRadius * 2;
|
|
134
|
+
const radius = (outerRadius + innerRadius) / 2;
|
|
135
|
+
return (
|
|
136
|
+
<View
|
|
137
|
+
style={{
|
|
138
|
+
width: size,
|
|
139
|
+
height: size,
|
|
140
|
+
borderRadius: outerRadius,
|
|
141
|
+
overflow: 'hidden',
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<Svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
|
|
145
|
+
<Defs>
|
|
146
|
+
<AndroidConicalGradent id="gradent">{this.renderStops()}</AndroidConicalGradent>
|
|
147
|
+
</Defs>
|
|
148
|
+
<G origin={`${outerRadius},${outerRadius}`}>
|
|
149
|
+
<Circle
|
|
150
|
+
cx={outerRadius}
|
|
151
|
+
cy={outerRadius}
|
|
152
|
+
r={radius}
|
|
153
|
+
fill="transparent"
|
|
154
|
+
strokeWidth={outerRadius - innerRadius}
|
|
155
|
+
stroke="url(#gradent)"
|
|
156
|
+
/>
|
|
157
|
+
</G>
|
|
158
|
+
</Svg>
|
|
159
|
+
</View>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return <Normal {...this.props} colors={colors} />;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { processColor, View } from 'react-native';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import Normal from './Normal';
|
|
5
|
+
import IOSConicalGradent from './Ios';
|
|
6
|
+
import { isLargeAppRnVersion } from './utils';
|
|
7
|
+
import { StopItem } from './interface';
|
|
8
|
+
|
|
9
|
+
const fullDeg = Math.PI * 2;
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
/**
|
|
13
|
+
* 外圈半径
|
|
14
|
+
*/
|
|
15
|
+
outerRadius: number;
|
|
16
|
+
/**
|
|
17
|
+
* 内圈半径
|
|
18
|
+
*/
|
|
19
|
+
innerRadius: number;
|
|
20
|
+
/**
|
|
21
|
+
* 切分角度
|
|
22
|
+
*/
|
|
23
|
+
segmentAngle: number;
|
|
24
|
+
/**
|
|
25
|
+
* 偏移角度
|
|
26
|
+
*/
|
|
27
|
+
offsetAngle: number;
|
|
28
|
+
/**
|
|
29
|
+
* 渐变颜色配置
|
|
30
|
+
*/
|
|
31
|
+
colors: StopItem[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface State {
|
|
35
|
+
colors: StopItem[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default class ConicalGradent extends Component<Props, State> {
|
|
39
|
+
static defaultProps = {
|
|
40
|
+
outerRadius: 120,
|
|
41
|
+
innerRadius: 80,
|
|
42
|
+
offsetAngle: 0,
|
|
43
|
+
colors: [
|
|
44
|
+
{ angle: 0, color: 'red' },
|
|
45
|
+
{ angle: fullDeg, color: 'green' },
|
|
46
|
+
],
|
|
47
|
+
segmentAngle: fullDeg / 360, // 每隔多少度切一个颜色
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
constructor(props: Props) {
|
|
51
|
+
super(props);
|
|
52
|
+
this.state = {
|
|
53
|
+
colors: this.getColors(this.props.colors),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// eslint-disable-next-line react/no-deprecated
|
|
58
|
+
componentWillReceiveProps(nextProps: Props) {
|
|
59
|
+
if (!_.isEqual(nextProps.colors, this.props.colors)) {
|
|
60
|
+
this.setState({ colors: [...nextProps.colors] });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
shouldComponentUpdate(nextProps: Props, nextState: State) {
|
|
65
|
+
const { outerRadius, innerRadius, segmentAngle, offsetAngle, colors } = nextProps;
|
|
66
|
+
const {
|
|
67
|
+
outerRadius: oldOuterRadius,
|
|
68
|
+
innerRadius: oldinnerRadius,
|
|
69
|
+
segmentAngle: oldSegmentAngle,
|
|
70
|
+
offsetAngle: oldOffsetAngle,
|
|
71
|
+
colors: oldColors,
|
|
72
|
+
} = nextProps;
|
|
73
|
+
return (
|
|
74
|
+
!_.isEqual(outerRadius, oldOuterRadius) ||
|
|
75
|
+
!_.isEqual(innerRadius, oldinnerRadius) ||
|
|
76
|
+
!_.isEqual(segmentAngle, oldSegmentAngle) ||
|
|
77
|
+
!_.isEqual(offsetAngle, oldOffsetAngle) ||
|
|
78
|
+
!_.isEqual(colors, oldColors) ||
|
|
79
|
+
!_.isEqual(this.state.colors, nextState.colors)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getColors(colors: StopItem[]) {
|
|
84
|
+
return [...colors].sort((a, b) => {
|
|
85
|
+
return a.angle > b.angle ? 1 : -1;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setColors(colors: StopItem[]) {
|
|
90
|
+
this.setState({ colors: this.getColors(colors) });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getIosProps() {
|
|
94
|
+
const { outerRadius, innerRadius, offsetAngle } = this.props;
|
|
95
|
+
const { colors } = this.state;
|
|
96
|
+
const lastAngle = colors[colors.length - 1].angle;
|
|
97
|
+
const list: StopItem[] = colors
|
|
98
|
+
.map(item => ({ angle: lastAngle - item.angle, color: item.color }))
|
|
99
|
+
.reverse();
|
|
100
|
+
list.push({ angle: fullDeg, color: list[0].color });
|
|
101
|
+
const size = outerRadius * 2;
|
|
102
|
+
return {
|
|
103
|
+
innerRadius: innerRadius / outerRadius,
|
|
104
|
+
fromDegree: ((offsetAngle - fullDeg + lastAngle) * 180) / Math.PI,
|
|
105
|
+
colors: list.map(item => processColor(item.color)),
|
|
106
|
+
stops: list.map(item => item.angle / fullDeg),
|
|
107
|
+
style: { width: size, height: size },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
render() {
|
|
112
|
+
const { colors } = this.state;
|
|
113
|
+
if (isLargeAppRnVersion([5, 19])) {
|
|
114
|
+
const { outerRadius } = this.props;
|
|
115
|
+
const size = outerRadius * 2;
|
|
116
|
+
return (
|
|
117
|
+
<View style={{ width: size, height: size, borderRadius: outerRadius, overflow: 'hidden' }}>
|
|
118
|
+
<IOSConicalGradent {...this.getIosProps()} />
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return <Normal {...this.props} colors={colors} />;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { processColor } from 'react-native';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import Normal from './Normal';
|
|
5
|
+
import { StopItem } from './interface';
|
|
6
|
+
|
|
7
|
+
const fullDeg = Math.PI * 2;
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
/**
|
|
11
|
+
* 外圈半径
|
|
12
|
+
*/
|
|
13
|
+
outerRadius: number;
|
|
14
|
+
/**
|
|
15
|
+
* 内圈半径
|
|
16
|
+
*/
|
|
17
|
+
innerRadius: number;
|
|
18
|
+
/**
|
|
19
|
+
* 切分角度
|
|
20
|
+
*/
|
|
21
|
+
segmentAngle: number;
|
|
22
|
+
/**
|
|
23
|
+
* 偏移角度
|
|
24
|
+
*/
|
|
25
|
+
offsetAngle: number;
|
|
26
|
+
/**
|
|
27
|
+
* 渐变颜色配置
|
|
28
|
+
*/
|
|
29
|
+
colors: StopItem[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface State {
|
|
33
|
+
colors: StopItem[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default class ConicalGradent extends Component<Props, State> {
|
|
37
|
+
static defaultProps = {
|
|
38
|
+
outerRadius: 120,
|
|
39
|
+
innerRadius: 80,
|
|
40
|
+
offsetAngle: 0,
|
|
41
|
+
colors: [
|
|
42
|
+
{ angle: 0, color: 'red' },
|
|
43
|
+
{ angle: fullDeg, color: 'green' },
|
|
44
|
+
],
|
|
45
|
+
segmentAngle: fullDeg / 360, // 每隔多少度切一个颜色
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
constructor(props: Props) {
|
|
49
|
+
super(props);
|
|
50
|
+
this.state = {
|
|
51
|
+
colors: this.getColors(this.props.colors),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line react/no-deprecated
|
|
56
|
+
componentWillReceiveProps(nextProps: Props) {
|
|
57
|
+
if (!_.isEqual(nextProps.colors, this.props.colors)) {
|
|
58
|
+
this.setState({ colors: [...nextProps.colors] });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getColors(colors: StopItem[]) {
|
|
63
|
+
return [...colors].sort((a, b) => {
|
|
64
|
+
return a.angle > b.angle ? 1 : -1;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
setColors(colors: StopItem[]) {
|
|
69
|
+
this.setState({ colors: this.getColors(colors) });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getIosProps() {
|
|
73
|
+
const { outerRadius, innerRadius, offsetAngle } = this.props;
|
|
74
|
+
const { colors } = this.state;
|
|
75
|
+
const lastAngle = colors[colors.length - 1].angle;
|
|
76
|
+
const list: StopItem[] = colors
|
|
77
|
+
.map(item => ({ angle: lastAngle - item.angle, color: item.color }))
|
|
78
|
+
.reverse();
|
|
79
|
+
list.push({ angle: fullDeg, color: list[0].color });
|
|
80
|
+
const size = outerRadius * 2;
|
|
81
|
+
return {
|
|
82
|
+
innerRadius: innerRadius / outerRadius,
|
|
83
|
+
fromDegree: ((offsetAngle - fullDeg + lastAngle) * 180) / Math.PI,
|
|
84
|
+
colors: list.map(item => processColor(item.color)),
|
|
85
|
+
stops: list.map(item => item.angle / fullDeg),
|
|
86
|
+
style: { width: size, height: size },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
render() {
|
|
91
|
+
const { colors } = this.state;
|
|
92
|
+
return <Normal {...this.props} colors={colors} />;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface StopItem {
|
|
2
|
+
angle: number;
|
|
3
|
+
color: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface Coordinate {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ColorItem {
|
|
12
|
+
path?: string;
|
|
13
|
+
from?: Coordinate;
|
|
14
|
+
to?: Coordinate;
|
|
15
|
+
startColor?: string;
|
|
16
|
+
endColor?: string;
|
|
17
|
+
angle?: number;
|
|
18
|
+
color?: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TYSdk } from 'tuya-panel-kit';
|
|
2
|
+
|
|
3
|
+
export const isLargeAppRnVersion = (target: number[]): boolean => {
|
|
4
|
+
const { mobile } = TYSdk;
|
|
5
|
+
if (!mobile.mobileInfo) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
const {
|
|
9
|
+
mobileInfo: { appRnVersion },
|
|
10
|
+
} = mobile;
|
|
11
|
+
let versionInfo = [];
|
|
12
|
+
if (typeof appRnVersion === 'string') {
|
|
13
|
+
versionInfo = appRnVersion.split('.');
|
|
14
|
+
}
|
|
15
|
+
if (+versionInfo[0] > +target[0]) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (versionInfo[1] !== undefined && target[1] !== undefined && +versionInfo[1] > +target[1]) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (versionInfo[2] !== undefined && target[2] !== undefined && +versionInfo[2] > +target[2]) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
};
|