@ledvance/base 1.3.81 → 1.3.82

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.
@@ -1,6 +1,6 @@
1
- import {Image, StyleSheet, Text, TouchableOpacity, View, ViewProps} from 'react-native'
1
+ import { Image, StyleSheet, Text, TouchableOpacity, View, ViewProps } from 'react-native'
2
2
  import React from 'react'
3
- import {Utils} from 'tuya-panel-kit'
3
+ import { Utils } from 'tuya-panel-kit'
4
4
  import res from '../res'
5
5
  import ThemeType from '../config/themeType'
6
6
 
@@ -49,17 +49,17 @@ const Tag = (props: TagProps) => {
49
49
  onPress={() => {
50
50
  props.onCheckedChange(!props.checked)
51
51
  }}>
52
- <View style={[styles.root, props.checked ? styles.checked : styles.uncheck, props.style]}>
53
- <Text
54
- accessibilityLabel={"Tag"}
55
- accessibilityHint={props.text}
56
- accessibilityState={{checked: props.checked}}
57
- style={[styles.text, {marginEnd: cx(props.checked ? 4 : 12)}]}
58
- >
52
+ <View
53
+ accessibilityLabel={"Tag"}
54
+ accessibilityHint={props.text}
55
+ accessibilityState={{ checked: props.checked }}
56
+ style={[styles.root, props.checked ? styles.checked : styles.uncheck, props.style]}
57
+ >
58
+ <Text style={[styles.text, { marginEnd: cx(props.checked ? 4 : 12) }]}>
59
59
  {props.text}
60
60
  </Text>
61
61
  {
62
- props.checked ? <Image source={{uri: res.ic_arrows_nav_clear}} style={styles.icon}/> : <></>
62
+ props.checked ? <Image accessibilityLabel='TagClearIcon' source={{ uri: res.ic_arrows_nav_clear }} style={styles.icon} /> : <></>
63
63
  }
64
64
  </View>
65
65
  </TouchableOpacity>
@@ -55,7 +55,7 @@ const UATabs = (props: UATabsProps) => {
55
55
 
56
56
  return <TouchableOpacity
57
57
  accessibilityLabel={"UATabs"}
58
- accessibilityHint={item.value}
58
+ accessibilityHint={`${item.value}`}
59
59
  accessibilityState={{checked: active}}
60
60
  key={index}
61
61
  style={{ flex: 1 }}
@@ -10,6 +10,7 @@ import RectPicker, {
10
10
  } from './RectPicker';
11
11
  import Slider, { IBrightOption } from './Slider';
12
12
  import ColorUtils from './utils/color';
13
+ import StorageUtils from './utils/storage';
13
14
 
14
15
  export interface IWhite {
15
16
  brightness: number;
@@ -52,20 +53,38 @@ const defaultProps = {
52
53
  onRelease(_v: any, _option?: { isChangeBright: boolean }) {},
53
54
  onPress(_v: any, _option?: { isChangeBright: boolean }) {},
54
55
  };
56
+
57
+ interface TempStorageData {
58
+ temperature: number;
59
+ position: Point;
60
+ }
61
+
55
62
  type DefaultProps = {
56
63
  style?: ViewStyle;
57
64
  rectStyle?: ViewStyle;
65
+ storageKey?: string;
58
66
  } & Readonly<typeof defaultProps>;
59
67
 
60
68
  type WhiteProps = DefaultProps;
61
69
 
70
+ let storageKeyIndex = 0;
71
+
62
72
  export default class WhitePicker extends Component<WhiteProps, IWhite> {
63
73
  static defaultProps = defaultProps;
64
74
 
65
75
  constructor(props: WhiteProps) {
66
76
  super(props);
67
- const { value: { brightness, temperature }, } = this.props;
77
+ // 是否定义了storageKey
78
+ const {
79
+ storageKey,
80
+ value: { brightness, temperature },
81
+ } = this.props;
68
82
  this.state = { brightness, temperature };
83
+ if (!storageKey) {
84
+ this.storageKey = `temperature_key_${storageKeyIndex++}`;
85
+ } else {
86
+ this.storageKey = storageKey;
87
+ }
69
88
  }
70
89
 
71
90
  componentDidUpdate(prevProps: WhiteProps) {
@@ -199,7 +218,26 @@ export default class WhitePicker extends Component<WhiteProps, IWhite> {
199
218
  }
200
219
 
201
220
  initData = async (validBound: ValidBound) => {
221
+ let cacheEnabled = true;
222
+ // 尺寸有变化时,不使用缓存
223
+ if (!_.isEqual(validBound, this.pickerBound)) {
224
+ cacheEnabled = false;
225
+ }
226
+
202
227
  const { temperature } = this.state;
228
+
229
+ // 获取当前positon的值
230
+ const data = (await StorageUtils.getDevItem(this.storageKey)) as TempStorageData;
231
+ // 是否相同色温,相同使用缓存坐标展示
232
+ if (data && data.temperature === temperature && cacheEnabled) {
233
+ this.thumbPosition = data.position;
234
+ this.currentTemperature = temperature;
235
+ } else {
236
+ // 根据色温计算位置
237
+ this.thumbPosition = this.autoTemperaturePosition(temperature, validBound);
238
+ this.currentTemperature = temperature;
239
+ }
240
+
203
241
  // 根据色温计算位置
204
242
  this.thumbPosition = this.autoTemperaturePosition(temperature, validBound);
205
243
  this.currentTemperature = temperature;
@@ -217,6 +255,8 @@ export default class WhitePicker extends Component<WhiteProps, IWhite> {
217
255
  validBound
218
256
  );
219
257
  }
258
+
259
+ StorageUtils.setDevItem(this.storageKey, { temperature, position });
220
260
  return position;
221
261
  }
222
262
 
@@ -242,6 +282,7 @@ export default class WhitePicker extends Component<WhiteProps, IWhite> {
242
282
  x: normal.x * length + normalVector.originX,
243
283
  y: normal.y * length + normalVector.originY,
244
284
  };
285
+ StorageUtils.setDevItem(this.storageKey, { temperature, position });
245
286
  return position;
246
287
  }
247
288
 
@@ -263,6 +304,11 @@ export default class WhitePicker extends Component<WhiteProps, IWhite> {
263
304
  }
264
305
  return this.handleTemperaturePosition(temperature, validBound);
265
306
  }
307
+
308
+ StorageUtils.setDevItem(this.storageKey, {
309
+ temperature,
310
+ position: origin,
311
+ });
266
312
  this.currentTemperature = temperature;
267
313
  this.thumbPosition = origin;
268
314
  return origin;
@@ -281,6 +327,7 @@ export default class WhitePicker extends Component<WhiteProps, IWhite> {
281
327
  private currentTemperature: number;
282
328
  private pickerRef: RectPicker | null;
283
329
  private pickerBound: ValidBound;
330
+ private storageKey: string;
284
331
 
285
332
  handlePickerGrant = () => {
286
333
  const { temperature, brightness } = this.state;
@@ -0,0 +1,97 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ import { AsyncStorage } from 'react-native';
3
+ import { TYSdk } from 'tuya-panel-kit';
4
+
5
+ const getDevKey = (name: string) => {
6
+ const { devId } = TYSdk.devInfo;
7
+ return `${devId}_${name}`;
8
+ };
9
+
10
+ const getPidKey = (name: string) => {
11
+ const { productId } = TYSdk.devInfo;
12
+ return `${productId}_${name}`;
13
+ };
14
+
15
+ const getUiKey = (name: string) => {
16
+ const { uiId } = TYSdk.devInfo;
17
+ return `${uiId}_${name}`;
18
+ };
19
+
20
+ export default {
21
+ async setItem(key: string, value: any) {
22
+ const data = { value, type: typeof value };
23
+ const jsonValue = JSON.stringify(data);
24
+ return new Promise((resolve, reject) => {
25
+ AsyncStorage.setItem(key, jsonValue, err => {
26
+ if (err) {
27
+ reject(err);
28
+ return;
29
+ }
30
+ resolve('');
31
+ });
32
+ });
33
+ },
34
+ async setDevItem(name: string, value: any) {
35
+ const key = getDevKey(name);
36
+ return this.setItem(key, value);
37
+ },
38
+ async setPidItem(name: string, value: any) {
39
+ const key = getPidKey(name);
40
+ return this.setItem(key, value);
41
+ },
42
+ async setUiItem(name: string, value: any) {
43
+ const key = getUiKey(name);
44
+ return this.setItem(key, value);
45
+ },
46
+ async getItem(key: string) {
47
+ return new Promise((resolve, reject) => {
48
+ AsyncStorage.getItem(key, (err, data) => {
49
+ if (err) {
50
+ reject(err);
51
+ return;
52
+ }
53
+ if (data) {
54
+ resolve(JSON.parse(data).value);
55
+ }
56
+ resolve(null);
57
+ });
58
+ });
59
+ },
60
+ async getDevItem(name: string) {
61
+ const key = getDevKey(name);
62
+ return this.getItem(key);
63
+ },
64
+ async getPidItem(name: string) {
65
+ const key = getPidKey(name);
66
+ return this.getItem(key);
67
+ },
68
+ async getUiItem(name: string) {
69
+ const key = getUiKey(name);
70
+ return this.getItem(key);
71
+ },
72
+ async removeItem(key: string) {
73
+ return new Promise((resolve, reject) => {
74
+ AsyncStorage.removeItem(key, err => {
75
+ if (err) {
76
+ reject(err);
77
+ return;
78
+ }
79
+ resolve('');
80
+ });
81
+ });
82
+ },
83
+
84
+ async removeDevItem(name: string) {
85
+ const key = getDevKey(name);
86
+ return this.removeItem(key);
87
+ },
88
+
89
+ async removePidItem(name: string) {
90
+ const key = getDevKey(name);
91
+ return this.removeItem(key);
92
+ },
93
+ async removeUiItem(name: string) {
94
+ const key = getUiKey(name);
95
+ return this.removeItem(key);
96
+ },
97
+ };