@ledvance/base 1.3.61 → 1.3.63

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "@ledvance/base",
5
5
  "pid": [],
6
6
  "uiid": "",
7
- "version": "1.3.61",
7
+ "version": "1.3.63",
8
8
  "scripts": {
9
9
  "prepublishOnly": "python update-localazy.py"
10
10
  },
package/src/api/native.ts CHANGED
@@ -52,6 +52,7 @@ export enum UADeviceCategory {
52
52
  MatterLight = 'MatterLight',
53
53
  MeshLight = 'MeshLight',
54
54
  MeshSwitch = 'MeshSwitch',
55
+ VideoDoorbell = 'VideoDoorbell',
55
56
  }
56
57
 
57
58
  export interface DeviceInfo {
@@ -1,11 +1,20 @@
1
1
  import {View} from 'react-native'
2
- import React from 'react'
2
+ import React, {useCallback} from 'react'
3
3
  import LdvColorSlider from './ldvColorSlider'
4
4
  import {hex2Hsv, hsv2Hex} from '../utils'
5
5
  import LdvPresetView from './ldvPresetView'
6
6
  import LdvSaturation from './ldvSaturation'
7
7
  import LdvColorBrightness from './ldvColorBrightness'
8
8
  import I18n from '../i18n/index'
9
+ import RectColorAndBrightPicker from './rect-color-and-bright-picker'
10
+ import {Utils} from "tuya-panel-kit";
11
+ import {useReactive, useUpdateEffect} from "ahooks";
12
+ import {useNewPalette} from "../models/modules/NativePropsSlice";
13
+
14
+ const cx = Utils.RatioUtils.convertX
15
+ const scaleUp = (value) => value * 10
16
+ const scaleDown = (value) => Math.round(value / 10)
17
+ const width = Utils.RatioUtils.width - cx(80)
9
18
 
10
19
  export interface ColorAdjustViewProps {
11
20
  h: number
@@ -19,7 +28,59 @@ export interface ColorAdjustViewProps {
19
28
  onHSVChangeComplete: (h: number, s: number, v: number) => void
20
29
  }
21
30
 
22
- const ColorAdjustView = (props: ColorAdjustViewProps) => {
31
+ const NewColorPicker = React.memo((props: ColorAdjustViewProps) => {
32
+ const { h = 0, s = 100, v = 100, minBrightness = 10, onHSVChange, onHSVChangeComplete } = props
33
+ const state = useReactive({
34
+ hue: h,
35
+ saturation: scaleUp(s),
36
+ value: scaleUp(v),
37
+ moving: false
38
+ })
39
+
40
+ useUpdateEffect(() => {
41
+ if (!state.moving) {
42
+ state.hue = h
43
+ state.saturation = scaleUp(s)
44
+ state.value = scaleUp(v)
45
+ }
46
+ }, [h, s, v])
47
+
48
+ const handleMove = useCallback((v) => {
49
+ onHSVChange?.(v.hue, scaleDown(v.saturation), scaleDown(v.value))
50
+ }, [onHSVChange])
51
+
52
+ const handleComplete = useCallback((v) => {
53
+ onHSVChangeComplete?.(v.hue, scaleDown(v.saturation), scaleDown(v.value))
54
+ state.moving = false
55
+ }, [onHSVChangeComplete])
56
+
57
+ const { hue, saturation, value } = state;
58
+ const hsv = { hue, saturation, value };
59
+
60
+ return (
61
+ <View style={{justifyContent: 'center', alignItems: 'center'}}>
62
+ <View style={{
63
+ width: width,
64
+ height: cx(200),
65
+ borderRadius: cx(10),
66
+ borderColor: '#eeeeef',
67
+ borderWidth: 1,
68
+ overflow: 'hidden'
69
+ }}>
70
+ <RectColorAndBrightPicker.ColourPicker
71
+ value={hsv}
72
+ brightOption={{min: minBrightness, minPercent: minBrightness ? 1 : 0}}
73
+ onGrant={() => state.moving = true}
74
+ onMove={handleMove}
75
+ onRelease={handleComplete}
76
+ onPress={handleComplete}
77
+ />
78
+ </View>
79
+ </View>
80
+ )
81
+ })
82
+
83
+ const OldColorPicker = React.memo((props: ColorAdjustViewProps) => {
23
84
  return (
24
85
  <View>
25
86
  <LdvColorSlider
@@ -42,14 +103,14 @@ const ColorAdjustView = (props: ColorAdjustViewProps) => {
42
103
  }
43
104
  }}/>
44
105
  {!props.hideSat && <LdvSaturation
45
- value={props.s}
46
- minSaturation={props.minSaturation}
47
- onValueChange={s => {
48
- props.onHSVChange && props.onHSVChange(props.h, s, props.v)
49
- }}
50
- onSlidingComplete={s => {
51
- props.onHSVChangeComplete(props.h, s, props.v)
52
- }}/>}
106
+ value={props.s}
107
+ minSaturation={props.minSaturation}
108
+ onValueChange={s => {
109
+ props.onHSVChange && props.onHSVChange(props.h, s, props.v)
110
+ }}
111
+ onSlidingComplete={s => {
112
+ props.onHSVChangeComplete(props.h, s, props.v)
113
+ }}/>}
53
114
  <LdvColorBrightness
54
115
  minBrightness={props.minBrightness}
55
116
  value={props.v}
@@ -61,6 +122,11 @@ const ColorAdjustView = (props: ColorAdjustViewProps) => {
61
122
  }}/>
62
123
  </View>
63
124
  )
125
+ })
126
+
127
+ const ColorAdjustView = (props: ColorAdjustViewProps) => {
128
+ const newPalette = useNewPalette()
129
+ return newPalette ? <NewColorPicker {...props} /> : <OldColorPicker {...props} />
64
130
  }
