@ledvance/base 1.1.73 → 1.1.75

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.1.73",
7
+ "version": "1.1.75",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
@@ -0,0 +1,121 @@
1
+ import { exchangeNumber, localeNumber } from "@ledvance/base/src/utils/common";
2
+ import res from "@res";
3
+ import { useReactive } from "ahooks";
4
+ import React, { memo, useCallback } from "react";
5
+ import { TouchableOpacity, View, Image, TextInput, StyleSheet, StyleProp, ViewStyle } from "react-native";
6
+ import { Utils } from "tuya-panel-kit";
7
+
8
+ const { add, subtract, inMaxMin} = Utils.NumberUtils
9
+
10
+ const { convertX: cx } = Utils.RatioUtils
11
+
12
+ export interface StepperProps {
13
+ value: number | string
14
+ stepValue?: number // 1
15
+ min?: number // 0
16
+ max?: number // 99
17
+ editable?: boolean
18
+ selectionColor?: string
19
+ onValueChange?: ((value: number) => void)
20
+ disabled?: boolean
21
+ style?: StyleProp<ViewStyle>
22
+ buttonStyle?: StyleProp<ViewStyle>
23
+ inputStyle?: StyleProp<ViewStyle>
24
+ }
25
+
26
+ const Stepper = (props: StepperProps) => {
27
+ const state = useReactive({
28
+ value: localeNumber(Number(props.value), 1) ?? 0,
29
+ stepValue: props.stepValue ?? 1,
30
+ min: props.min ?? 0,
31
+ max: props.max ?? 99
32
+ })
33
+
34
+ const handlePress = useCallback((isAdd: boolean) => {
35
+ const v = inMaxMin(state.min, state.max, isAdd ? add(Number(exchangeNumber(state.value)), state.stepValue) : subtract(Number(exchangeNumber(state.value)), state.stepValue))
36
+ state.value = localeNumber(v, 1)
37
+ props.onValueChange && props.onValueChange(v)
38
+ }, [])
39
+
40
+
41
+ const handleChangeText = useCallback((v: string) =>{
42
+ const newValue = exchangeNumber(v)
43
+ const idx = newValue.indexOf('.')
44
+ if(newValue[0] === '.' ||
45
+ (newValue.length === 2 && newValue[0] === '0' && newValue[1] !== '.') ||
46
+ newValue.split('').filter(item => item === '.').length > 1 ||
47
+ Number(newValue) > state.max || Number(newValue) < state.min ||
48
+ (idx !== -1 && newValue.length > idx + 2)){
49
+ return
50
+ }
51
+ state.value = v
52
+ }, [])
53
+
54
+ const handleEndText = useCallback(() =>{
55
+ if (typeof state.value === 'string' && !state.value.length) {
56
+ props.onValueChange && props.onValueChange(state.min)
57
+ state.value = state.min.toString()
58
+ }else{
59
+ props.onValueChange && props.onValueChange(Number(exchangeNumber(state.value)))
60
+ }
61
+
62
+ }, [])
63
+
64
+ return (
65
+ <View style={[styles.stepperContainer, props.style]}>
66
+ <TouchableOpacity
67
+ style={[styles.stepperButton, props.buttonStyle]}
68
+ onPress={() => handlePress(false)}
69
+ >
70
+ <Image width={cx(16)} height={cx(16)} source={res.ic_minus} />
71
+ </TouchableOpacity>
72
+ <TextInput
73
+ style={[styles.stepperInput, props.inputStyle]}
74
+ value={state.value.toString()}
75
+ keyboardType="numeric"
76
+ onChangeText={handleChangeText}
77
+ maxLength={4}
78
+ enablesReturnKeyAutomatically={true}
79
+ onEndEditing={handleEndText}
80
+ editable={props.editable || props.disabled}
81
+ />
82
+ <TouchableOpacity
83
+ style={[styles.stepperButton, props.buttonStyle]}
84
+ onPress={() => handlePress(true)}
85
+ >
86
+ <Image style={{ width: cx(20), height: cx(20) }} source={res.ic_plus} />
87
+ </TouchableOpacity>
88
+ </View>
89
+ )
90
+ }
91
+
92
+ const styles = StyleSheet.create({
93
+ stepperContainer: {
94
+ flexDirection: 'row',
95
+ alignItems: 'center',
96
+ backgroundColor: '#f5f5f5',
97
+ padding: cx(2),
98
+ borderRadius: cx(12),
99
+ width: cx(150),
100
+ },
101
+ stepperButton: {
102
+ width: cx(52),
103
+ height: cx(28),
104
+ backgroundColor: '#fff',
105
+ borderRadius: cx(10),
106
+ alignItems: 'center',
107
+ justifyContent: 'center',
108
+ },
109
+ stepperInput: {
110
+ width: cx(42),
111
+ height: cx(22),
112
+ color: '#333',
113
+ fontSize: cx(16),
114
+ padding: 0,
115
+ alignItems: 'center',
116
+ justifyContent: 'center',
117
+ textAlign: 'center',
118
+ }
119
+ })
120
+
121
+ export default memo(Stepper)
@@ -6,10 +6,11 @@ import {DevInfo, DpValue} from 'tuya-panel-kit'
6
6
  import {NativeApi} from '../../api/native'
