@ledvance/base 1.2.81 → 1.2.83

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.
Files changed (165) hide show
  1. package/.babelrc +31 -31
  2. package/.eslintignore +5 -5
  3. package/.eslintrc.js +27 -27
  4. package/.prettierrc.js +1 -1
  5. package/.versionrc +5 -5
  6. package/localazy.json +848 -848
  7. package/localazy.keys.json +4 -4
  8. package/package.json +74 -74
  9. package/rn-cli.config.js +8 -8
  10. package/src/api/native.d.ts +71 -71
  11. package/src/api/native.ts +423 -423
  12. package/src/api/nativeEventEmitter.d.ts +3 -3
  13. package/src/api/nativeEventEmitter.ts +125 -125
  14. package/src/components/AdvanceCard.d.ts +25 -25
  15. package/src/components/AdvanceCard.tsx +117 -117
  16. package/src/components/AdvanceList.d.ts +9 -9
  17. package/src/components/AdvanceList.tsx +69 -69
  18. package/src/components/ApplyForDeviceItem.d.ts +6 -6
  19. package/src/components/ApplyForDeviceItem.tsx +83 -83
  20. package/src/components/ApplyForDeviceList.d.ts +7 -7
  21. package/src/components/ApplyForDeviceList.tsx +61 -61
  22. package/src/components/ApplyForText.d.ts +6 -6
  23. package/src/components/ApplyForText.tsx +52 -52
  24. package/src/components/Card.d.ts +10 -10
  25. package/src/components/Card.tsx +40 -40
  26. package/src/components/Cell.d.ts +21 -21
  27. package/src/components/Cell.tsx +69 -69
  28. package/src/components/CircularProgress.d.ts +8 -8
  29. package/src/components/CircularProgress.tsx +42 -42
  30. package/src/components/ColorAdjustView.d.ts +12 -12
  31. package/src/components/ColorAdjustView.tsx +64 -64
  32. package/src/components/ColorExtractor.d.ts +73 -73
  33. package/src/components/ColorExtractor.tsx +374 -374
  34. package/src/components/ColorTempAdjustView.d.ts +13 -13
  35. package/src/components/ColorTempAdjustView.tsx +57 -57
  36. package/src/components/ColorsLine.d.ts +7 -7
  37. package/src/components/ColorsLine.tsx +47 -47
  38. package/src/components/CustomListDialog.d.ts +15 -15
  39. package/src/components/CustomListDialog.tsx +66 -65
  40. package/src/components/DeleteButton.d.ts +10 -10
  41. package/src/components/DeleteButton.tsx +40 -40
  42. package/src/components/Dialog.d.ts +10 -10
  43. package/src/components/Dialog.tsx +38 -38
  44. package/src/components/DrawToolView.d.ts +46 -46
  45. package/src/components/DrawToolView.tsx +262 -262
  46. package/src/components/FanAdjustView.d.ts +23 -23
  47. package/src/components/FanAdjustView.tsx +141 -141
  48. package/src/components/InfoText.d.ts +11 -11
  49. package/src/components/InfoText.tsx +45 -45
  50. package/src/components/LampAdjustView.d.ts +10 -10
  51. package/src/components/LampAdjustView.tsx +75 -75
  52. package/src/components/LampAdjustView2.d.ts +24 -24
  53. package/src/components/LampAdjustView2.tsx +104 -104
  54. package/src/components/LinearGradientLine.d.ts +9 -9
  55. package/src/components/LinearGradientLine.tsx +63 -63
  56. package/src/components/LoadingView.tsx +39 -39
  57. package/src/components/MoodColorsLine.d.ts +9 -9
  58. package/src/components/MoodColorsLine.tsx +38 -38
  59. package/src/components/Page.d.ts +21 -21
  60. package/src/components/Page.tsx +104 -104
  61. package/src/components/Popup.d.ts +7 -7
  62. package/src/components/Popup.tsx +71 -71
  63. package/src/components/Segmented.d.ts +14 -14
  64. package/src/components/Segmented.tsx +76 -76
  65. package/src/components/ShowSelect.d.ts +1 -1
  66. package/src/components/ShowSelect.tsx +158 -158
  67. package/src/components/SocketItem.d.ts +13 -13
  68. package/src/components/SocketItem.tsx +87 -87
  69. package/src/components/Spacer.d.ts +7 -7
  70. package/src/components/Spacer.tsx +13 -13
  71. package/src/components/Stepper.d.ts +19 -19
  72. package/src/components/Stepper.tsx +130 -130
  73. package/src/components/StripAdjustView.d.ts +16 -16
  74. package/src/components/StripAdjustView.tsx +129 -129
  75. package/src/components/StripLightView.d.ts +14 -14
  76. package/src/components/StripLightView.tsx +24 -24
  77. package/src/components/Summary.tsx +116 -124
  78. package/src/components/Tag.d.ts +8 -8
  79. package/src/components/Tag.tsx +56 -56
  80. package/src/components/TextButton.d.ts +9 -9
  81. package/src/components/TextButton.tsx +31 -31
  82. package/src/components/TextField.d.ts +9 -9
  83. package/src/components/TextField.tsx +92 -92
  84. package/src/components/TextFieldStyleButton.d.ts +8 -8
  85. package/src/components/TextFieldStyleButton.tsx +85 -85
  86. package/src/components/UATabTitle.d.ts +6 -6
  87. package/src/components/UATabTitle.tsx +31 -31
  88. package/src/components/UATabs.d.ts +12 -12
  89. package/src/components/UATabs.tsx +77 -77
  90. package/src/components/connect.d.ts +10 -10
  91. package/src/components/connect.tsx +20 -20
  92. package/src/components/ldvColorBrightness.d.ts +1 -1
  93. package/src/components/ldvColorBrightness.tsx +18 -18
  94. package/src/components/ldvColorSlider.d.ts +14 -14
  95. package/src/components/ldvColorSlider.tsx +131 -131
  96. package/src/components/ldvItemView.d.ts +12 -12
  97. package/src/components/ldvItemView.tsx +43 -43
  98. package/src/components/ldvPickerView.d.ts +13 -13
  99. package/src/components/ldvPickerView.tsx +97 -97
  100. package/src/components/ldvPresetView.d.ts +2 -2
  101. package/src/components/ldvPresetView.tsx +86 -86
  102. package/src/components/ldvSaturation.d.ts +2 -2
  103. package/src/components/ldvSaturation.tsx +22 -22
  104. package/src/components/ldvSlider.d.ts +15 -15
  105. package/src/components/ldvSlider.tsx +103 -103
  106. package/src/components/ldvSwitch.d.ts +10 -10
  107. package/src/components/ldvSwitch.tsx +52 -52
  108. package/src/components/ldvTemperatureSlider.d.ts +13 -13
  109. package/src/components/ldvTemperatureSlider.tsx +139 -139
  110. package/src/components/ldvTopBar.d.ts +10 -10
  111. package/src/components/ldvTopBar.tsx +76 -76
  112. package/src/components/ldvTopName.d.ts +9 -9
  113. package/src/components/ldvTopName.tsx +63 -63
  114. package/src/components/segmentControl.d.ts +1 -1
  115. package/src/components/segmentControl.tsx +65 -65
  116. package/src/components/weekSelect.d.ts +7 -7
  117. package/src/components/weekSelect.tsx +98 -98
  118. package/src/composeLayout.d.ts +30 -30
  119. package/src/composeLayout.tsx +261 -261
  120. package/src/config/dark-theme.ts +61 -61
  121. package/src/config/light-theme.ts +61 -61
  122. package/src/hooks/Hooks.d.ts +2 -2
  123. package/src/hooks/Hooks.ts +8 -8
  124. package/src/i18n/index.d.ts +16 -16
  125. package/src/i18n/index.ts +37 -37
  126. package/src/i18n/strings.d.ts +15953 -15953
  127. package/src/i18n/strings.ts +23723 -23723
  128. package/src/main.tsx +9 -9
  129. package/src/models/GlobalParams.d.ts +14 -14
  130. package/src/models/GlobalParams.ts +14 -14
  131. package/src/models/TuyaApi.d.ts +29 -29
  132. package/src/models/TuyaApi.ts +92 -92
  133. package/src/models/combine.d.ts +26 -26
  134. package/src/models/combine.ts +17 -17
  135. package/src/models/configureStore.d.ts +9 -9
  136. package/src/models/configureStore.ts +33 -33
  137. package/src/models/index.d.ts +31 -31
  138. package/src/models/index.ts +22 -22
  139. package/src/models/modules/NativePropsSlice.d.ts +61 -61
  140. package/src/models/modules/NativePropsSlice.tsx +467 -467
  141. package/src/models/modules/Result.d.ts +14 -14
  142. package/src/models/modules/Result.ts +15 -15
  143. package/src/models/modules/common.d.ts +44 -44
  144. package/src/models/modules/common.ts +161 -161
  145. package/src/res/index.d.ts +70 -70
  146. package/src/res/index.ts +73 -73
  147. package/src/utils/ColorParser.d.ts +66 -66
  148. package/src/utils/ColorParser.ts +189 -189
  149. package/src/utils/ColorUtils.d.ts +71 -71
  150. package/src/utils/ColorUtils.tsx +448 -448
  151. package/src/utils/Support.d.ts +13 -13
  152. package/src/utils/Support.ts +108 -108
  153. package/src/utils/TypeUtils.d.ts +3 -3
  154. package/src/utils/cctUtils.d.ts +1 -1
  155. package/src/utils/cctUtils.ts +110 -110
  156. package/src/utils/common.d.ts +35 -35
  157. package/src/utils/common.ts +379 -379
  158. package/src/utils/index.d.ts +26 -26
  159. package/src/utils/index.ts +191 -191
  160. package/src/utils/interface.d.ts +6 -6
  161. package/src/utils/interface.ts +50 -11
  162. package/src/utils/loopsCompare.d.ts +1 -1
  163. package/src/utils/loopsCompare.ts +62 -62
  164. package/tsconfig.json +50 -50
  165. package/update-localazy.py +52 -52