65
131
 
66
- export default ColorAdjustView
132
+ export default ColorAdjustView
@@ -1,5 +1,5 @@
1
1
  import {View} from 'react-native'
2
- import React from 'react'
2
+ import React, {useCallback} from 'react'
3
3
  import LdvColorSlider from './ldvColorSlider'
4
4
  import Spacer from './Spacer'
5
5
  import LdvPresetView from './ldvPresetView'
@@ -7,13 +7,17 @@ import LdvSlider from './ldvSlider'
7
7
  import {Utils} from 'tuya-panel-kit'
8
8
  import I18n from '../i18n/index'
9
9
  import {cctToColor} from '../utils/cctUtils'
10
- import ThemeType from '../config/themeType'
10
+ import RectColorAndBrightPicker from "./rect-color-and-bright-picker";
11
+ import {useReactive, useUpdateEffect} from 'ahooks'
12
+ import { useNewPalette } from 'models/modules/NativePropsSlice'
11
13
 
12
14
  const {convertX: cx} = Utils.RatioUtils
13
- const { withTheme } = Utils.ThemeUtils
15
+
16
+ const scaleUp = (value: number) => value * 10;
17
+ const scaleDown = (value: number) => Math.round(value / 10);
18
+ const width = Utils.RatioUtils.width - cx(80);
14
19
 