7
7
  import {useDispatch} from 'react-redux'
8
8
  import {GlobalParams} from '../GlobalParams'
9
- import {snakeCase} from 'lodash'
9
+ import {isNumber, snakeCase} from 'lodash'
10
10
 
11
11
  export interface NativeProps {
12
12
  familyName: string
13
+ role: 0 | 1 | 2 | 3
13
14
  deviceInfo: DeviceInfo
14
15
  uaGroupInfo: UAGroupInfo
15
16
  timeSchedule?: boolean
@@ -31,6 +32,7 @@ export interface UAGroupInfo {
31
32
 
32
33
  const initialState: NativeProps = {
33
34
  familyName: '',
35
+ role: 2,
34
36
  deviceInfo: {
35
37
  devId: '',
36
38
  pId: '',
@@ -64,6 +66,9 @@ const nativePropsSlice = createSlice({
64
66
  if (!!action.payload.familyName) {
65
67
  state.familyName = action.payload.familyName
66
68
  }
69
+ if (isNumber(action.payload.role)) {
70
+ state.role = action.payload.role
71
+ }
67
72
  if (!!action.payload.deviceInfo.pId) {
68
73
  state.deviceInfo.pId = action.payload.deviceInfo.pId
69
74
  }
@@ -145,6 +150,10 @@ const useFamilyName: () => string = () => {
145
150
  return useSelector(store => store.ldvModules.familyName)
146
151
  }
147
152
 
153
+ const useRole: () => 0 | 1 | 2 | 3 = () => {
154
+ return useSelector(store => store.ldvModules.role)
155
+ }
156
+
148
157
  function useDp<T, R extends any>(dp: string): [T, (value: T) => Promise<Result<R>>] {
149
158
  const deviceId = useDeviceId()
150
159
  const dispatch = useDispatch()
@@ -281,6 +290,7 @@ export {
281
290
  useScaledDp,
282
291
  useDps,
283
292
  useFamilyName,
293
+ useRole,
284
294
  useTimeSchedule,
285
295
  useEnergieverbrauch,
286
296
  }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/src/res/index.ts CHANGED
@@ -61,5 +61,7 @@ export default {
61
61
  ic_colorize: require('./ic_colorize.png'),
62
62
  ic_mood_del: require('./ic_mood_del.png'),
63
63
  ic_paint_bucket: require('./ic_paint_bucket.png'),
64
- ic_text_field_input_error: require('./ic_text_field_input_error.png')
64
+ ic_text_field_input_error: require('./ic_text_field_input_error.png'),
65
+ ic_minus: require('./ic_minus.png'),
66
+ ic_plus: require('./ic_plus.png')
65
67
  }