@@ -1,375 +1,375 @@
1
- import React, { Component } from 'react'
2
- import { Dimensions, Image, PanResponder, View, StyleSheet, PanResponderInstance } from 'react-native'
3
- import { TYSdk } from 'tuya-panel-kit'
4
-
5
- import ColorUtils from '../utils/ColorUtils'
6
- import res from '@res'
7
-
8
- export default class ColorExtractor extends Component<any> {
9
- state: any
10
- _panResponder: PanResponderInstance
11
- onColorChange: any
12
- lastX: any
13
- lastY: any
14
- self: any
15
- startTouchXY: any
16
-
17
- constructor(props) {
18
- super(props)
19
- let {
20
- thumbSizeW,
21
- radius,
22
- color,
23
- onColorChange,
24
- colorTemperatureInterval,
25
- miniColorTemperature,
26
- } = !!props && props
27
- this.onColorChange = onColorChange
28
- radius = radius || 130
29
- thumbSizeW = thumbSizeW || 30
30
- const currentColor = color
31
- this.state = {
32
- thumbSizeW,
33
- radius,
34
- offset: { x: radius - thumbSizeW / 2, y: radius - thumbSizeW / 2 },
35
- currentColor,
36
- ratio: 0,
37
- miniColorTemperature: !!miniColorTemperature ? miniColorTemperature : 2700,
38
- colorTemperatureInterval: colorTemperatureInterval,
39
- }
40
- this.lastX = radius - thumbSizeW / 2
41
- this.lastY = radius - thumbSizeW / 2
42
- }
43
-
44
- onLayout(_: any) {
45
-
46
- }
47
-
48
- componentDidMount() {
49
- this.updateUIWithColor(this.state.currentColor, true)
50
- // 图标的手势
51
- this._panResponder = PanResponder.create({
52
- onMoveShouldSetPanResponder: () => {
53
- return true
54
- },
55
- onPanResponderMove: (evt, gestureState) => {
56
- this.handlerData(evt, gestureState, true)
57
- },
58
- onPanResponderRelease: (evt, gestureState) => {
59
- this.handlerData(evt, gestureState, false)
60
- },
61
- })
62
-
63
- if (this.props.showColorTemperature) {
64
- TYSdk.event.off('onColorTempChange')
65
- TYSdk.event.on('onColorTempChange', (color) => {
66
- this.updateUIWithColor(color, false)
67
- })
68
- } else {
69
- TYSdk.event.off('onColorChange')
70
- TYSdk.event.on('onColorChange', (color) => {
71
- this.updateUIWithColor(color, false)
72
- })
73
- }
74
- }
75
-
76
- componentWillUnmount() {
77
- TYSdk.event.off('onColorChange')
78
- TYSdk.event.off('onColorTempChange')
79
- }
80
-
81
- handleTapData(evt) {
82
- if (!!this.props.disabled) {
83
- return
84
- }
85
- let tapX = evt.nativeEvent.locationX
86
- let tapY = evt.nativeEvent.locationY
87
- let result = this.getPointValues(tapX, tapY)
88
- let maxX = result.maxX
89
- let maxY = result.maxY
90
- this.setState({
91
- offset: {
92
- x: maxX,
93
- y: maxY,
94
- },
95
- })
96
- this.lastX = maxX
97
- this.lastY = maxY
98
- this.updateColor(evt.nativeEvent.locationX, evt.nativeEvent.locationY, false)
99
- }
100
-
101
- handlerData(_evt, ges, moving) {
102
- if (!!this.props.disabled) {
103
- return
104
- }
105
-
106
- //此时视图的坐标
107
- let locationX = this.lastX + ges.dx + this.state.thumbSizeW / 2
108
- let locationY = this.lastY + ges.dy + this.state.thumbSizeW / 2
109
- // 获取在父元素的实际坐标点值
110
- let result = this.getPointValues(locationX, locationY)
111
- let maxX = result.maxX
112
- let maxY = result.maxY
113
- // 获取此点的颜色值
114
- this.updateColor(locationX, locationY, moving)
115
-
116
- this.setState({
117
- offset: {
118
- x: maxX,
119
- y: maxY,
120
- },
121
- })
122
-
123
- if (!(!!moving)) {
124
- // 记录滑动前 图表的位置
125
- this.lastX = this.state.offset.x
126
- this.lastY = this.state.offset.y
127
- }
128
- }
129
-
130
- // 获取实际坐标的 角度 坐标值 步长
131
- getPointValues(locationX, locationY) {
132
- //半径
133
- let radius = this.state.radius
134
- // 求斜边的长度
135
- let offsetX = Math.abs(radius - locationX)
136
- let offsetY = Math.abs(radius - locationY)
137
- let length = Math.sqrt(offsetX * offsetX + offsetY * offsetY)// 斜边长度
138
- //求角度
139
- // let angle = Math.atan2(offsetY, offsetX) * (180 / Math.PI)
140
- let angle = this.getPointAngle(radius - locationX, radius - locationY)
141
- // console.log('是否出界'+[locationX,locationY,angle])
142
- // 最终的坐标
143
- let maxX = locationX - this.state.thumbSizeW / 2//this.lastX + ges.dx
144
- let maxY = locationY - this.state.thumbSizeW / 2//this.lastY + ges.dy
145
- if (length > this.state.radius) {
146
- // 超出边界
147
- let maxOffsetX = this.state.radius * (locationX - radius) / length
148
- let maxOffsetY = this.state.radius * (radius - locationY) / length
149
- maxX = radius + maxOffsetX - this.state.thumbSizeW / 2
150
- maxY = radius - maxOffsetY - this.state.thumbSizeW / 2
151
- length = this.state.radius
152
- }
153
- return {
154
- angle: angle,
155
- maxX: maxX,
156
- maxY: maxY,
157
- length: length,
158
- }
159
- }
160
-
161
- getPointAngle(x, y) {
162
- // 此时的角度是从左边为 0°开始 顺时针 到右边为 180° 逆时针到最右边为 -180°
163
- let angle = Math.atan2(y, x) * (180 / Math.PI)
164
- // 此转换为左边 0° 顺时针转一圈为 360°
165
- angle = 180 - angle
166
- //console.log('获取角度' + angle)
167
- return angle
168
- }
169
-
170
- // 根据颜色值更新图标的位置 color : #ffffff
171
- updateUIWithColor(color, isFirst) {
172
- const { radius } = this.state
173
- // 根据初始的颜色值回去图标的坐标
174
- const hsv = ColorUtils.hex2Hsv(color)
175
- //console.log('初始值颜色' + [hsv.h, hsv.s, hsv.v])
176
-
177
- //角度
178
- let angle = 180 - hsv.h
179
- // 在色盘中的步长
180
- let length = (radius / 100) * hsv.s
181
- //
182
- const offset = this.hypotenuse(length, angle)
183
- const offsetX = radius - offset.x - this.state.thumbSizeW / 2
184
- const offsetY = radius - offset.y - this.state.thumbSizeW / 2
185
-
186
- this.lastX = offsetX
187
- this.lastY = offsetY
188
- this.setState({
189
- currentColor: color,
190
- offset: {
191
- x: offsetX,
192
- y: offsetY,
193
- },
194
- ratio: hsv.s / 100,
195
- }, () => {
196
- this.updateColor(offsetX + this.state.thumbSizeW / 2, offsetY + this.state.thumbSizeW / 2, false, isFirst)
197
- })
198
- }
199
-
200
- //已知角度和斜边,求直角边
201
- hypotenuse(long, angle) {
202
- //获得弧度
203
- const radian = 2 * Math.PI / 360 * angle
204
- return {
205
- x: Math.cos(radian) * long,
206
- y: Math.sin(radian) * long,
207
- }
208
- }
209
-
210
- // 根据坐标的位置 获取颜色值
211
- updateColor(x, y, moving, isFirst?: boolean) {
212
- const { angle, length } = this.getPointValues(x, y)
213
- //console.log('根据坐标的位置 获取颜色值', angle, maxX, maxY, length);
214
- let radius = length / this.state.radius
215
- const rad = radius > 1 ? 1 : radius
216
- const hsv = { h: angle, s: 100 * rad, v: 100 }
217
- const currentColor = ColorUtils.hsv2Hex(hsv)
218
- this.setState({ currentColor, ratio: rad })
219
- //console.log('获取当前的颜色' + [currentColor, angle])
220
- //滑动结束 发送当前颜色值
221
- if (moving === false) {
222
- this.onColorChange && this.onColorChange(hsv, isFirst)
223
- }
224
- }
225
-
226
- render() {
227
- const { radius, offset, ratio, miniColorTemperature, colorTemperatureInterval } = this.state
228
- const { x, y } = offset
229
- const { showColorTemperature } = this.props
230
- return (
231
- <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
232
- <View
233
- ref={node => {
234
- this.self = node
235
- }}
236
- onLayout={nativeEvent => this.onLayout(nativeEvent)}
237
- style={[{
238
- height: radius * 2,
239
- width: radius * 2,
240
- }, this.props.style]}>
241
-
242
- <View
243
- style={[styles.img, {
244
- height: radius * 2,
245
- width: radius * 2,
246
- }]}>
247
- <Image
248
- style={{
249
- height: radius * 2,
250
- width: radius * 2,
251
- alignItems: 'center',
252
- position: 'absolute',
253
- }}
254
- source={{ uri: !!showColorTemperature ? res.color_temperature_wheel : res.color_wheel }}
255
- // @ts-ignore
256
- onStartShouldSetResponder={(evt) => {
257
- this.startTouchXY = evt.nativeEvent
258
- return true
259
- }}
260
- onResponderMove={() => {
261
- return false
262
- }}
263
- onResponderRelease={(evt) => {
264
- const { locationX, locationY, timestamp } = !!this.startTouchXY && this.startTouchXY
265
- const endLocationX = evt.nativeEvent.locationX
266
- const endLocationY = evt.nativeEvent.locationY
267
- const endTimestamp = evt.nativeEvent.timestamp
268
-
269
- if (Math.abs(locationX - endLocationX) <= 10 && Math.abs(locationY - endLocationY) <= 10 && endTimestamp - timestamp < 500) {
270
- this.handleTapData(evt)
271
- }
272
- }} />
273
- {<View
274
- {...(this._panResponder || {}).panHandlers}
275
- style={{
276
- marginTop: y,
277
- marginLeft: x,
278
- width: this.state.thumbSizeW,
279
- height: this.state.thumbSizeW,
280
- position: 'absolute',
281
- backgroundColor: '#ffffff',
282
- elevation: !!this.props.disabled ? 0 : 3,
283
- shadowOpacity: 0.15,
284
- shadowRadius: 5,
285
- shadowOffset: { width: 0, height: 3.5 },
286
- borderRadius: this.state.thumbSizeW / 2,
287
- }}>
288
- {!(!!showColorTemperature) && <View
289
- style={{
290
- marginTop: 3,
291
- marginLeft: 3,
292
- width: this.state.thumbSizeW - 6,
293
- height: this.state.thumbSizeW - 6,
294
- position: 'absolute',
295
- backgroundColor: this.state.currentColor,
296
- borderRadius: (this.state.thumbSizeW - 6) / 2,
297
- }}>
298
- </View>}
299
-
300
- {!!showColorTemperature && <View
301
- style={{
302
- marginTop: 3,
303
- marginLeft: 3,
304
- width: this.state.thumbSizeW - 6,
305
- height: this.state.thumbSizeW - 6,
306
- position: 'absolute',
307
- backgroundColor: colorTemperatureToColor(miniColorTemperature + ratio * colorTemperatureInterval),
308
- borderRadius: (this.state.thumbSizeW - 6) / 2,
309
- }}>
310
- </View>}
311
- </View>}
312
- </View>
313
- </View>
314
- </View>
315
- )
316
- }
317
- }
318
- const styles = StyleSheet.create({
319
- colorWheelStyle: {
320
- width: Dimensions.get('window').width,
321
- },
322
- coverResponder: {
323
- width: 260,
324
- height: 260,
325
- },
326
- img: {},
327
- })
328
-
329
- export const colorTemperature = {
330
- 2700: '#FFDC94',
331
- 2800: '#FFDD96',
332
- 2900: '#FFDF9A',
333
- 3000: '#FFE19D',
334
- 3100: '#FFE29F',
335
- 3200: '#FFE4A3',
336
- 3300: '#FFE5A6',
337
- 3400: '#FFE7A9',
338
- 3500: '#FFE8AC',
339
- 3600: '#FFEAAF',
340
- 3700: '#FFECB3',
341
- 3800: '#FFEDB6',
342
- 3900: '#FFEFB9',
343
- 4000: '#FFF0BB',
344
- 4100: '#FFF2BF',
345
- 4200: '#FFF3C2',
346
- 4300: '#FFF5C5',
347
- 4400: '#FFF6C8',
348
- 4500: '#FFF8CB',
349
- 4600: '#FFFACF',
350
- 4700: '#FFFBD2',
351
- 4800: '#FFFCD4',
352
- 4900: '#FFFDD7',
353
- 5000: '#FEFEDA',
354
- 5100: '#FEFEDD',
355
- 5200: '#FEFFE0',
356
- 5300: '#FAFEE1',
357
- 5400: '#F7FEE3',
358
- 5500: '#F3FCE3',
359
- 5600: '#F0FCE4',
360
- 5700: '#EDFBE6',
361
- 5800: '#E9FAE6',
362
- 5900: '#E5F9E8',
363
- 6000: '#E2F9E9',
364
- 6100: '#DFF8EA',
365
- 6200: '#DCF7EC',
366
- 6300: '#D7F6EC',
367
- 6400: '#D4F5ED',
368
- 6500: '#D1F5EF',
369
- }
370
-
371
- export const colorTemperatureToColor = (temperature) => {
372
- const colorTemperatureValue = parseInt(`${temperature / 100}`, 10) * 100
373
- //console.log("colorTemperatureValue :::::: ",colorTemperatureValue,colorTemperature[`${colorTemperatureValue}`])
374
- return colorTemperature[colorTemperatureValue]
1
+ import React, { Component } from 'react'
2
+ import { Dimensions, Image, PanResponder, View, StyleSheet, PanResponderInstance } from 'react-native'
3
+ import { TYSdk } from 'tuya-panel-kit'
4
+
5
+ import ColorUtils from '../utils/ColorUtils'
6
+ import res from '@res'
7
+
8
+ export default class ColorExtractor extends Component<any> {
9
+ state: any
10
+ _panResponder: PanResponderInstance
11
+ onColorChange: any
12
+ lastX: any
13
+ lastY: any
14
+ self: any
15
+ startTouchXY: any
16
+
17
+ constructor(props) {
18
+ super(props)
19
+ let {
20
+ thumbSizeW,
21
+ radius,
22
+ color,
23
+ onColorChange,
24
+ colorTemperatureInterval,
25
+ miniColorTemperature,
26
+ } = !!props && props
27
+ this.onColorChange = onColorChange
28
+ radius = radius || 130
29
+ thumbSizeW = thumbSizeW || 30
30
+ const currentColor = color
31
+ this.state = {
32
+ thumbSizeW,
33
+ radius,
34
+ offset: { x: radius - thumbSizeW / 2, y: radius - thumbSizeW / 2 },
35
+ currentColor,
36
+ ratio: 0,
37
+ miniColorTemperature: !!miniColorTemperature ? miniColorTemperature : 2700,
38
+ colorTemperatureInterval: colorTemperatureInterval,
39
+ }
40
+ this.lastX = radius - thumbSizeW / 2
41
+ this.lastY = radius - thumbSizeW / 2
42
+ }
43
+
44
+ onLayout(_: any) {
45
+
46
+ }
47
+
48
+ componentDidMount() {
49
+ this.updateUIWithColor(this.state.currentColor, true)
50
+ // 图标的手势
51
+ this._panResponder = PanResponder.create({
52
+ onMoveShouldSetPanResponder: () => {
53
+ return true
54
+ },
55
+ onPanResponderMove: (evt, gestureState) => {
56
+ this.handlerData(evt, gestureState, true)
57
+ },
58
+ onPanResponderRelease: (evt, gestureState) => {
59
+ this.handlerData(evt, gestureState, false)
60
+ },
61
+ })
62
+
63
+ if (this.props.showColorTemperature) {
64
+ TYSdk.event.off('onColorTempChange')
65
+ TYSdk.event.on('onColorTempChange', (color) => {
66
+ this.updateUIWithColor(color, false)
67
+ })
68
+ } else {
69
+ TYSdk.event.off('onColorChange')
70
+ TYSdk.event.on('onColorChange', (color) => {
71
+ this.updateUIWithColor(color, false)
72
+ })
73
+ }
74
+ }
75
+
76
+ componentWillUnmount() {
77
+ TYSdk.event.off('onColorChange')
78
+ TYSdk.event.off('onColorTempChange')
79
+ }
80
+
81
+ handleTapData(evt) {
82
+ if (!!this.props.disabled) {
83
+ return
84
+ }
85
+ let tapX = evt.nativeEvent.locationX
86
+ let tapY = evt.nativeEvent.locationY
87
+ let result = this.getPointValues(tapX, tapY)
88
+ let maxX = result.maxX
89
+ let maxY = result.maxY
90
+ this.setState({
91
+ offset: {
92
+ x: maxX,
93
+ y: maxY,
94
+ },
95
+ })
96
+ this.lastX = maxX
97
+ this.lastY = maxY
98
+ this.updateColor(evt.nativeEvent.locationX, evt.nativeEvent.locationY, false)
99
+ }
100
+
101
+ handlerData(_evt, ges, moving) {
102
+ if (!!this.props.disabled) {
103
+ return
104
+ }
105
+
106
+ //此时视图的坐标
107
+ let locationX = this.lastX + ges.dx + this.state.thumbSizeW / 2
108
+ let locationY = this.lastY + ges.dy + this.state.thumbSizeW / 2
109
+ // 获取在父元素的实际坐标点值
110
+ let result = this.getPointValues(locationX, locationY)
111
+ let maxX = result.maxX
112
+ let maxY = result.maxY
113
+ // 获取此点的颜色值
114
+ this.updateColor(locationX, locationY, moving)
115
+
116
+ this.setState({
117
+ offset: {
118
+ x: maxX,
119
+ y: maxY,
120
+ },
121
+ })
122
+
123
+ if (!(!!moving)) {
124
+ // 记录滑动前 图表的位置
125
+ this.lastX = this.state.offset.x
126
+ this.lastY = this.state.offset.y
127
+ }
128
+ }
129
+
130
+ // 获取实际坐标的 角度 坐标值 步长
131
+ getPointValues(locationX, locationY) {
132
+ //半径
133
+ let radius = this.state.radius
134
+ // 求斜边的长度
135
+ let offsetX = Math.abs(radius - locationX)
136
+ let offsetY = Math.abs(radius - locationY)
137
+ let length = Math.sqrt(offsetX * offsetX + offsetY * offsetY)// 斜边长度
138
+ //求角度
139
+ // let angle = Math.atan2(offsetY, offsetX) * (180 / Math.PI)
140
+ let angle = this.getPointAngle(radius - locationX, radius - locationY)
141
+ // console.log('是否出界'+[locationX,locationY,angle])
142
+ // 最终的坐标
143
+ let maxX = locationX - this.state.thumbSizeW / 2//this.lastX + ges.dx
144
+ let maxY = locationY - this.state.thumbSizeW / 2//this.lastY + ges.dy
145
+ if (length > this.state.radius) {
146
+ // 超出边界
147
+ let maxOffsetX = this.state.radius * (locationX - radius) / length
148
+ let maxOffsetY = this.state.radius * (radius - locationY) / length
149
+ maxX = radius + maxOffsetX - this.state.thumbSizeW / 2
150
+ maxY = radius - maxOffsetY - this.state.thumbSizeW / 2
151
+ length = this.state.radius
152
+ }
153
+ return {
154
+ angle: angle,
155
+ maxX: maxX,
156
+ maxY: maxY,
157
+ length: length,
158
+ }
159
+ }
160
+
161
+ getPointAngle(x, y) {
162
+ // 此时的角度是从左边为 0°开始 顺时针 到右边为 180° 逆时针到最右边为 -180°
163
+ let angle = Math.atan2(y, x) * (180 / Math.PI)
164
+ // 此转换为左边 0° 顺时针转一圈为 360°
165
+ angle = 180 - angle
166
+ //console.log('获取角度' + angle)
167
+ return angle
168
+ }
169
+
170
+ // 根据颜色值更新图标的位置 color : #ffffff
171
+ updateUIWithColor(color, isFirst) {
172
+ const { radius } = this.state
173
+ // 根据初始的颜色值回去图标的坐标
174
+ const hsv = ColorUtils.hex2Hsv(color)
175
+ //console.log('初始值颜色' + [hsv.h, hsv.s, hsv.v])
176
+
177
+ //角度
178
+ let angle = 180 - hsv.h
179
+ // 在色盘中的步长
180
+ let length = (radius / 100) * hsv.s
181
+ //
182
+ const offset = this.hypotenuse(length, angle)
183
+ const offsetX = radius - offset.x - this.state.thumbSizeW / 2
184
+ const offsetY = radius - offset.y - this.state.thumbSizeW / 2
185
+
186
+ this.lastX = offsetX
187
+ this.lastY = offsetY
188
+ this.setState({
189
+ currentColor: color,
190
+ offset: {
191
+ x: offsetX,
192
+ y: offsetY,
193
+ },
194
+ ratio: hsv.s / 100,
195
+ }, () => {
196
+ this.updateColor(offsetX + this.state.thumbSizeW / 2, offsetY + this.state.thumbSizeW / 2, false, isFirst)
197
+ })
198
+ }
199
+
200
+ //已知角度和斜边,求直角边
201
+ hypotenuse(long, angle) {
202
+ //获得弧度
203
+ const radian = 2 * Math.PI / 360 * angle
204
+ return {
205
+ x: Math.cos(radian) * long,
206
+ y: Math.sin(radian) * long,
207
+ }
208
+ }
209
+
210
+ // 根据坐标的位置 获取颜色值
211
+ updateColor(x, y, moving, isFirst?: boolean) {
212
+ const { angle, length } = this.getPointValues(x, y)
213
+ //console.log('根据坐标的位置 获取颜色值', angle, maxX, maxY, length);
214
+ let radius = length / this.state.radius
215
+ const rad = radius > 1 ? 1 : radius
216
+ const hsv = { h: angle, s: 100 * rad, v: 100 }
217
+ const currentColor = ColorUtils.hsv2Hex(hsv)
218
+ this.setState({ currentColor, ratio: rad })
219
+ //console.log('获取当前的颜色' + [currentColor, angle])
220
+ //滑动结束 发送当前颜色值
221
+ if (moving === false) {
222
+ this.onColorChange && this.onColorChange(hsv, isFirst)
223
+ }
224
+ }
225
+
226
+ render() {
227
+ const { radius, offset, ratio, miniColorTemperature, colorTemperatureInterval } = this.state
228
+ const { x, y } = offset
229
+ const { showColorTemperature } = this.props
230
+ return (
231
+ <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
232
+ <View
233
+ ref={node => {
234
+ this.self = node
235
+ }}
236
+ onLayout={nativeEvent => this.onLayout(nativeEvent)}
237
+ style={[{
238
+ height: radius * 2,
239
+ width: radius * 2,
240
+ }, this.props.style]}>
241
+
242
+ <View
243
+ style={[styles.img, {
244
+ height: radius * 2,
245
+ width: radius * 2,
246
+ }]}>
247
+ <Image
248
+ style={{
249
+ height: radius * 2,
250
+ width: radius * 2,
251
+ alignItems: 'center',
252
+ position: 'absolute',
253
+ }}
254
+ source={{ uri: !!showColorTemperature ? res.color_temperature_wheel : res.color_wheel }}
255
+ // @ts-ignore
256
+ onStartShouldSetResponder={(evt) => {
257
+ this.startTouchXY = evt.nativeEvent
258
+ return true
259
+ }}
260
+ onResponderMove={() => {
261
+ return false
262
+ }}
263
+ onResponderRelease={(evt) => {
264
+ const { locationX, locationY, timestamp } = !!this.startTouchXY && this.startTouchXY
265
+ const endLocationX = evt.nativeEvent.locationX
266
+ const endLocationY = evt.nativeEvent.locationY
267
+ const endTimestamp = evt.nativeEvent.timestamp
268
+
269
+ if (Math.abs(locationX - endLocationX) <= 10 && Math.abs(locationY - endLocationY) <= 10 && endTimestamp - timestamp < 500) {
270
+ this.handleTapData(evt)
271
+ }
272
+ }} />
273
+ {<View
274
+ {...(this._panResponder || {}).panHandlers}
275
+ style={{
276
+ marginTop: y,
277
+ marginLeft: x,
278
+ width: this.state.thumbSizeW,
279
+ height: this.state.thumbSizeW,
280
+ position: 'absolute',
281
+ backgroundColor: '#ffffff',
282
+ elevation: !!this.props.disabled ? 0 : 3,
283
+ shadowOpacity: 0.15,
284
+ shadowRadius: 5,
285
+ shadowOffset: { width: 0, height: 3.5 },
286
+ borderRadius: this.state.thumbSizeW / 2,
287
+ }}>
288
+ {!(!!showColorTemperature) && <View
289
+ style={{
290
+ marginTop: 3,
291
+ marginLeft: 3,
292
+ width: this.state.thumbSizeW - 6,
293
+ height: this.state.thumbSizeW - 6,
294
+ position: 'absolute',
295
+ backgroundColor: this.state.currentColor,
296
+ borderRadius: (this.state.thumbSizeW - 6) / 2,
297
+ }}>
298
+ </View>}
299
+
300
+ {!!showColorTemperature && <View
301
+ style={{
302
+ marginTop: 3,
303
+ marginLeft: 3,
304
+ width: this.state.thumbSizeW - 6,
305
+ height: this.state.thumbSizeW - 6,
306
+ position: 'absolute',
307
+ backgroundColor: colorTemperatureToColor(miniColorTemperature + ratio * colorTemperatureInterval),
308
+ borderRadius: (this.state.thumbSizeW - 6) / 2,
309
+ }}>
310
+ </View>}
311
+ </View>}
312
+ </View>
313
+ </View>
314
+ </View>
315
+ )
316
+ }
317
+ }
318
+ const styles = StyleSheet.create({
319
+ colorWheelStyle: {
320
+ width: Dimensions.get('window').width,
321
+ },
322
+ coverResponder: {
323
+ width: 260,
324
+ height: 260,
325
+ },
326
+ img: {},
327
+ })
328
+
329
+ export const colorTemperature = {
330
+ 2700: '#FFDC94',
331
+ 2800: '#FFDD96',
332
+ 2900: '#FFDF9A',
333
+ 3000: '#FFE19D',
334
+ 3100: '#FFE29F',
335
+ 3200: '#FFE4A3',
336
+ 3300: '#FFE5A6',
337
+ 3400: '#FFE7A9',
338
+ 3500: '#FFE8AC',
339
+ 3600: '#FFEAAF',
340
+ 3700: '#FFECB3',
341
+ 3800: '#FFEDB6',
342
+ 3900: '#FFEFB9',
343
+ 4000: '#FFF0BB',
344
+ 4100: '#FFF2BF',
345
+ 4200: '#FFF3C2',
346
+ 4300: '#FFF5C5',
347
+ 4400: '#FFF6C8',
348
+ 4500: '#FFF8CB',
349
+ 4600: '#FFFACF',
350
+ 4700: '#FFFBD2',
351
+ 4800: '#FFFCD4',
352
+ 4900: '#FFFDD7',
353
+ 5000: '#FEFEDA',
354
+ 5100: '#FEFEDD',
355
+ 5200: '#FEFFE0',
356
+ 5300: '#FAFEE1',
357
+ 5400: '#F7FEE3',
358
+ 5500: '#F3FCE3',
359
+ 5600: '#F0FCE4',
360
+ 5700: '#EDFBE6',
361
+ 5800: '#E9FAE6',
362
+ 5900: '#E5F9E8',
363
+ 6000: '#E2F9E9',
364
+ 6100: '#DFF8EA',
365
+ 6200: '#DCF7EC',
366
+ 6300: '#D7F6EC',
367
+ 6400: '#D4F5ED',
368
+ 6500: '#D1F5EF',
369
+ }
370
+
371
+ export const colorTemperatureToColor = (temperature) => {
372
+ const colorTemperatureValue = parseInt(`${temperature / 100}`, 10) * 100
373
+ //console.log("colorTemperatureValue :::::: ",colorTemperatureValue,colorTemperature[`${colorTemperatureValue}`])
374
+ return colorTemperature[colorTemperatureValue]
375
375
  }