@mpxjs/webpack-plugin 2.9.62 → 2.9.65
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/config.js +38 -10
- package/lib/index.js +1 -3
- package/lib/platform/style/wx/index.js +115 -66
- package/lib/platform/template/wx/index.js +12 -8
- package/lib/react/processStyles.js +1 -0
- package/lib/react/processTemplate.js +2 -3
- package/lib/react/style-helper.js +9 -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 +53 -74
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +20 -18
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +30 -42
- package/lib/runtime/components/react/dist/mpx-form.jsx +18 -15
- package/lib/runtime/components/react/dist/mpx-icon.jsx +15 -17
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +36 -34
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +36 -31
- package/lib/runtime/components/react/dist/mpx-label.jsx +30 -37
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +15 -19
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +10 -9
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +2 -1
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +9 -5
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +13 -8
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +3 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +22 -20
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +103 -10
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +149 -54
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +20 -18
- package/lib/runtime/components/react/dist/mpx-radio.jsx +29 -43
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +8 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +36 -27
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +141 -75
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +16 -7
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +20 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +18 -14
- package/lib/runtime/components/react/dist/mpx-text.jsx +20 -35
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +296 -210
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -7
- package/lib/runtime/components/react/dist/parser.js +218 -0
- package/lib/runtime/components/react/dist/useNodesRef.js +1 -5
- package/lib/runtime/components/react/dist/utils.jsx +445 -0
- package/lib/runtime/components/react/getInnerListeners.ts +18 -8
- package/lib/runtime/components/react/mpx-button.tsx +83 -91
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +50 -43
- package/lib/runtime/components/react/mpx-checkbox.tsx +56 -64
- package/lib/runtime/components/react/mpx-form.tsx +51 -22
- package/lib/runtime/components/react/mpx-icon.tsx +31 -27
- package/lib/runtime/components/react/mpx-image/index.tsx +54 -47
- package/lib/runtime/components/react/mpx-image/svg.tsx +5 -3
- package/lib/runtime/components/react/mpx-input.tsx +59 -38
- package/lib/runtime/components/react/mpx-label.tsx +55 -59
- package/lib/runtime/components/react/mpx-movable-area.tsx +40 -25
- package/lib/runtime/components/react/mpx-movable-view.tsx +29 -29
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -2
- package/lib/runtime/components/react/mpx-picker/date.tsx +4 -4
- package/lib/runtime/components/react/mpx-picker/index.tsx +12 -11
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +17 -13
- package/lib/runtime/components/react/mpx-picker/region.tsx +23 -19
- package/lib/runtime/components/react/mpx-picker/selector.tsx +7 -7
- package/lib/runtime/components/react/mpx-picker/time.tsx +29 -31
- package/lib/runtime/components/react/mpx-picker/type.ts +1 -1
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +149 -20
- package/lib/runtime/components/react/mpx-picker-view.tsx +180 -63
- package/lib/runtime/components/react/mpx-radio-group.tsx +51 -47
- package/lib/runtime/components/react/mpx-radio.tsx +57 -72
- package/lib/runtime/components/react/mpx-root-portal.tsx +10 -8
- package/lib/runtime/components/react/mpx-scroll-view.tsx +136 -104
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +175 -96
- package/lib/runtime/components/react/mpx-swiper/index.tsx +21 -9
- package/lib/runtime/components/react/mpx-swiper/type.ts +16 -5
- package/lib/runtime/components/react/mpx-swiper-item.tsx +48 -14
- package/lib/runtime/components/react/mpx-switch.tsx +46 -24
- package/lib/runtime/components/react/mpx-text.tsx +38 -45
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +401 -241
- package/lib/runtime/components/react/mpx-web-view.tsx +22 -22
- 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 +24 -2
- package/lib/runtime/components/react/useNodesRef.ts +1 -7
- package/lib/runtime/components/react/utils.tsx +524 -0
- package/lib/runtime/components/web/mpx-scroll-view.vue +25 -5
- package/lib/style-compiler/index.js +5 -4
- package/lib/template-compiler/compiler.js +133 -161
- package/lib/template-compiler/gen-node-react.js +1 -3
- package/lib/utils/const.js +2 -1
- package/lib/web/processStyles.js +2 -1
- package/lib/web/processTemplate.js +2 -3
- package/lib/wxml/loader.js +1 -1
- package/package.json +7 -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,26 @@ 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 = useRef(null)
|
|
196
|
+
useNodesRef(props, ref, nodeRef)
|
|
197
|
+
|
|
198
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
199
|
+
|
|
172
200
|
useEffect(() => {
|
|
173
201
|
if (inputValue !== value) {
|
|
174
202
|
setInputValue(value)
|
|
@@ -187,7 +215,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
187
215
|
if (!bindinput && !bindblur) return
|
|
188
216
|
const {
|
|
189
217
|
range: { start, end },
|
|
190
|
-
text
|
|
218
|
+
text
|
|
191
219
|
} = nativeEvent
|
|
192
220
|
cursorIndex.current = start < end ? start : start + text.length
|
|
193
221
|
}
|
|
@@ -202,7 +230,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
202
230
|
{
|
|
203
231
|
detail: {
|
|
204
232
|
value: evt.nativeEvent.text,
|
|
205
|
-
cursor: cursorIndex.current
|
|
233
|
+
cursor: cursorIndex.current
|
|
206
234
|
},
|
|
207
235
|
layoutRef
|
|
208
236
|
},
|
|
@@ -225,7 +253,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
225
253
|
evt,
|
|
226
254
|
{
|
|
227
255
|
detail: {
|
|
228
|
-
value: tmpValue.current || ''
|
|
256
|
+
value: tmpValue.current || ''
|
|
229
257
|
},
|
|
230
258
|
layoutRef
|
|
231
259
|
},
|
|
@@ -243,7 +271,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
243
271
|
{
|
|
244
272
|
detail: {
|
|
245
273
|
value: tmpValue.current || '',
|
|
246
|
-
cursor: cursorIndex.current
|
|
274
|
+
cursor: cursorIndex.current
|
|
247
275
|
},
|
|
248
276
|
layoutRef
|
|
249
277
|
},
|
|
@@ -261,7 +289,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
261
289
|
evt,
|
|
262
290
|
{
|
|
263
291
|
detail: {
|
|
264
|
-
value: tmpValue.current || ''
|
|
292
|
+
value: tmpValue.current || ''
|
|
265
293
|
},
|
|
266
294
|
layoutRef
|
|
267
295
|
},
|
|
@@ -279,7 +307,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
279
307
|
evt,
|
|
280
308
|
{
|
|
281
309
|
detail: {
|
|
282
|
-
value: tmpValue.current || ''
|
|
310
|
+
value: tmpValue.current || ''
|
|
283
311
|
},
|
|
284
312
|
layoutRef
|
|
285
313
|
},
|
|
@@ -303,7 +331,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
303
331
|
detail: {
|
|
304
332
|
height,
|
|
305
333
|
lineHeight,
|
|
306
|
-
lineCount: lineCount.current
|
|
334
|
+
lineCount: lineCount.current
|
|
307
335
|
},
|
|
308
336
|
layoutRef
|
|
309
337
|
},
|
|
@@ -323,7 +351,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
323
351
|
{
|
|
324
352
|
detail: {
|
|
325
353
|
selectionStart: evt.nativeEvent.selection.start,
|
|
326
|
-
selectionEnd: evt.nativeEvent.selection.end
|
|
354
|
+
selectionEnd: evt.nativeEvent.selection.end
|
|
327
355
|
},
|
|
328
356
|
layoutRef
|
|
329
357
|
},
|
|
@@ -332,12 +360,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
332
360
|
)
|
|
333
361
|
}
|
|
334
362
|
|
|
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
363
|
const resetValue = () => {
|
|
342
364
|
setInputValue('')
|
|
343
365
|
}
|
|
@@ -348,7 +370,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
348
370
|
|
|
349
371
|
if (formValuesMap) {
|
|
350
372
|
if (!props.name) {
|
|
351
|
-
|
|
373
|
+
warn('If a form component is used, the name attribute is required.')
|
|
352
374
|
} else {
|
|
353
375
|
formValuesMap.set(props.name, { getValue, resetValue })
|
|
354
376
|
}
|
|
@@ -363,16 +385,23 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
363
385
|
: (nodeRef.current as TextInput)?.blur()
|
|
364
386
|
}, [focus])
|
|
365
387
|
|
|
388
|
+
const composeStyle = { ...normalStyle, ...layoutStyle }
|
|
389
|
+
|
|
366
390
|
const innerProps = useInnerProps(props, {
|
|
367
391
|
ref: nodeRef,
|
|
368
|
-
|
|
392
|
+
style: {
|
|
393
|
+
padding: 0,
|
|
394
|
+
...composeStyle,
|
|
395
|
+
...multiline && autoHeight && {
|
|
396
|
+
height: Math.max((composeStyle as any)?.minHeight || 35, contentHeight)
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
...layoutProps
|
|
369
400
|
},
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
layoutRef
|
|
375
|
-
})
|
|
401
|
+
[],
|
|
402
|
+
{
|
|
403
|
+
layoutRef
|
|
404
|
+
})
|
|
376
405
|
|
|
377
406
|
return (
|
|
378
407
|
<TextInput
|
|
@@ -400,14 +429,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
400
429
|
onSubmitEditing={onSubmitEditing}
|
|
401
430
|
onContentSizeChange={onContentSizeChange}
|
|
402
431
|
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
432
|
/>
|
|
412
433
|
)
|
|
413
434
|
})
|
|
@@ -2,101 +2,87 @@
|
|
|
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 = useRef(null)
|
|
58
|
+
useNodesRef(props, ref, nodeRef, { defaultStyle })
|
|
49
59
|
|
|
50
|
-
const {
|
|
51
|
-
defaultStyle
|
|
52
|
-
})
|
|
60
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
53
61
|
|
|
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
|
-
)
|
|
62
|
+
const { textStyle, backgroundStyle, innerStyle } = splitStyle(normalStyle)
|
|
63
|
+
|
|
64
|
+
if (backgroundStyle) {
|
|
65
|
+
warn('Label does not support background image-related styles!')
|
|
67
66
|
}
|
|
68
67
|
|
|
68
|
+
const contextRef: LabelContextValue = useRef({
|
|
69
|
+
triggerChange: noop
|
|
70
|
+
})
|
|
71
|
+
|
|
69
72
|
const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
70
73
|
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, props))
|
|
71
74
|
contextRef.current.triggerChange?.(evt)
|
|
72
75
|
}
|
|
73
76
|
|
|
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
77
|
const innerProps = useInnerProps(
|
|
92
78
|
props,
|
|
93
79
|
{
|
|
94
80
|
ref: nodeRef,
|
|
95
|
-
style: { ...
|
|
96
|
-
|
|
97
|
-
|
|
81
|
+
style: { ...innerStyle, ...layoutStyle },
|
|
82
|
+
...layoutProps,
|
|
83
|
+
bindtap: onTap
|
|
98
84
|
},
|
|
99
|
-
[
|
|
85
|
+
[],
|
|
100
86
|
{
|
|
101
87
|
layoutRef
|
|
102
88
|
}
|
|
@@ -104,7 +90,17 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
|
104
90
|
|
|
105
91
|
return <View {...innerProps}>
|
|
106
92
|
<LabelContext.Provider value={contextRef}>
|
|
107
|
-
{
|
|
93
|
+
{
|
|
94
|
+
wrapChildren(
|
|
95
|
+
props,
|
|
96
|
+
{
|
|
97
|
+
hasVarDec,
|
|
98
|
+
varContext: varContextRef.current,
|
|
99
|
+
textStyle,
|
|
100
|
+
textProps
|
|
101
|
+
}
|
|
102
|
+
)
|
|
103
|
+
}
|
|
108
104
|
</LabelContext.Provider>
|
|
109
105
|
</View>
|
|
110
106
|
}
|
|
@@ -3,65 +3,80 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { View, LayoutChangeEvent } from 'react-native'
|
|
6
|
-
import { JSX, useState, useEffect,
|
|
6
|
+
import { JSX, useState, useEffect, forwardRef, ReactNode, useRef } 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
|
|
|
30
|
-
const {
|
|
35
|
+
const {
|
|
36
|
+
hasSelfPercent,
|
|
37
|
+
normalStyle,
|
|
38
|
+
hasVarDec,
|
|
39
|
+
varContextRef,
|
|
40
|
+
setWidth,
|
|
41
|
+
setHeight
|
|
42
|
+
} = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight })
|
|
43
|
+
|
|
44
|
+
const movableViewRef = useRef(null)
|
|
45
|
+
useNodesRef(props, ref, movableViewRef)
|
|
31
46
|
|
|
32
47
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
33
48
|
const { width = 10, height = 10 } = e.nativeEvent.layout
|
|
34
49
|
setAreaWidth(width)
|
|
35
50
|
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
51
|
}
|
|
52
|
+
|
|
53
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef, onLayout })
|
|
54
|
+
|
|
40
55
|
const innerProps = useInnerProps(props, {
|
|
56
|
+
style: { height: areaHeight, width: areaWidth, overflow: 'hidden', ...normalStyle, ...layoutStyle },
|
|
41
57
|
ref: movableViewRef,
|
|
42
|
-
|
|
43
|
-
}, [
|
|
44
|
-
'children',
|
|
45
|
-
'style',
|
|
46
|
-
], { layoutRef })
|
|
58
|
+
...layoutProps
|
|
59
|
+
}, [], { layoutRef })
|
|
47
60
|
|
|
48
61
|
return (
|
|
49
62
|
<MovableAreaContext.Provider value={{ height: areaHeight, width: areaWidth }}>
|
|
50
63
|
<View
|
|
51
64
|
{...innerProps}
|
|
52
|
-
style={{
|
|
53
|
-
height: areaHeight,
|
|
54
|
-
width: areaWidth,
|
|
55
|
-
overflow: 'hidden',
|
|
56
|
-
...style
|
|
57
|
-
}}
|
|
58
65
|
>
|
|
59
|
-
|
|
66
|
+
{
|
|
67
|
+
wrapChildren(
|
|
68
|
+
props,
|
|
69
|
+
{
|
|
70
|
+
hasVarDec,
|
|
71
|
+
varContext: varContextRef.current
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
}
|
|
60
75
|
</View>
|
|
61
76
|
</MovableAreaContext.Provider>
|
|
62
|
-
)
|
|
77
|
+
)
|
|
63
78
|
})
|
|
64
79
|
|
|
65
|
-
_MovableArea.displayName = 'mpx-movable-area'
|
|
80
|
+
_MovableArea.displayName = 'mpx-movable-area'
|
|
66
81
|
|
|
67
|
-
export default _MovableArea
|
|
82
|
+
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 => {
|
|
@@ -84,15 +84,16 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
84
84
|
y: Number(y)
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
const
|
|
87
|
+
const nodeRef = useRef<View>(null)
|
|
88
|
+
useNodesRef(props, ref, nodeRef, {
|
|
88
89
|
defaultStyle: styles.container
|
|
89
90
|
})
|
|
90
91
|
|
|
91
92
|
let panResponder: any = {}
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
const isFirstTouch = useRef<boolean>(true)
|
|
95
|
+
const touchEvent = useRef<string>('')
|
|
96
|
+
const initialDistance = useRef<number>(0)
|
|
96
97
|
|
|
97
98
|
propsRef.current = props
|
|
98
99
|
|
|
@@ -102,7 +103,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
102
103
|
Animated.spring(scaleValue.current, {
|
|
103
104
|
toValue: clampedScale,
|
|
104
105
|
friction,
|
|
105
|
-
useNativeDriver: false
|
|
106
|
+
useNativeDriver: false
|
|
106
107
|
}).start(() => {
|
|
107
108
|
bindscale && bindscale(getCustomEvent('scale', {}, {
|
|
108
109
|
detail: {
|
|
@@ -115,7 +116,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
115
116
|
)
|
|
116
117
|
})
|
|
117
118
|
}
|
|
118
|
-
}, [originScaleValue])
|
|
119
|
+
}, [originScaleValue])
|
|
119
120
|
|
|
120
121
|
useEffect(() => {
|
|
121
122
|
if (movablePosition.current.x !== Number(x) || movablePosition.current.y !== Number(y)) {
|
|
@@ -142,7 +143,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
142
143
|
},
|
|
143
144
|
layoutRef
|
|
144
145
|
}, props)
|
|
145
|
-
)
|
|
146
|
+
)
|
|
146
147
|
})
|
|
147
148
|
}
|
|
148
149
|
}, [x, y])
|
|
@@ -194,34 +195,33 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
194
195
|
pan.current.setOffset({
|
|
195
196
|
x: direction === 'all' || direction === 'horizontal' ? pan.current.x._value : 0,
|
|
196
197
|
y: direction === 'all' || direction === 'vertical' ? pan.current.y._value : 0
|
|
197
|
-
})
|
|
198
|
-
pan.current.setValue({ x: 0, y: 0 })
|
|
198
|
+
})
|
|
199
|
+
pan.current.setValue({ x: 0, y: 0 })
|
|
199
200
|
} else {
|
|
200
|
-
initialDistance.current = 0
|
|
201
|
+
initialDistance.current = 0
|
|
201
202
|
setTransformOrigin('50% 50%')
|
|
202
203
|
}
|
|
203
204
|
},
|
|
204
205
|
onPanResponderMove: (e, gestureState) => {
|
|
205
206
|
if (gestureState.numberActiveTouches === 2 && scale) {
|
|
206
207
|
setTransformOrigin('50% 50%')
|
|
207
|
-
const touch1 = e.nativeEvent.touches[0]
|
|
208
|
-
const touch2 = e.nativeEvent.touches[1]
|
|
208
|
+
const touch1 = e.nativeEvent.touches[0]
|
|
209
|
+
const touch2 = e.nativeEvent.touches[1]
|
|
209
210
|
const currentTouchDistance = Math.sqrt(
|
|
210
211
|
Math.pow(touch1.pageX - touch2.pageX, 2) + Math.pow(touch1.pageY - touch2.pageY, 2)
|
|
211
212
|
)
|
|
212
213
|
|
|
213
214
|
if (!initialDistance.current) {
|
|
214
|
-
initialDistance.current = currentTouchDistance
|
|
215
|
+
initialDistance.current = currentTouchDistance
|
|
215
216
|
} else {
|
|
216
217
|
const newScale = currentTouchDistance / initialDistance.current
|
|
217
218
|
const clampedScale = Math.min(scaleMax, Math.max(scaleMin, newScale))
|
|
218
219
|
|
|
219
|
-
|
|
220
220
|
Animated.spring(scaleValue.current, {
|
|
221
221
|
toValue: clampedScale,
|
|
222
222
|
friction: 7,
|
|
223
223
|
useNativeDriver: false
|
|
224
|
-
}).start()
|
|
224
|
+
}).start()
|
|
225
225
|
bindscale && bindscale(getCustomEvent('scale', e, {
|
|
226
226
|
detail: {
|
|
227
227
|
x: pan.current.x._value,
|
|
@@ -229,29 +229,29 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
229
229
|
scale: clampedScale
|
|
230
230
|
},
|
|
231
231
|
layoutRef
|
|
232
|
-
}, propsRef.current))
|
|
232
|
+
}, propsRef.current))
|
|
233
233
|
}
|
|
234
234
|
} else if (gestureState.numberActiveTouches === 1) {
|
|
235
235
|
if (initialDistance.current) {
|
|
236
|
-
return
|
|
236
|
+
return // Skip processing if it's switching from a double touch
|
|
237
237
|
}
|
|
238
238
|
setTransformOrigin('0% 0%')
|
|
239
239
|
if (isFirstTouch.current) {
|
|
240
240
|
touchEvent.current = Math.abs(gestureState.dx) > Math.abs(gestureState.dy) ? 'htouchmove' : 'vtouchmove'
|
|
241
|
-
isFirstTouch.current = false
|
|
241
|
+
isFirstTouch.current = false
|
|
242
242
|
}
|
|
243
243
|
Animated.event(
|
|
244
244
|
[
|
|
245
245
|
null,
|
|
246
246
|
{
|
|
247
247
|
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)
|
|
248
|
+
dy: direction === 'all' || direction === 'vertical' ? pan.current.y : new Animated.Value(0)
|
|
249
249
|
}
|
|
250
250
|
],
|
|
251
251
|
{
|
|
252
252
|
useNativeDriver: false
|
|
253
253
|
}
|
|
254
|
-
)(e, gestureState)
|
|
254
|
+
)(e, gestureState)
|
|
255
255
|
|
|
256
256
|
movablePosition.current = {
|
|
257
257
|
x: pan.current.x.__getValue(),
|
|
@@ -375,7 +375,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
const [translateX, translateY] = [pan.current.x, pan.current.y]
|
|
378
|
+
const [translateX, translateY] = [pan.current.x, pan.current.y]
|
|
379
379
|
|
|
380
380
|
const transformStyle = { transform: [{ translateX }, { translateY }, { scale: scaleValue.current }], transformOrigin: transformOrigin }
|
|
381
381
|
|
|
@@ -387,8 +387,8 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
387
387
|
ref: nodeRef,
|
|
388
388
|
...panResponder.panHandlers,
|
|
389
389
|
onLayout,
|
|
390
|
-
...(hasTouchmove() ? {
|
|
391
|
-
...(hasCatchTouchmove() ? {
|
|
390
|
+
...(hasTouchmove() ? { bindtouchmove: onTouchMove } : {}),
|
|
391
|
+
...(hasCatchTouchmove() ? { catchtouchmove: onCatchTouchMove } : {})
|
|
392
392
|
}, [
|
|
393
393
|
'children',
|
|
394
394
|
'style',
|
|
@@ -417,9 +417,9 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
417
417
|
>
|
|
418
418
|
{children}
|
|
419
419
|
</Animated.View>
|
|
420
|
-
)
|
|
420
|
+
)
|
|
421
421
|
})
|
|
422
422
|
|
|
423
423
|
_MovableView.displayName = 'mpx-movable-view'
|
|
424
424
|
|
|
425
|
-
export default _MovableView
|
|
425
|
+
export default _MovableView
|