15
20
  export interface ColorTempAdjustViewProps {
16
- theme?: ThemeType
17
21
  colorTemp: number
18
22
  brightness: number
19
23
  minBrightness?: number
@@ -25,7 +29,67 @@ export interface ColorTempAdjustViewProps {
25
29
  onBrightnessChangeComplete: (brightness: number) => void
26
30
  }
27
31
 
28
- const ColorTempAdjustView = (props: ColorTempAdjustViewProps) => {
32
+ const NewColorTempPicker = React.memo((props: ColorTempAdjustViewProps) => {
33
+ const {
34
+ colorTemp = 0,
35
+ brightness = 100,
36
+ isSupportTemperature,
37
+ onCCTChange,
38
+ onCCTChangeComplete,
39
+ onBrightnessChange,
40
+ onBrightnessChangeComplete,
41
+ } = props
42
+ const state = useReactive({
43
+ temperature: scaleUp(colorTemp),
44
+ brightness: scaleUp(brightness),
45
+ moving: false
46
+ })
47
+
48
+ useUpdateEffect(() => {
49
+ if (!state.moving) {
50
+ state.temperature = scaleUp(colorTemp)
51
+ state.brightness = scaleUp(brightness)
52
+ }
53
+ }, [colorTemp, brightness])
54
+
55
+ const handleMove = useCallback((v) => {
56
+ onCCTChange?.(scaleDown(v.temperature))
57
+ onBrightnessChange?.(scaleDown(v.brightness))
58
+ }, [onCCTChange, onBrightnessChange])
59
+
60
+ const handleComplete = useCallback((v) => {
61
+ onCCTChangeComplete?.(scaleDown(v.temperature))
62
+ onBrightnessChangeComplete?.(scaleDown(v.brightness))
63
+ state.moving = false
64
+ }, [onCCTChangeComplete, onBrightnessChangeComplete])
65
+
66
+ const { temperature, brightness: stateBrightness } = state
67
+ const white = { temperature, brightness: stateBrightness }
68
+
69
+ return (
70
+ <View style={{justifyContent: 'center', alignItems: 'center'}}>
71
+ <View style={{
72
+ width: width,
73
+ height: cx(isSupportTemperature? 200 : 50),
74
+ borderRadius: cx(10),
75
+ borderColor: '#eeeeef',
76
+ borderWidth: 1,
77
+ overflow: 'hidden'
78
+ }}>
79
+ <RectColorAndBrightPicker.WhitePicker
80
+ hideTemp={!isSupportTemperature}
81
+ value={white}
82
+ onGrant={() => state.moving = true}
83
+ onMove={handleMove}
84
+ onRelease={handleComplete}
85
+ onPress={handleComplete}
86
+ />
87
+ </View>
88
+ </View>
89
+ )
90
+ })
91
+
92
+ const OldColorTempPicker = React.memo((props: ColorTempAdjustViewProps) => {
29
93
  return (
30
94
  <View>
31
95
  {props.isSupportTemperature &&
@@ -56,6 +120,11 @@ const ColorTempAdjustView = (props: ColorTempAdjustViewProps) => {
56
120
  onSlidingComplete={props.onBrightnessChangeComplete}/>}
57
121
  </View>
58
122
  )
123
+ })
124
+
125
+ const ColorTempAdjustView = (props: ColorTempAdjustViewProps) => {
126
+ const newPalette = useNewPalette()
127
+ return newPalette ? <NewColorTempPicker {...props} /> : <OldColorTempPicker {...props} />
59
128
  }
60
129
 
61
- export default withTheme(ColorTempAdjustView)
130
+ export default ColorTempAdjustView
@@ -0,0 +1,266 @@
1
+ import React, { Component } from 'react';
2
+ import _ from 'lodash';
3
+ import { View, ViewStyle, StyleProp } from 'react-native';
4
+ import RectPicker, { ValidBound, Point, defaultProps as baseDefault } from './RectPicker';
5
+ import Slider, { IBrightOption } from './Slider';
6
+ import ColorUtils from './utils/color';
7
+
8
+
9
+ export const rectGradientBg = [
10
+ {
11
+ colors: [
12
+ { offset: '0%', stopColor: '#FF0000', stopOpacity: 1 },
13
+ { offset: '8%', stopColor: '#FF7F00', stopOpacity: 1 },
14
+ { offset: '20%', stopColor: '#FFFF00', stopOpacity: 1 },
15
+ { offset: '25%', stopColor: '#7FFF00', stopOpacity: 1 },
16
+ { offset: '33%', stopColor: '#00FF00', stopOpacity: 1 },
17
+ { offset: '42%', stopColor: '#00FF7F', stopOpacity: 1 },
18
+ { offset: '50%', stopColor: '#00FFFF', stopOpacity: 1 },
19
+ { offset: '58%', stopColor: '#007FFF', stopOpacity: 1 },
20
+ { offset: '66%', stopColor: '#0000FF', stopOpacity: 1 },
21
+ { offset: '75%', stopColor: '#7F00FF', stopOpacity: 1 },
22
+ { offset: '83%', stopColor: '#FF00FF', stopOpacity: 1 },
23
+ { offset: '92%', stopColor: '#FF007F', stopOpacity: 1 },
24
+ { offset: '100%', stopColor: '#FF0000', stopOpacity: 1 },
25
+ ],
26
+ },
27
+ {
28
+ x2: '0%',
29
+ y2: '100%',
30
+ colors: [
31
+ { offset: '0%', stopColor: '#fff', stopOpacity: 1 },
32
+ { offset: '16%', stopColor: '#fff', stopOpacity: 0.9 },
33
+ { offset: '100%', stopColor: '#fff', stopOpacity: 0 },
34
+ ],
35
+ },
36
+ ];
37
+
38
+ export interface IHsv {
39
+ hue: number;
40
+ saturation: number;
41
+ value: number;
42
+ }
43
+
44
+ const defaultProps = {
45
+ ...baseDefault,
46
+ /**
47
+ * 值
48
+ */
49
+ value: { hue: 0, saturation: 1000, value: 1000 } as IHsv,
50
+ /**
51
+ * 色度偏量
52
+ */
53
+ hueOffset: 1,
54
+ /**
55
+ * 亮度配置
56
+ */
57
+ brightOption: {} as IBrightOption,
58
+ /**
59
+ * 是否隐藏亮度调节
60
+ */
61
+ hideBright: false,
62
+ /**
63
+ * 失去焦点时的亮度滑动条颜色
64
+ */
65
+ lossSliderColor: 'rgba(255,255,255,0.4)',
66
+ /**
67
+ * 背景渐变配置
68
+ */
69
+ bgs: rectGradientBg,
70
+ /**
71
+ * 滑动开始事件
72
+ * @param _v
73
+ * @param _option
74
+ */
75
+ onGrant(_v: any, _option?: { isChangeBright: boolean }) {},
76
+ /**
77
+ * 滑动过程事件
78
+ * @param _v
79
+ * @param _option
80
+ */
81
+ onMove(_v: any, _option?: { isChangeBright: boolean }) {},
82
+ /**
83
+ * 滑动结束事件
84
+ * @param _v
85
+ * @param _option
86
+ */
87
+ onRelease(_v: any, _option?: { isChangeBright: boolean }) {},
88
+ /**
89
+ * 点击事件
90
+ * @param _v
91
+ * @param _option
92
+ * @version ^0.3.0
93
+ */
94
+ onPress(_v: any, _option?: { isChangeBright: boolean }) {},
95
+ };
96
+
97
+ type DefaultProps = Readonly<typeof defaultProps>;
98
+
99
+ type ColourProps = {
100
+ /**
101
+ * 组件的样式
102
+ */
103
+ style?: StyleProp<ViewStyle>;
104
+ /**
105
+ * 颜色选择区的样式
106
+ */
107
+ rectStyle?: StyleProp<ViewStyle>;
108
+ } & DefaultProps;
109
+
110
+ type IState = IHsv;
111
+
112
+ export default class ColourPicker extends Component<ColourProps, IState> {
113
+ static defaultProps: DefaultProps = defaultProps;
114
+ constructor(props: ColourProps) {
115
+ super(props);
116
+ this.state = { ...this.props.value };
117
+ }
118
+
119
+ // eslint-disable-next-line react/no-deprecated
120
+ componentWillReceiveProps(nextProps: ColourProps) {
121
+ if (!_.isEqual(nextProps.value, this.props.value)) {
122
+ this.setState({ ...nextProps.value });
123
+ }
124
+ }
125
+
126
+ shouldComponentUpdate(nextProps: ColourProps, nextState: IState) {
127
+ return !_.isEqual(nextProps, this.props) || !_.isEqual(nextState, this.state);
128
+ }
129
+
130
+ onBrightGrant = () => {
131
+ const { hue, saturation, value } = this.state;
132
+ this.firPropsEvent(this.props.onGrant, { hue, saturation, value }, { isChangeBright: true });
133
+ };
134
+
135
+ onBrightMove = (value: number) => {
136
+ const { hue, saturation } = this.state;
137
+ this.firPropsEvent(this.props.onMove, { hue, saturation, value }, { isChangeBright: true });
138
+ };
139
+
140
+ onBrightRelease = (value: number) => {
141
+ const { hue, saturation } = this.state;
142
+ this.setState({ value });
143
+ this.firPropsEvent(this.props.onRelease, { hue, saturation, value }, { isChangeBright: true });
144
+ };
145
+
146
+ onBrightPress = (value: number) => {
147
+ const { hue, saturation } = this.state;
148
+ this.setState({ value });
149
+ this.firPropsEvent(this.props.onPress, { hue, saturation, value }, { isChangeBright: true });
150
+ };
151
+
152
+ coorToValue = ({ x, y }: Point, validBound: ValidBound) => {
153
+ const { hueOffset } = this.props;
154
+ const { width, height, x: validStartX, y: validStartY } = validBound;
155
+ const { value } = this.state;
156
+ let hue = Math.round(((x - validStartX) / width) * 360 + hueOffset) % 360;
157
+ const saturation = Math.round(((y - validStartY) / height) * 1000);
158
+
159
+ // hueOffset 不等于0时,最左边与最右边的值一样,为确保不会滑到最左边时跳到最右边
160
+ // 滑到最左边时,hue + 1;
161
+ if (hueOffset !== 0) {
162
+ if (Math.abs(x - validStartX) < 1) {
163
+ hue += 1;
164
+ }
165
+ }
166
+
167
+ return { hue, saturation, value };
168
+ };
169
+
170
+ valueToCoor = (hsv: IHsv, _origin: Point, validBound: ValidBound): Point => {
171
+ const { hueOffset } = this.props;
172
+ const { width, height, x: validStartX, y: validStartY } = validBound;
173
+ const { hue, saturation } = hsv;
174
+ let x = ((hue - hueOffset) / 360) * width;
175
+ if (x <= 0) {
176
+ x = width + x;
177
+ }
178
+ const y = (saturation / 1000) * height;
179
+
180
+ return { x: x + validStartX, y: y + validStartY };
181
+ };
182
+
183
+ valueToColor = (hsv: IHsv): string => {
184
+ const { hue, saturation, value } = hsv;
185
+ return ColorUtils.hsv2rgba(hue!, saturation, value) || 'transparent';
186
+ };
187
+
188
+ firPropsEvent(cb: (params?: any) => void, ...args: any[]) {
189
+ typeof cb === 'function' && cb(...args);
190
+ }
191
+
192
+ handlePickerGrant = () => {
193
+ const { hue, saturation, value } = this.state;
194
+ this.firPropsEvent(this.props.onGrant, { hue, saturation, value });
195
+ };
196
+
197
+ handlePickerMove = (hsv: IHsv) => {
198
+ this.firPropsEvent(this.props.onMove, hsv);
199
+ };
200
+
201
+ handlePickerRelease = (hsv: IHsv) => {
202
+ this.setState({ ...hsv });
203
+ this.firPropsEvent(this.props.onRelease, hsv);
204
+ };
205
+
206
+ handlePickerPress = (hsv: IHsv) => {
207
+ this.setState({ ...hsv });
208
+ this.firPropsEvent(this.props.onPress, hsv);
209
+ };
210
+
211
+ initData = async () => {};
212
+ render() {
213
+ const {
214
+ style,
215
+ rectStyle,
216
+ brightOption,
217
+ lossShow,
218
+ lossSliderColor,
219
+ clickEnabled,
220
+ hideBright,
221
+ opacityAnimationValue,
222
+ opacityAnimationDuration,
223
+ ...pickerProps
224
+ } = this.props;
225
+ const { hue, saturation, value: bright } = this.state;
226
+ const sliderProps: any = {};
227
+ if (lossShow) {
228
+ sliderProps.activeColor = lossSliderColor;
229
+ }
230
+ return (
231
+ <View style={[{ flex: 1 }, style]}>
232
+ <RectPicker
233
+ coorToValue={this.coorToValue}
234
+ valueToColor={this.valueToColor}
235
+ valueToCoor={this.valueToCoor}
236
+ value={{ hue, saturation, value: bright }}
237
+ lossShow={lossShow}
238
+ clickEnabled={clickEnabled}
239
+ opacityAnimationValue={opacityAnimationValue}
240
+ opacityAnimationDuration={opacityAnimationDuration}
241
+ {...pickerProps}
242
+ style={rectStyle}
243
+ onGrant={this.handlePickerGrant}
244
+ onMove={this.handlePickerMove}
245
+ onRelease={this.handlePickerRelease}
246
+ onPress={this.handlePickerPress}
247
+ initData={this.initData}
248
+ />
249
+ {!hideBright && (
250
+ <Slider
251
+ opacityAnimationValue={opacityAnimationValue}
252
+ opacityAnimationDuration={opacityAnimationDuration}
253
+ {...brightOption}
254
+ {...sliderProps}
255
+ value={bright}
256
+ clickEnabled={clickEnabled}
257
+ onGrant={this.onBrightGrant}
258
+ onMove={this.onBrightMove}
259
+ onRelease={this.onBrightRelease}
260
+ onPress={this.onBrightPress}
261
+ />
262
+ )}
263
+ </View>
264
+ );
265
+ }
266
+ }