@mpxjs/webpack-plugin 2.9.62 → 2.9.64
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/lib/index.js +1 -3
- package/lib/platform/style/wx/index.js +67 -53
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +12 -7
- package/lib/runtime/components/react/context.ts +9 -7
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +12 -1
- package/lib/runtime/components/react/dist/mpx-button.jsx +52 -74
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +19 -18
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +28 -41
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -14
- package/lib/runtime/components/react/dist/mpx-icon.jsx +14 -17
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +34 -33
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +35 -31
- package/lib/runtime/components/react/dist/mpx-label.jsx +29 -37
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -18
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +8 -8
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +9 -9
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +7 -4
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +11 -7
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +18 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +102 -10
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +147 -53
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +19 -18
- package/lib/runtime/components/react/dist/mpx-radio.jsx +28 -43
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +33 -26
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +139 -74
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +14 -6
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +19 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +17 -14
- package/lib/runtime/components/react/dist/mpx-text.jsx +19 -35
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +284 -209
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +8 -5
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/utils.jsx +433 -0
- package/lib/runtime/components/react/getInnerListeners.ts +18 -8
- package/lib/runtime/components/react/mpx-button.tsx +81 -91
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +48 -43
- package/lib/runtime/components/react/mpx-checkbox.tsx +52 -63
- package/lib/runtime/components/react/mpx-form.tsx +49 -21
- package/lib/runtime/components/react/mpx-icon.tsx +30 -27
- package/lib/runtime/components/react/mpx-image/index.tsx +52 -46
- package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
- package/lib/runtime/components/react/mpx-input.tsx +58 -38
- package/lib/runtime/components/react/mpx-label.tsx +54 -59
- package/lib/runtime/components/react/mpx-movable-area.tsx +38 -24
- package/lib/runtime/components/react/mpx-movable-view.tsx +27 -28
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
- package/lib/runtime/components/react/mpx-picker/date.tsx +2 -3
- package/lib/runtime/components/react/mpx-picker/index.tsx +10 -10
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +15 -12
- package/lib/runtime/components/react/mpx-picker/region.tsx +21 -18
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -6
- package/lib/runtime/components/react/mpx-picker/time.tsx +25 -29
- package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +148 -20
- package/lib/runtime/components/react/mpx-picker-view.tsx +179 -63
- package/lib/runtime/components/react/mpx-radio-group.tsx +50 -47
- package/lib/runtime/components/react/mpx-radio.tsx +56 -72
- package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +133 -103
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +174 -96
- package/lib/runtime/components/react/mpx-swiper/index.tsx +18 -9
- package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +46 -13
- package/lib/runtime/components/react/mpx-switch.tsx +44 -23
- package/lib/runtime/components/react/mpx-text.tsx +37 -45
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +388 -240
- package/lib/runtime/components/react/mpx-web-view.tsx +19 -20
- package/lib/runtime/components/react/parser.ts +245 -0
- package/lib/runtime/components/react/types/common.ts +4 -4
- package/lib/runtime/components/react/types/global.d.ts +14 -2
- package/lib/runtime/components/react/useNodesRef.ts +1 -2
- package/lib/runtime/components/react/utils.tsx +505 -0
- package/lib/template-compiler/compiler.js +28 -20
- package/lib/template-compiler/gen-node-react.js +1 -3
- package/lib/web/processStyles.js +2 -5
- package/package.json +6 -4
- package/lib/runtime/components/react/dist/utils.js +0 -148
- package/lib/runtime/components/react/utils.ts +0 -170
|
@@ -54,7 +54,8 @@ import {
|
|
|
54
54
|
TextInputChangeEventData,
|
|
55
55
|
TextInputSubmitEditingEventData
|
|
56
56
|
} from 'react-native'
|
|
57
|
-
import {
|
|
57
|
+
import { warn } from '@mpxjs/utils'
|
|
58
|
+
import { parseInlineStyle, useUpdateEffect, useTransformStyle, useLayout } from './utils'
|
|
58
59
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
59
60
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
60
61
|
import { FormContext, FormFieldValue } from './context'
|
|
@@ -72,6 +73,7 @@ type InputStyle = Omit<
|
|
|
72
73
|
>
|
|
73
74
|
|
|
74
75
|
type Type = 'text' | 'number' | 'idcard' | 'digit'
|
|
76
|
+
|
|
75
77
|
export interface InputProps {
|
|
76
78
|
name?: string
|
|
77
79
|
style?: InputStyle & Record<string, any>
|
|
@@ -91,6 +93,11 @@ export interface InputProps {
|
|
|
91
93
|
'selection-end'?: number
|
|
92
94
|
'placeholder-style'?: string
|
|
93
95
|
'enable-offset'?: boolean,
|
|
96
|
+
'enable-var'?: boolean
|
|
97
|
+
'external-var-context'?: Record<string, any>
|
|
98
|
+
'parent-font-size'?: number
|
|
99
|
+
'parent-width'?: number
|
|
100
|
+
'parent-height'?: number
|
|
94
101
|
bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
|
|
95
102
|
bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
|
|
96
103
|
bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
|
|
@@ -113,8 +120,8 @@ const keyboardTypeMap: Record<Type, string> = {
|
|
|
113
120
|
digit:
|
|
114
121
|
Platform.select({
|
|
115
122
|
ios: 'decimal-pad',
|
|
116
|
-
android: 'numeric'
|
|
117
|
-
}) || ''
|
|
123
|
+
android: 'numeric'
|
|
124
|
+
}) || ''
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps>((props: FinalInputProps, ref): JSX.Element => {
|
|
@@ -134,7 +141,11 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
134
141
|
'cursor-color': cursorColor,
|
|
135
142
|
'selection-start': selectionStart = -1,
|
|
136
143
|
'selection-end': selectionEnd = -1,
|
|
137
|
-
'enable-
|
|
144
|
+
'enable-var': enableVar,
|
|
145
|
+
'external-var-context': externalVarContext,
|
|
146
|
+
'parent-font-size': parentFontSize,
|
|
147
|
+
'parent-width': parentWidth,
|
|
148
|
+
'parent-height': parentHeight,
|
|
138
149
|
bindinput,
|
|
139
150
|
bindfocus,
|
|
140
151
|
bindblur,
|
|
@@ -143,7 +154,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
143
154
|
// private
|
|
144
155
|
multiline,
|
|
145
156
|
'auto-height': autoHeight,
|
|
146
|
-
bindlinechange
|
|
157
|
+
bindlinechange
|
|
147
158
|
} = props
|
|
148
159
|
|
|
149
160
|
const formContext = useContext(FormContext)
|
|
@@ -154,14 +165,11 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
154
165
|
formValuesMap = formContext.formValuesMap
|
|
155
166
|
}
|
|
156
167
|
|
|
157
|
-
const { nodeRef } = useNodesRef(props, ref)
|
|
158
|
-
|
|
159
168
|
const keyboardType = keyboardTypeMap[type]
|
|
160
169
|
const defaultValue = type === 'number' && value ? value + '' : value
|
|
161
170
|
const placeholderTextColor = parseInlineStyle(placeholderStyle)?.color
|
|
162
171
|
const textAlignVertical = multiline ? 'top' : 'auto'
|
|
163
172
|
|
|
164
|
-
const layoutRef = useRef({})
|
|
165
173
|
const tmpValue = useRef<string>()
|
|
166
174
|
const cursorIndex = useRef<number>(0)
|
|
167
175
|
const lineCount = useRef<number>(0)
|
|
@@ -169,6 +177,25 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
169
177
|
const [inputValue, setInputValue] = useState(defaultValue)
|
|
170
178
|
const [contentHeight, setContentHeight] = useState(0)
|
|
171
179
|
|
|
180
|
+
const styleObj = {
|
|
181
|
+
padding: 0,
|
|
182
|
+
...style,
|
|
183
|
+
...multiline && autoHeight && {
|
|
184
|
+
height: Math.max((style as any)?.minHeight || 35, contentHeight)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const {
|
|
189
|
+
hasSelfPercent,
|
|
190
|
+
normalStyle,
|
|
191
|
+
setWidth,
|
|
192
|
+
setHeight
|
|
193
|
+
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
194
|
+
|
|
195
|
+
const { nodeRef } = useNodesRef(props, ref)
|
|
196
|
+
|
|
197
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
198
|
+
|
|
172
199
|
useEffect(() => {
|
|
173
200
|
if (inputValue !== value) {
|
|
174
201
|
setInputValue(value)
|
|
@@ -187,7 +214,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
187
214
|
if (!bindinput && !bindblur) return
|
|
188
215
|
const {
|
|
189
216
|
range: { start, end },
|
|
190
|
-
text
|
|
217
|
+
text
|
|
191
218
|
} = nativeEvent
|
|
192
219
|
cursorIndex.current = start < end ? start : start + text.length
|
|
193
220
|
}
|
|
@@ -202,7 +229,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
202
229
|
{
|
|
203
230
|
detail: {
|
|
204
231
|
value: evt.nativeEvent.text,
|
|
205
|
-
cursor: cursorIndex.current
|
|
232
|
+
cursor: cursorIndex.current
|
|
206
233
|
},
|
|
207
234
|
layoutRef
|
|
208
235
|
},
|
|
@@ -225,7 +252,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
225
252
|
evt,
|
|
226
253
|
{
|
|
227
254
|
detail: {
|
|
228
|
-
value: tmpValue.current || ''
|
|
255
|
+
value: tmpValue.current || ''
|
|
229
256
|
},
|
|
230
257
|
layoutRef
|
|
231
258
|
},
|
|
@@ -243,7 +270,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
243
270
|
{
|
|
244
271
|
detail: {
|
|
245
272
|
value: tmpValue.current || '',
|
|
246
|
-
cursor: cursorIndex.current
|
|
273
|
+
cursor: cursorIndex.current
|
|
247
274
|
},
|
|
248
275
|
layoutRef
|
|
249
276
|
},
|
|
@@ -261,7 +288,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
261
288
|
evt,
|
|
262
289
|
{
|
|
263
290
|
detail: {
|
|
264
|
-
value: tmpValue.current || ''
|
|
291
|
+
value: tmpValue.current || ''
|
|
265
292
|
},
|
|
266
293
|
layoutRef
|
|
267
294
|
},
|
|
@@ -279,7 +306,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
279
306
|
evt,
|
|
280
307
|
{
|
|
281
308
|
detail: {
|
|
282
|
-
value: tmpValue.current || ''
|
|
309
|
+
value: tmpValue.current || ''
|
|
283
310
|
},
|
|
284
311
|
layoutRef
|
|
285
312
|
},
|
|
@@ -303,7 +330,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
303
330
|
detail: {
|
|
304
331
|
height,
|
|
305
332
|
lineHeight,
|
|
306
|
-
lineCount: lineCount.current
|
|
333
|
+
lineCount: lineCount.current
|
|
307
334
|
},
|
|
308
335
|
layoutRef
|
|
309
336
|
},
|
|
@@ -323,7 +350,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
323
350
|
{
|
|
324
351
|
detail: {
|
|
325
352
|
selectionStart: evt.nativeEvent.selection.start,
|
|
326
|
-
selectionEnd: evt.nativeEvent.selection.end
|
|
353
|
+
selectionEnd: evt.nativeEvent.selection.end
|
|
327
354
|
},
|
|
328
355
|
layoutRef
|
|
329
356
|
},
|
|
@@ -332,12 +359,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
332
359
|
)
|
|
333
360
|
}
|
|
334
361
|
|
|
335
|
-
const onLayout = () => {
|
|
336
|
-
nodeRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
337
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
|
|
338
|
-
})
|
|
339
|
-
}
|
|
340
|
-
|
|
341
362
|
const resetValue = () => {
|
|
342
363
|
setInputValue('')
|
|
343
364
|
}
|
|
@@ -348,7 +369,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
348
369
|
|
|
349
370
|
if (formValuesMap) {
|
|
350
371
|
if (!props.name) {
|
|
351
|
-
|
|
372
|
+
warn('If a form component is used, the name attribute is required.')
|
|
352
373
|
} else {
|
|
353
374
|
formValuesMap.set(props.name, { getValue, resetValue })
|
|
354
375
|
}
|
|
@@ -363,16 +384,23 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
363
384
|
: (nodeRef.current as TextInput)?.blur()
|
|
364
385
|
}, [focus])
|
|
365
386
|
|
|
387
|
+
const composeStyle = { ...normalStyle, ...layoutStyle }
|
|
388
|
+
|
|
366
389
|
const innerProps = useInnerProps(props, {
|
|
367
390
|
ref: nodeRef,
|
|
368
|
-
|
|
391
|
+
style: {
|
|
392
|
+
padding: 0,
|
|
393
|
+
...composeStyle,
|
|
394
|
+
...multiline && autoHeight && {
|
|
395
|
+
height: Math.max((composeStyle as any)?.minHeight || 35, contentHeight)
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
...layoutProps
|
|
369
399
|
},
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
layoutRef
|
|
375
|
-
})
|
|
400
|
+
[],
|
|
401
|
+
{
|
|
402
|
+
layoutRef
|
|
403
|
+
})
|
|
376
404
|
|
|
377
405
|
return (
|
|
378
406
|
<TextInput
|
|
@@ -400,14 +428,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
400
428
|
onSubmitEditing={onSubmitEditing}
|
|
401
429
|
onContentSizeChange={onContentSizeChange}
|
|
402
430
|
onSelectionChange={onSelectionChange}
|
|
403
|
-
style={{
|
|
404
|
-
padding: 0,
|
|
405
|
-
...style,
|
|
406
|
-
...multiline && autoHeight && {
|
|
407
|
-
height: Math.max((style as any)?.minHeight || 35, contentHeight)
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
431
|
/>
|
|
412
432
|
)
|
|
413
433
|
})
|
|
@@ -2,101 +2,86 @@
|
|
|
2
2
|
* ✘ for
|
|
3
3
|
*/
|
|
4
4
|
import { JSX, useRef, forwardRef, ReactNode } from 'react'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
Text,
|
|
8
|
-
ViewStyle,
|
|
9
|
-
NativeSyntheticEvent,
|
|
10
|
-
TextStyle,
|
|
11
|
-
} from 'react-native'
|
|
5
|
+
import { View, ViewStyle, NativeSyntheticEvent } from 'react-native'
|
|
6
|
+
import { noop, warn } from '@mpxjs/utils'
|
|
12
7
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
13
8
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
14
|
-
import {
|
|
9
|
+
import { splitProps, splitStyle, useLayout, useTransformStyle, wrapChildren } from './utils'
|
|
15
10
|
import { LabelContext, LabelContextValue } from './context'
|
|
16
11
|
|
|
17
12
|
export interface LabelProps {
|
|
18
13
|
for?: string
|
|
19
14
|
style?: ViewStyle & Record<string, any>
|
|
20
15
|
'enable-offset'?: boolean
|
|
16
|
+
'enable-var'?: boolean
|
|
17
|
+
'external-var-context'?: Record<string, any>
|
|
18
|
+
'parent-font-size'?: number
|
|
19
|
+
'parent-width'?: number
|
|
20
|
+
'parent-height'?: number
|
|
21
21
|
children: ReactNode
|
|
22
22
|
bindtap?: (evt: NativeSyntheticEvent<TouchEvent> | unknown) => void
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
26
|
-
(
|
|
26
|
+
(labelProps, ref): JSX.Element => {
|
|
27
|
+
const { textProps, innerProps: props = {} } = splitProps(labelProps)
|
|
28
|
+
|
|
27
29
|
const {
|
|
28
30
|
style = {},
|
|
29
|
-
'enable-
|
|
30
|
-
|
|
31
|
+
'enable-var': enableVar,
|
|
32
|
+
'external-var-context': externalVarContext,
|
|
33
|
+
'parent-font-size': parentFontSize,
|
|
34
|
+
'parent-width': parentWidth,
|
|
35
|
+
'parent-height': parentHeight,
|
|
31
36
|
bindtap
|
|
32
37
|
} = props
|
|
33
38
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
if (imageStyle) {
|
|
37
|
-
throwReactWarning('[Mpx runtime warn]: Label does not support background image-related styles!')
|
|
39
|
+
const defaultStyle = {
|
|
40
|
+
flexDirection: 'row'
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
const
|
|
41
|
-
|
|
43
|
+
const styleObj = {
|
|
44
|
+
...defaultStyle,
|
|
45
|
+
...style
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
const {
|
|
49
|
+
hasSelfPercent,
|
|
50
|
+
normalStyle,
|
|
51
|
+
hasVarDec,
|
|
52
|
+
varContextRef,
|
|
53
|
+
setWidth,
|
|
54
|
+
setHeight
|
|
55
|
+
} = useTransformStyle(styleObj, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
47
56
|
|
|
48
|
-
const
|
|
57
|
+
const { nodeRef } = useNodesRef(props, ref, { defaultStyle })
|
|
49
58
|
|
|
50
|
-
const {
|
|
51
|
-
defaultStyle
|
|
52
|
-
})
|
|
59
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
53
60
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
y: number,
|
|
59
|
-
width: number,
|
|
60
|
-
height: number,
|
|
61
|
-
offsetLeft: number,
|
|
62
|
-
offsetTop: number
|
|
63
|
-
) => {
|
|
64
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
|
|
65
|
-
}
|
|
66
|
-
)
|
|
61
|
+
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
|
|
62
|
+
|
|
63
|
+
if (backgroundStyle) {
|
|
64
|
+
warn('Label does not support background image-related styles!')
|
|
67
65
|
}
|
|
68
66
|
|
|
67
|
+
const contextRef: LabelContextValue = useRef({
|
|
68
|
+
triggerChange: noop
|
|
69
|
+
})
|
|
70
|
+
|
|
69
71
|
const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
70
72
|
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
|
|
71
73
|
contextRef.current.triggerChange?.(evt)
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
const wrapChildren = (
|
|
75
|
-
children: ReactNode,
|
|
76
|
-
textStyle?: TextStyle
|
|
77
|
-
) => {
|
|
78
|
-
const { textProps } = splitProps(props)
|
|
79
|
-
|
|
80
|
-
if (every(children, (child) => isText(child))) {
|
|
81
|
-
if (textStyle || textProps) {
|
|
82
|
-
children = <Text key='labelTextWrap' style={textStyle || {}} {...(textProps || {})}>{children}</Text>
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
if (textStyle) throwReactWarning('[Mpx runtime warn]: Text style will be ignored unless every child of the Label is Text node!')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return children
|
|
89
|
-
}
|
|
90
|
-
|
|
91
76
|
const innerProps = useInnerProps(
|
|
92
77
|
props,
|
|
93
78
|
{
|
|
94
79
|
ref: nodeRef,
|
|
95
|
-
style: { ...
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
81
|
+
...layoutProps,
|
|
82
|
+
bindtap: onTap
|
|
98
83
|
},
|
|
99
|
-
[
|
|
84
|
+
[],
|
|
100
85
|
{
|
|
101
86
|
layoutRef
|
|
102
87
|
}
|
|
@@ -104,7 +89,17 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
|
104
89
|
|
|
105
90
|
return <View {...innerProps}>
|
|
106
91
|
<LabelContext.Provider value={contextRef}>
|
|
107
|
-
{
|
|
92
|
+
{
|
|
93
|
+
wrapChildren(
|
|
94
|
+
props,
|
|
95
|
+
{
|
|
96
|
+
hasVarDec,
|
|
97
|
+
varContext: varContextRef.current,
|
|
98
|
+
textStyle,
|
|
99
|
+
textProps
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
}
|
|
108
103
|
</LabelContext.Provider>
|
|
109
104
|
</View>
|
|
110
105
|
}
|
|
@@ -3,65 +3,79 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { View, LayoutChangeEvent } from 'react-native'
|
|
6
|
-
import { JSX, useState, useEffect,
|
|
6
|
+
import { JSX, useState, useEffect, forwardRef, ReactNode } from 'react'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
8
8
|
import useInnerProps from './getInnerListeners'
|
|
9
9
|
import { MovableAreaContext } from './context'
|
|
10
|
+
import { useTransformStyle, wrapChildren, useLayout } from './utils'
|
|
10
11
|
|
|
11
12
|
interface MovableAreaProps {
|
|
12
13
|
style?: Record<string, any>;
|
|
13
14
|
children: ReactNode;
|
|
14
15
|
width?: number;
|
|
15
16
|
height?: number;
|
|
17
|
+
'enable-offset'?: boolean;
|
|
18
|
+
'enable-var'?: boolean
|
|
19
|
+
'external-var-context'?: Record<string, any>;
|
|
20
|
+
'parent-font-size'?: number;
|
|
21
|
+
'parent-width'?: number;
|
|
22
|
+
'parent-height'?: number;
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaProps>((props: MovableAreaProps, ref): JSX.Element => {
|
|
19
|
-
const {
|
|
20
|
-
const [areaWidth, setAreaWidth] = useState(0)
|
|
21
|
-
const [areaHeight, setAreaHeight] = useState(0)
|
|
22
|
-
|
|
23
|
-
const layoutRef = useRef<any>({})
|
|
26
|
+
const { style = {}, width = 10, height = 10, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props
|
|
27
|
+
const [areaWidth, setAreaWidth] = useState(0)
|
|
28
|
+
const [areaHeight, setAreaHeight] = useState(0)
|
|
24
29
|
|
|
25
30
|
useEffect(() => {
|
|
26
31
|
setAreaWidth(width)
|
|
27
32
|
setAreaHeight(height)
|
|
28
33
|
}, [width, height])
|
|
29
34
|
|
|
35
|
+
const {
|
|
36
|
+
hasSelfPercent,
|
|
37
|
+
normalStyle,
|
|
38
|
+
hasVarDec,
|
|
39
|
+
varContextRef,
|
|
40
|
+
setWidth,
|
|
41
|
+
setHeight
|
|
42
|
+
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
43
|
+
|
|
30
44
|
const { nodeRef: movableViewRef } = useNodesRef(props, ref)
|
|
31
45
|
|
|
32
46
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
33
47
|
const { width = 10, height = 10 } = e.nativeEvent.layout
|
|
34
48
|
setAreaWidth(width)
|
|
35
49
|
setAreaHeight(height)
|
|
36
|
-
movableViewRef.current?.measure((x: number, y: number, width: number, height: number, offsetLeft: number, offsetTop: number) => {
|
|
37
|
-
layoutRef.current = { x, y, width, height, offsetLeft, offsetTop }
|
|
38
|
-
})
|
|
39
50
|
}
|
|
51
|
+
|
|
52
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef, onLayout })
|
|
53
|
+
|
|
40
54
|
const innerProps = useInnerProps(props, {
|
|
55
|
+
style: { height: areaHeight, width: areaWidth, overflow: 'hidden', ...normalStyle, ...layoutStyle },
|
|
41
56
|
ref: movableViewRef,
|
|
42
|
-
|
|
43
|
-
}, [
|
|
44
|
-
'children',
|
|
45
|
-
'style',
|
|
46
|
-
], { layoutRef })
|
|
57
|
+
...layoutProps
|
|
58
|
+
}, [], { layoutRef })
|
|
47
59
|
|
|
48
60
|
return (
|
|
49
61
|
<MovableAreaContext.Provider value={{ height: areaHeight, width: areaWidth }}>
|
|
50
62
|
<View
|
|
51
63
|
{...innerProps}
|
|
52
|
-
style={{
|
|
53
|
-
height: areaHeight,
|
|
54
|
-
width: areaWidth,
|
|
55
|
-
overflow: 'hidden',
|
|
56
|
-
...style
|
|
57
|
-
}}
|
|
58
64
|
>
|
|
59
|
-
|
|
65
|
+
{
|
|
66
|
+
wrapChildren(
|
|
67
|
+
props,
|
|
68
|
+
{
|
|
69
|
+
hasVarDec,
|
|
70
|
+
varContext: varContextRef.current
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
}
|
|
60
74
|
</View>
|
|
61
75
|
</MovableAreaContext.Provider>
|
|
62
|
-
)
|
|
76
|
+
)
|
|
63
77
|
})
|
|
64
78
|
|
|
65
|
-
_MovableArea.displayName = 'mpx-movable-area'
|
|
79
|
+
_MovableArea.displayName = 'mpx-movable-area'
|
|
66
80
|
|
|
67
|
-
export default _MovableArea
|
|
81
|
+
export default _MovableArea
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* ✔ htouchmove
|
|
18
18
|
* ✔ vtouchmove
|
|
19
19
|
*/
|
|
20
|
-
import { useRef, useEffect, forwardRef, ReactNode, useContext, useState, useMemo } from 'react'
|
|
21
|
-
import { StyleSheet, Animated, NativeSyntheticEvent, PanResponder, View } from 'react-native'
|
|
22
|
-
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
20
|
+
import { useRef, useEffect, forwardRef, ReactNode, useContext, useState, useMemo } from 'react'
|
|
21
|
+
import { StyleSheet, Animated, NativeSyntheticEvent, PanResponder, View } from 'react-native'
|
|
22
|
+
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
23
23
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
24
24
|
import { MovableAreaContext } from './context'
|
|
25
25
|
|
|
@@ -51,7 +51,7 @@ const styles = StyleSheet.create({
|
|
|
51
51
|
position: 'absolute',
|
|
52
52
|
left: 0,
|
|
53
53
|
top: 0
|
|
54
|
-
}
|
|
54
|
+
}
|
|
55
55
|
})
|
|
56
56
|
|
|
57
57
|
const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewProps>((props: MovableViewProps, ref): JSX.Element => {
|
|
@@ -90,9 +90,9 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
90
90
|
|
|
91
91
|
let panResponder: any = {}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const isFirstTouch = useRef<boolean>(true)
|
|
94
|
+
const touchEvent = useRef<string>('')
|
|
95
|
+
const initialDistance = useRef<number>(0)
|
|
96
96
|
|
|
97
97
|
propsRef.current = props
|
|
98
98
|
|
|
@@ -102,7 +102,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
102
102
|
Animated.spring(scaleValue.current, {
|
|
103
103
|
toValue: clampedScale,
|
|
104
104
|
friction,
|
|
105
|
-
useNativeDriver: false
|
|
105
|
+
useNativeDriver: false
|
|
106
106
|
}).start(() => {
|
|
107
107
|
bindscale && bindscale(getCustomEvent('scale', {}, {
|
|
108
108
|
detail: {
|
|
@@ -115,7 +115,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
115
115
|
)
|
|
116
116
|
})
|
|
117
117
|
}
|
|
118
|
-
}, [originScaleValue])
|
|
118
|
+
}, [originScaleValue])
|
|
119
119
|
|
|
120
120
|
useEffect(() => {
|
|
121
121
|
if (movablePosition.current.x !== Number(x) || movablePosition.current.y !== Number(y)) {
|
|
@@ -142,7 +142,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
142
142
|
},
|
|
143
143
|
layoutRef
|
|
144
144
|
}, props)
|
|
145
|
-
)
|
|
145
|
+
)
|
|
146
146
|
})
|
|
147
147
|
}
|
|
148
148
|
}, [x, y])
|
|
@@ -194,34 +194,33 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
194
194
|
pan.current.setOffset({
|
|
195
195
|
x: direction === 'all' || direction === 'horizontal' ? pan.current.x._value : 0,
|
|
196
196
|
y: direction === 'all' || direction === 'vertical' ? pan.current.y._value : 0
|
|
197
|
-
})
|
|
198
|
-
pan.current.setValue({ x: 0, y: 0 })
|
|
197
|
+
})
|
|
198
|
+
pan.current.setValue({ x: 0, y: 0 })
|
|
199
199
|
} else {
|
|
200
|
-
initialDistance.current = 0
|
|
200
|
+
initialDistance.current = 0
|
|
201
201
|
setTransformOrigin('50% 50%')
|
|
202
202
|
}
|
|
203
203
|
},
|
|
204
204
|
onPanResponderMove: (e, gestureState) => {
|
|
205
205
|
if (gestureState.numberActiveTouches === 2 && scale) {
|
|
206
206
|
setTransformOrigin('50% 50%')
|
|
207
|
-
const touch1 = e.nativeEvent.touches[0]
|
|
208
|
-
const touch2 = e.nativeEvent.touches[1]
|
|
207
|
+
const touch1 = e.nativeEvent.touches[0]
|
|
208
|
+
const touch2 = e.nativeEvent.touches[1]
|
|
209
209
|
const currentTouchDistance = Math.sqrt(
|
|
210
210
|
Math.pow(touch1.pageX - touch2.pageX, 2) + Math.pow(touch1.pageY - touch2.pageY, 2)
|
|
211
211
|
)
|
|
212
212
|
|
|
213
213
|
if (!initialDistance.current) {
|
|
214
|
-
initialDistance.current = currentTouchDistance
|
|
214
|
+
initialDistance.current = currentTouchDistance
|
|
215
215
|
} else {
|
|
216
216
|
const newScale = currentTouchDistance / initialDistance.current
|
|
217
217
|
const clampedScale = Math.min(scaleMax, Math.max(scaleMin, newScale))
|
|
218
218
|
|
|
219
|
-
|
|
220
219
|
Animated.spring(scaleValue.current, {
|
|
221
220
|
toValue: clampedScale,
|
|
222
221
|
friction: 7,
|
|
223
222
|
useNativeDriver: false
|
|
224
|
-
}).start()
|
|
223
|
+
}).start()
|
|
225
224
|
bindscale && bindscale(getCustomEvent('scale', e, {
|
|
226
225
|
detail: {
|
|
227
226
|
x: pan.current.x._value,
|
|
@@ -229,29 +228,29 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
229
228
|
scale: clampedScale
|
|
230
229
|
},
|
|
231
230
|
layoutRef
|
|
232
|
-
}, propsRef.current))
|
|
231
|
+
}, propsRef.current))
|
|
233
232
|
}
|
|
234
233
|
} else if (gestureState.numberActiveTouches === 1) {
|
|
235
234
|
if (initialDistance.current) {
|
|
236
|
-
return
|
|
235
|
+
return // Skip processing if it's switching from a double touch
|
|
237
236
|
}
|
|
238
237
|
setTransformOrigin('0% 0%')
|
|
239
238
|
if (isFirstTouch.current) {
|
|
240
239
|
touchEvent.current = Math.abs(gestureState.dx) > Math.abs(gestureState.dy) ? 'htouchmove' : 'vtouchmove'
|
|
241
|
-
isFirstTouch.current = false
|
|
240
|
+
isFirstTouch.current = false
|
|
242
241
|
}
|
|
243
242
|
Animated.event(
|
|
244
243
|
[
|
|
245
244
|
null,
|
|
246
245
|
{
|
|
247
246
|
dx: direction === 'all' || direction === 'horizontal' ? pan.current.x : new Animated.Value(0),
|
|
248
|
-
dy: direction === 'all' || direction === 'vertical' ? pan.current.y : new Animated.Value(0)
|
|
247
|
+
dy: direction === 'all' || direction === 'vertical' ? pan.current.y : new Animated.Value(0)
|
|
249
248
|
}
|
|
250
249
|
],
|
|
251
250
|
{
|
|
252
251
|
useNativeDriver: false
|
|
253
252
|
}
|
|
254
|
-
)(e, gestureState)
|
|
253
|
+
)(e, gestureState)
|
|
255
254
|
|
|
256
255
|
movablePosition.current = {
|
|
257
256
|
x: pan.current.x.__getValue(),
|
|
@@ -375,7 +374,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
375
374
|
}
|
|
376
375
|
}
|
|
377
376
|
|
|
378
|
-
const [translateX, translateY] = [pan.current.x, pan.current.y]
|
|
377
|
+
const [translateX, translateY] = [pan.current.x, pan.current.y]
|
|
379
378
|
|
|
380
379
|
const transformStyle = { transform: [{ translateX }, { translateY }, { scale: scaleValue.current }], transformOrigin: transformOrigin }
|
|
381
380
|
|
|
@@ -387,8 +386,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
387
386
|
ref: nodeRef,
|
|
388
387
|
...panResponder.panHandlers,
|
|
389
388
|
onLayout,
|
|
390
|
-
...(hasTouchmove() ? {
|
|
391
|
-
...(hasCatchTouchmove() ? {
|
|
389
|
+
...(hasTouchmove() ? { bindtouchmove: onTouchMove } : {}),
|
|
390
|
+
...(hasCatchTouchmove() ? { catchtouchmove: onCatchTouchMove } : {})
|
|
392
391
|
}, [
|
|
393
392
|
'children',
|
|
394
393
|
'style',
|
|
@@ -417,9 +416,9 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
417
416
|
>
|
|
418
417
|
{children}
|
|
419
418
|
</Animated.View>
|
|
420
|
-
)
|
|
419
|
+
)
|
|
421
420
|
})
|
|
422
421
|
|
|
423
422
|
_MovableView.displayName = 'mpx-movable-view'
|
|
424
423
|
|
|
425
|
-
export default _MovableView
|
|
424
|
+
export default _MovableView
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
* ✔ delta
|
|
9
9
|
*/
|
|
10
10
|
import { View } from 'react-native'
|
|
11
|
-
import { useCallback, forwardRef, JSX } from 'react'
|
|
11
|
+
import { useCallback, forwardRef, JSX } from 'react'
|
|
12
12
|
import useInnerProps from './getInnerListeners'
|
|
13
13
|
import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
14
14
|
|
|
15
|
-
import MpxView, { _ViewProps }
|
|
15
|
+
import MpxView, { _ViewProps } from './mpx-view'
|
|
16
16
|
|
|
17
17
|
interface _NavigatorProps extends _ViewProps {
|
|
18
18
|
['open-type']: 'navigate' | 'redirect' | 'switchTab' | 'reLaunch' | 'navigateBack'
|