@ledvance/base 1.1.83 → 1.1.84

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.83",
7
+ "version": "1.1.84",
8
8
  "scripts": {},
9
9
  "dependencies": {
10
10
  "@reduxjs/toolkit": "^1.8.6",
@@ -9,7 +9,7 @@ import {
9
9
  import {actions} from '@models'
10
10
 
11
11
  const nativeModule = NativeModules.LDVDeviceEventEmitter
12
- const nativeEventEmitter = new NativeEventEmitter(nativeModule)
12
+ export const nativeEventEmitter = new NativeEventEmitter(nativeModule)
13
13
 
14
14
  let deviceDPListener: EmitterSubscription | null
15
15
  let groupFeatureListener: EmitterSubscription | null
@@ -0,0 +1,225 @@
1
+ import React, { useMemo, useEffect, useCallback } from 'react'
2
+ import { View, Text, StyleSheet, TouchableOpacity, Image } from 'react-native'
3
+ import { Utils, Modal } from 'tuya-panel-kit'
4
+ import { useReactive } from "ahooks"
5
+ import Card from "@ledvance/base/src/components/Card"
6
+ import res from '@ledvance/base/src/res'
7
+ import I18n from '@ledvance/base/src/i18n'
8
+ import LdvSwitch from '@ledvance/base/src/components/ldvSwitch'
9
+ import LampAdjustView from '@ledvance/base/src/components/LampAdjustView'
10
+ import { hsv2Hex, mapFloatToRange } from '@ledvance/base/src/utils'
11
+ import Spacer from "@ledvance/base/src/components/Spacer"
12
+ import DeleteButton from "@ledvance/base/src/components/DeleteButton"
13
+ import Stepper from '@ledvance/base/src/components/Stepper'
14
+ const { convertX: cx } = Utils.RatioUtils
15
+ import StripLightView from './StripLightView'
16
+ import { nativeEventEmitter} from '@ledvance/base/src/api/nativeEventEmitter'
17
+
18
+ export type Node = {
19
+ color: string,
20
+ backgroundColor?: string
21
+ }
22
+
23
+ interface DrawToolViewProps {
24
+ switchLed?: boolean
25
+ showEnable?: boolean
26
+ setEnable: (enable: boolean) => void
27
+ adjustType?: number // 1 全选, 2 单选, 3 擦除
28
+ setAdjustType: (type: number) => void
29
+ stripStyle?: 'ONLY_LINE' | 'WITH_BEAD'
30
+ nodes: Node[]
31
+ fixCount?: number
32
+ nodeTouch: (idx: number) => void
33
+ fingerUp: (idxList: string) => void
34
+ hideLightView?: boolean
35
+ isSupportColor?: boolean
36
+ isSupportTemperature?: boolean
37
+ isSupportBrightness?: boolean
38
+ isColorMode?: boolean
39
+ setIsColorMode: (isColorMode: boolean) => void
40
+ h: number
41
+ s: number
42
+ v: number
43
+ onHSVChange: (h: number, s: number, v: number) => void
44
+ onHSVChangeComplete: (h: number, s: number, v: number) => void
45
+ temperature: number
46
+ brightness: number
47
+ onCCTChange: (cct: number) => void
48
+ onCCTChangeComplete: (cct: number) => void
49
+ onBrightnessChange: (brightness: number) => void
50
+ onBrightnessChangeComplete: (brightness: number) => void
51
+ hideLedNum?: boolean
52
+ ledNum?: number
53
+ setLedNum: (num: number) => void
54
+ }
55
+ const DrawToolView = (props: DrawToolViewProps) => {
56
+ const state = useReactive({
57
+ visible: false,
58
+ ledNum: props.ledNum || 5,
59
+ width: 0
60
+ })
61
+
62
+ useEffect(() => {
63
+ const fingerUp = nativeEventEmitter.addListener('onFingerUp', props.fingerUp)
64
+
65
+ const nodeTouched = nativeEventEmitter.addListener('onNodeTouched', props.nodeTouch)
66
+ return () => {
67
+ fingerUp.remove()
68
+ nodeTouched.remove()
69
+ }
70
+ }, [])
71
+
72
+ const onLayout = (event) => {
73
+ const { width } = event.nativeEvent.layout
74
+ state.width = width
75
+ }
76
+
77
+ const height = useMemo(() => {
78
+ return cx(52 * Math.ceil((props.nodes.length / (props.fixCount || 5))))
79
+ }, [props.nodes])
80
+
81
+ const getBlockColor = useCallback(() => {
82
+ if (props.isColorMode) {
83
+ const s = Math.round(mapFloatToRange(props.s / 100, 30, 100))
84
+ return hsv2Hex(props.h, s, 100)
85
+ }
86
+ return '#ffffff'
87
+ }, [props.isColorMode, props.h, props.s])
88
+
89
+ return <Card style={{ marginHorizontal: cx(24) }}>
90
+ <LdvSwitch
91
+ title={I18n.getLang('light_sources_tile_tw_lighting_headline')}
92
+ color={'#fff'}
93
+ colorAlpha={1}
94
+ enable={!!props.switchLed}
95
+ showSwitch={!!props.showEnable}
96
+ setEnable={props.setEnable}
97
+ />
98
+ {(props.showEnable && props.switchLed || !props.showEnable) && <>
99
+ <View style={styles.container}>
100
+ <View style={styles.adjustButtons}>
101
+ <TouchableOpacity
102
+ onPress={() => {
103
+ props.setAdjustType(1)
104
+ }}>
105
+ <Image
106
+ style={[styles.adjustButton, { tintColor: props.adjustType === 1 ? '#f60' : '#666' }]}
107
+ source={res.ic_paint_bucket} />
108
+ </TouchableOpacity>
109
+ <TouchableOpacity
110
+ onPress={() => {
111
+ props.setAdjustType(3)
112
+ }}>
113
+ <Image
114
+ style={[styles.adjustButton, { tintColor: props.adjustType === 3 ? '#f60' : '#666' }]}
115
+ source={res.ic_disabled_light} />
116
+ </TouchableOpacity>
117
+ <TouchableOpacity
118
+ onPress={() => {
119
+ props.setAdjustType(2)
120
+ }}>
121
+ <Image
122
+ style={[styles.adjustButton, { tintColor: props.adjustType === 2 ? '#f60' : '#666' }]}
123
+ source={res.ic_colorize} />
124
+ </TouchableOpacity>
125
+ {!props.hideLedNum && <TouchableOpacity
126
+ onPress={() => {
127
+ state.visible = true
128
+ }}
129
+ style={[styles.adjustButton, { alignItems: 'center', justifyContent: 'center', backgroundColor: '#f60', borderRadius: cx(5) }]}>
130
+ <Text style={{ color: '#fff', fontSize: cx(18), fontWeight: 'bold' }}>{props.ledNum || 5}</Text>
131
+ </TouchableOpacity>}
132
+ </View>
133
+ <StripLightView
134
+ style={{ height, flex: 1 }}
135
+ nodes={JSON.stringify(props.nodes)}
136
+ fixCount={props.fixCount || 5}
137
+ stripStyle={props.stripStyle || 'WITH_BEAD'}
138
+ width={state.width}
139
+ onLayout={onLayout}
140
+ />
141
+ </View>
142
+ <LdvSwitch
143
+ title={I18n.getLang('add_new_dynamic_mood_lights_field_headline2_text')}
144
+ color={getBlockColor()}
145
+ colorAlpha={1}
146
+ enable={false}
147
+ showSwitch={false}
148
+ setEnable={() => { }}
149
+ />
150
+ <LampAdjustView
151
+ isSupportColor={!!props.isSupportColor}
152
+ isSupportTemperature={!!props.isSupportTemperature}
153
+ isSupportBrightness={!!props.isSupportBrightness}
154
+ isColorMode={!!props.isColorMode}
155
+ reserveSV={true}
156
+ setIsColorMode={props.setIsColorMode}
157
+ h={props.h} s={props.s} v={props.v}
158
+ onHSVChange={props.onHSVChange}
159
+ onHSVChangeComplete={props.onHSVChangeComplete}
160
+ colorTemp={props.temperature}
161
+ brightness={props.brightness}
162
+ onCCTChange={props.onCCTChange}
163
+ onCCTChangeComplete={props.onCCTChangeComplete}
164
+ onBrightnessChange={props.onBrightnessChange}
165
+ onBrightnessChangeComplete={props.onBrightnessChangeComplete} />
166
+ {!props.hideLedNum && <Modal
167
+ visible={state.visible}
168
+ onMaskPress={() => {
169
+ state.visible = false
170
+ }}
171
+ alignContainer='center'
172
+ style={{ width: '100%', height: cx(100) }}
173
+ >
174
+ <Card style={{ marginHorizontal: cx(24), marginTop: cx(50), alignItems: 'center' }}>
175
+ <Spacer />
176
+ <Stepper
177
+ min={5}
178
+ max={48}
179
+ stepValue={1}
180
+ editable={true}
181
+ value={state.ledNum}
182
+ onValueChange={(v) => {
183
+ state.ledNum = v
184
+ }}
185
+ />
186
+ <Spacer />
187
+ <DeleteButton
188
+ text={I18n.getLang('auto_scan_system_wifi_confirm')}
189
+ style={{ width: cx(150), height: cx(40), backgroundColor: '#f60' }}
190
+ textStyle={{ fontSize: cx(14) }}
191
+ onPress={() => {
192
+ props.setLedNum(state.ledNum)
193
+ state.visible = false
194
+ }}
195
+ />
196
+ <Spacer />
197
+ </Card>
198
+ </Modal>}
199
+ </>}
200
+ </Card>
201
+ }
202
+
203
+ const styles = StyleSheet.create({
204
+ container: {
205
+ paddingLeft: cx(10),
206
+ flexDirection: 'row',
207
+ alignItems: 'center'
208
+ },
209
+ title: {
210
+ color: '#000',
211
+ fontSize: cx(16),
212
+ marginLeft: cx(10),
213
+ fontFamily: 'helvetica_neue_lt_std_bd',
214
+ fontWeight: 'bold',
215
+ },
216
+ adjustButtons: {
217
+ width: cx(50)
218
+ },
219
+ adjustButton: {
220
+ width: cx(44),
221
+ height: cx(44)
222
+ }
223
+ })
224
+
225
+ export default DrawToolView
@@ -0,0 +1,4 @@
1
+ import { requireNativeComponent } from 'react-native'
2
+ const StripLightView = requireNativeComponent('StripLightView');
3
+
4
+ export default StripLightView