@mpxjs/webpack-plugin 2.9.65 → 2.9.67
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/dependencies/RecordGlobalComponentsDependency.js +11 -12
- package/lib/dependencies/RecordRuntimeInfoDependency.js +1 -1
- package/lib/index.js +28 -8
- package/lib/json-compiler/index.js +2 -11
- package/lib/loader.js +24 -45
- package/lib/native-loader.js +49 -64
- package/lib/platform/json/wx/index.js +3 -10
- package/lib/platform/style/wx/index.js +32 -56
- package/lib/react/index.js +4 -3
- package/lib/react/processJSON.js +5 -13
- package/lib/react/processMainScript.js +7 -3
- package/lib/react/processScript.js +3 -4
- package/lib/react/processTemplate.js +6 -4
- package/lib/resolver/AddModePlugin.js +17 -4
- package/lib/runtime/components/react/context.ts +8 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/mpx-button.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-form.jsx +33 -24
- package/lib/runtime/components/react/dist/mpx-icon.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-input.jsx +44 -38
- package/lib/runtime/components/react/dist/mpx-label.jsx +10 -7
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +10 -17
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +378 -294
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +30 -17
- package/lib/runtime/components/react/dist/mpx-radio.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +58 -30
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +77 -77
- package/lib/runtime/components/react/dist/mpx-swiper/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-switch.jsx +8 -1
- package/lib/runtime/components/react/dist/mpx-text.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-view.jsx +31 -12
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +2 -2
- package/lib/runtime/components/react/dist/useAnimationHooks.js +303 -0
- package/lib/runtime/components/react/dist/utils.jsx +13 -3
- package/lib/runtime/components/react/getInnerListeners.ts +1 -0
- package/lib/runtime/components/react/mpx-button.tsx +1 -1
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +52 -29
- package/lib/runtime/components/react/mpx-checkbox.tsx +1 -1
- package/lib/runtime/components/react/mpx-form.tsx +42 -34
- package/lib/runtime/components/react/mpx-icon.tsx +1 -1
- package/lib/runtime/components/react/mpx-image/index.tsx +2 -3
- package/lib/runtime/components/react/mpx-input.tsx +68 -66
- package/lib/runtime/components/react/mpx-label.tsx +11 -8
- package/lib/runtime/components/react/mpx-movable-area.tsx +11 -19
- package/lib/runtime/components/react/mpx-movable-view.tsx +456 -334
- package/lib/runtime/components/react/mpx-navigator.tsx +1 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +55 -29
- package/lib/runtime/components/react/mpx-radio.tsx +1 -1
- package/lib/runtime/components/react/mpx-root-portal.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +92 -37
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +77 -76
- package/lib/runtime/components/react/mpx-swiper/index.tsx +2 -1
- package/lib/runtime/components/react/mpx-swiper-item.tsx +1 -1
- package/lib/runtime/components/react/mpx-switch.tsx +10 -2
- package/lib/runtime/components/react/mpx-text.tsx +1 -1
- package/lib/runtime/components/react/mpx-textarea.tsx +1 -1
- package/lib/runtime/components/react/mpx-view.tsx +40 -20
- package/lib/runtime/components/react/mpx-web-view.tsx +2 -2
- package/lib/runtime/components/react/types/common.ts +8 -2
- package/lib/runtime/components/react/useAnimationHooks.ts +332 -0
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +23 -6
- package/lib/runtime/optionProcessorReact.js +0 -15
- package/lib/runtime/swanHelper.wxs +1 -1
- package/lib/style-compiler/index.js +1 -1
- package/lib/style-compiler/plugins/scope-id.js +1 -0
- package/lib/template-compiler/compiler.js +68 -33
- package/lib/template-compiler/index.js +4 -4
- package/lib/utils/pre-process-json.js +113 -0
- package/lib/web/index.js +5 -4
- package/lib/web/processJSON.js +5 -13
- package/lib/web/processTemplate.js +2 -2
- package/package.json +5 -4
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
* ✔ bindsubmit
|
|
5
5
|
* ✔ bindreset
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import { View } from 'react-native'
|
|
9
|
-
import { JSX, useRef, forwardRef, ReactNode } from 'react'
|
|
8
|
+
import { JSX, useRef, forwardRef, ReactNode, useMemo, useCallback } from 'react'
|
|
10
9
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
11
10
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
12
11
|
import { FormContext } from './context'
|
|
13
12
|
import { useTransformStyle, splitProps, splitStyle, useLayout, wrapChildren } from './utils'
|
|
14
13
|
interface FormProps {
|
|
15
14
|
style?: Record<string, any>;
|
|
16
|
-
children
|
|
15
|
+
children?: ReactNode;
|
|
17
16
|
'enable-offset'?: boolean;
|
|
18
17
|
'enable-var'?: boolean
|
|
19
18
|
'external-var-context'?: Record<string, any>;
|
|
@@ -30,7 +29,6 @@ interface FormProps {
|
|
|
30
29
|
|
|
31
30
|
const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: FormProps, ref): JSX.Element => {
|
|
32
31
|
const { textProps, innerProps: props = {} } = splitProps(fromProps)
|
|
33
|
-
const formValuesMap = useRef(new Map()).current
|
|
34
32
|
const {
|
|
35
33
|
style,
|
|
36
34
|
'enable-var': enableVar,
|
|
@@ -54,34 +52,10 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
|
|
|
54
52
|
const formRef = useRef(null)
|
|
55
53
|
useNodesRef(props, ref, formRef)
|
|
56
54
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const submit = () => {
|
|
60
|
-
const { bindsubmit } = props
|
|
61
|
-
const formValue: Record<string, any> = {}
|
|
62
|
-
for (const name of formValuesMap.keys()) {
|
|
63
|
-
if (formValuesMap.get(name).getValue) {
|
|
64
|
-
formValue[name] = formValuesMap.get(name).getValue()
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
bindsubmit && bindsubmit(getCustomEvent(
|
|
68
|
-
'submit',
|
|
69
|
-
{},
|
|
70
|
-
{
|
|
71
|
-
detail: {
|
|
72
|
-
value: formValue
|
|
73
|
-
},
|
|
74
|
-
layoutRef
|
|
75
|
-
},
|
|
76
|
-
props
|
|
77
|
-
))
|
|
78
|
-
}
|
|
55
|
+
const propsRef = useRef<FormProps>({})
|
|
56
|
+
propsRef.current = props
|
|
79
57
|
|
|
80
|
-
const
|
|
81
|
-
const { bindreset } = props
|
|
82
|
-
bindreset && bindreset()
|
|
83
|
-
formValuesMap.forEach(item => item.resetValue())
|
|
84
|
-
}
|
|
58
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: formRef })
|
|
85
59
|
|
|
86
60
|
const innerProps = useInnerProps(props, {
|
|
87
61
|
style: { ...innerStyle, ...layoutStyle },
|
|
@@ -92,11 +66,45 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
|
|
|
92
66
|
'bindreset'
|
|
93
67
|
], { layoutRef })
|
|
94
68
|
|
|
69
|
+
const contextValue = useMemo(() => {
|
|
70
|
+
const formValuesMap = new Map()
|
|
71
|
+
const submit = () => {
|
|
72
|
+
const { bindsubmit } = propsRef.current
|
|
73
|
+
const formValue: Record<string, any> = {}
|
|
74
|
+
for (const name of formValuesMap.keys()) {
|
|
75
|
+
if (formValuesMap.get(name).getValue) {
|
|
76
|
+
formValue[name] = formValuesMap.get(name).getValue()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
bindsubmit && bindsubmit(getCustomEvent(
|
|
80
|
+
'submit',
|
|
81
|
+
{},
|
|
82
|
+
{
|
|
83
|
+
detail: {
|
|
84
|
+
value: formValue
|
|
85
|
+
},
|
|
86
|
+
layoutRef
|
|
87
|
+
},
|
|
88
|
+
propsRef.current
|
|
89
|
+
))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const reset = () => {
|
|
93
|
+
const { bindreset } = propsRef.current
|
|
94
|
+
bindreset && bindreset()
|
|
95
|
+
formValuesMap.forEach(item => item.resetValue())
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
formValuesMap,
|
|
99
|
+
submit,
|
|
100
|
+
reset
|
|
101
|
+
}
|
|
102
|
+
}, [])
|
|
95
103
|
return (
|
|
96
104
|
<View
|
|
97
105
|
{...innerProps}
|
|
98
106
|
>
|
|
99
|
-
<FormContext.Provider value={
|
|
107
|
+
<FormContext.Provider value={contextValue}>
|
|
100
108
|
{
|
|
101
109
|
wrapChildren(
|
|
102
110
|
props,
|
|
@@ -107,12 +115,12 @@ const _Form = forwardRef<HandlerRef<View, FormProps>, FormProps>((fromProps: For
|
|
|
107
115
|
textProps
|
|
108
116
|
}
|
|
109
117
|
)
|
|
110
|
-
|
|
118
|
+
}
|
|
111
119
|
</FormContext.Provider>
|
|
112
120
|
</View>
|
|
113
121
|
)
|
|
114
122
|
})
|
|
115
123
|
|
|
116
|
-
_Form.displayName = '
|
|
124
|
+
_Form.displayName = 'MpxForm'
|
|
117
125
|
|
|
118
126
|
export default _Form
|
|
@@ -298,8 +298,7 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
298
298
|
[],
|
|
299
299
|
{
|
|
300
300
|
layoutRef
|
|
301
|
-
}
|
|
302
|
-
)
|
|
301
|
+
})
|
|
303
302
|
|
|
304
303
|
// if (typeof src === 'string' && REMOTE_SVG_REGEXP.test(src)) {
|
|
305
304
|
// return (
|
|
@@ -341,6 +340,6 @@ const Image = forwardRef<HandlerRef<RNImage, ImageProps>, ImageProps>((props, re
|
|
|
341
340
|
)
|
|
342
341
|
})
|
|
343
342
|
|
|
344
|
-
Image.displayName = '
|
|
343
|
+
Image.displayName = 'MpxImage'
|
|
345
344
|
|
|
346
345
|
export default Image
|
|
@@ -246,44 +246,41 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
const onInputFocus = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
249
|
-
bindfocus
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
{
|
|
255
|
-
|
|
256
|
-
value: tmpValue.current || ''
|
|
257
|
-
},
|
|
258
|
-
layoutRef
|
|
249
|
+
bindfocus!(
|
|
250
|
+
getCustomEvent(
|
|
251
|
+
'focus',
|
|
252
|
+
evt,
|
|
253
|
+
{
|
|
254
|
+
detail: {
|
|
255
|
+
value: tmpValue.current || ''
|
|
259
256
|
},
|
|
260
|
-
|
|
261
|
-
|
|
257
|
+
layoutRef
|
|
258
|
+
},
|
|
259
|
+
props
|
|
262
260
|
)
|
|
261
|
+
)
|
|
263
262
|
}
|
|
264
263
|
|
|
265
264
|
const onInputBlur = (evt: NativeSyntheticEvent<TextInputFocusEventData>) => {
|
|
266
|
-
bindblur
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
{
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
cursor: cursorIndex.current
|
|
275
|
-
},
|
|
276
|
-
layoutRef
|
|
265
|
+
bindblur!(
|
|
266
|
+
getCustomEvent(
|
|
267
|
+
'blur',
|
|
268
|
+
evt,
|
|
269
|
+
{
|
|
270
|
+
detail: {
|
|
271
|
+
value: tmpValue.current || '',
|
|
272
|
+
cursor: cursorIndex.current
|
|
277
273
|
},
|
|
278
|
-
|
|
279
|
-
|
|
274
|
+
layoutRef
|
|
275
|
+
},
|
|
276
|
+
props
|
|
280
277
|
)
|
|
278
|
+
)
|
|
281
279
|
}
|
|
282
280
|
|
|
283
281
|
const onKeyPress = (evt: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
bindconfirm(
|
|
282
|
+
evt.nativeEvent.key === 'Enter' &&
|
|
283
|
+
bindconfirm!(
|
|
287
284
|
getCustomEvent(
|
|
288
285
|
'confirm',
|
|
289
286
|
evt,
|
|
@@ -299,21 +296,36 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
299
296
|
}
|
|
300
297
|
|
|
301
298
|
const onSubmitEditing = (evt: NativeSyntheticEvent<TextInputSubmitEditingEventData>) => {
|
|
302
|
-
bindconfirm
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
detail: {
|
|
310
|
-
value: tmpValue.current || ''
|
|
311
|
-
},
|
|
312
|
-
layoutRef
|
|
299
|
+
bindconfirm!(
|
|
300
|
+
getCustomEvent(
|
|
301
|
+
'confirm',
|
|
302
|
+
evt,
|
|
303
|
+
{
|
|
304
|
+
detail: {
|
|
305
|
+
value: tmpValue.current || ''
|
|
313
306
|
},
|
|
314
|
-
|
|
315
|
-
|
|
307
|
+
layoutRef
|
|
308
|
+
},
|
|
309
|
+
props
|
|
316
310
|
)
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const onSelectionChange = (evt: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
|
|
315
|
+
bindselectionchange!(
|
|
316
|
+
getCustomEvent(
|
|
317
|
+
'selectionchange',
|
|
318
|
+
evt,
|
|
319
|
+
{
|
|
320
|
+
detail: {
|
|
321
|
+
selectionStart: evt.nativeEvent.selection.start,
|
|
322
|
+
selectionEnd: evt.nativeEvent.selection.end
|
|
323
|
+
},
|
|
324
|
+
layoutRef
|
|
325
|
+
},
|
|
326
|
+
props
|
|
327
|
+
)
|
|
328
|
+
)
|
|
317
329
|
}
|
|
318
330
|
|
|
319
331
|
const onContentSizeChange = (evt: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => {
|
|
@@ -342,24 +354,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
342
354
|
}
|
|
343
355
|
}
|
|
344
356
|
|
|
345
|
-
const onSelectionChange = (evt: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
|
|
346
|
-
bindselectionchange &&
|
|
347
|
-
bindselectionchange(
|
|
348
|
-
getCustomEvent(
|
|
349
|
-
'selectionchange',
|
|
350
|
-
evt,
|
|
351
|
-
{
|
|
352
|
-
detail: {
|
|
353
|
-
selectionStart: evt.nativeEvent.selection.start,
|
|
354
|
-
selectionEnd: evt.nativeEvent.selection.end
|
|
355
|
-
},
|
|
356
|
-
layoutRef
|
|
357
|
-
},
|
|
358
|
-
props
|
|
359
|
-
)
|
|
360
|
-
)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
357
|
const resetValue = () => {
|
|
364
358
|
setInputValue('')
|
|
365
359
|
}
|
|
@@ -376,6 +370,14 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
376
370
|
}
|
|
377
371
|
}
|
|
378
372
|
|
|
373
|
+
useEffect(() => {
|
|
374
|
+
return () => {
|
|
375
|
+
if (formValuesMap && props.name) {
|
|
376
|
+
formValuesMap.delete(props.name)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}, [])
|
|
380
|
+
|
|
379
381
|
useUpdateEffect(() => {
|
|
380
382
|
if (!nodeRef?.current) {
|
|
381
383
|
return
|
|
@@ -396,7 +398,12 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
396
398
|
height: Math.max((composeStyle as any)?.minHeight || 35, contentHeight)
|
|
397
399
|
}
|
|
398
400
|
},
|
|
399
|
-
...layoutProps
|
|
401
|
+
...layoutProps,
|
|
402
|
+
onFocus: bindfocus && onInputFocus,
|
|
403
|
+
onBlur: bindblur && onInputBlur,
|
|
404
|
+
onKeyPress: bindconfirm && onKeyPress,
|
|
405
|
+
onSubmitEditing: bindconfirm && multiline && onSubmitEditing,
|
|
406
|
+
onSelectionChange: bindselectionchange && onSelectionChange
|
|
400
407
|
},
|
|
401
408
|
[],
|
|
402
409
|
{
|
|
@@ -423,16 +430,11 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
|
|
|
423
430
|
multiline={!!multiline}
|
|
424
431
|
onTextInput={onTextInput}
|
|
425
432
|
onChange={onChange}
|
|
426
|
-
onFocus={onInputFocus}
|
|
427
|
-
onBlur={onInputBlur}
|
|
428
|
-
onKeyPress={onKeyPress}
|
|
429
|
-
onSubmitEditing={onSubmitEditing}
|
|
430
433
|
onContentSizeChange={onContentSizeChange}
|
|
431
|
-
onSelectionChange={onSelectionChange}
|
|
432
434
|
/>
|
|
433
435
|
)
|
|
434
436
|
})
|
|
435
437
|
|
|
436
|
-
Input.displayName = '
|
|
438
|
+
Input.displayName = 'MpxInput'
|
|
437
439
|
|
|
438
440
|
export default Input
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ✘ for
|
|
3
3
|
*/
|
|
4
|
-
import { JSX, useRef, forwardRef, ReactNode } from 'react'
|
|
4
|
+
import { JSX, useRef, forwardRef, ReactNode, useCallback } from 'react'
|
|
5
5
|
import { View, ViewStyle, NativeSyntheticEvent } from 'react-native'
|
|
6
6
|
import { noop, warn } from '@mpxjs/utils'
|
|
7
7
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
@@ -25,6 +25,7 @@ export interface LabelProps {
|
|
|
25
25
|
const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
26
26
|
(labelProps, ref): JSX.Element => {
|
|
27
27
|
const { textProps, innerProps: props = {} } = splitProps(labelProps)
|
|
28
|
+
const propsRef = useRef<any>({})
|
|
28
29
|
|
|
29
30
|
const {
|
|
30
31
|
style = {},
|
|
@@ -32,10 +33,11 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
|
32
33
|
'external-var-context': externalVarContext,
|
|
33
34
|
'parent-font-size': parentFontSize,
|
|
34
35
|
'parent-width': parentWidth,
|
|
35
|
-
'parent-height': parentHeight
|
|
36
|
-
bindtap
|
|
36
|
+
'parent-height': parentHeight
|
|
37
37
|
} = props
|
|
38
38
|
|
|
39
|
+
propsRef.current = props
|
|
40
|
+
|
|
39
41
|
const defaultStyle = {
|
|
40
42
|
flexDirection: 'row'
|
|
41
43
|
}
|
|
@@ -69,10 +71,11 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
|
69
71
|
triggerChange: noop
|
|
70
72
|
})
|
|
71
73
|
|
|
72
|
-
const onTap = (evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const onTap = useCallback((evt: NativeSyntheticEvent<TouchEvent>) => {
|
|
75
|
+
const { bindtap } = propsRef.current
|
|
76
|
+
bindtap && bindtap(getCustomEvent('tap', evt, { layoutRef }, { props: propsRef.current }))
|
|
77
|
+
contextRef.current.triggerChange(evt)
|
|
78
|
+
}, [])
|
|
76
79
|
|
|
77
80
|
const innerProps = useInnerProps(
|
|
78
81
|
props,
|
|
@@ -106,6 +109,6 @@ const Label = forwardRef<HandlerRef<View, LabelProps>, LabelProps>(
|
|
|
106
109
|
}
|
|
107
110
|
)
|
|
108
111
|
|
|
109
|
-
Label.displayName = '
|
|
112
|
+
Label.displayName = 'MpxLabel'
|
|
110
113
|
|
|
111
114
|
export default Label
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* ✘ scale-area
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { View
|
|
6
|
-
import { JSX,
|
|
5
|
+
import { View } from 'react-native'
|
|
6
|
+
import { JSX, forwardRef, ReactNode, useRef, useMemo } from 'react'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
8
8
|
import useInnerProps from './getInnerListeners'
|
|
9
9
|
import { MovableAreaContext } from './context'
|
|
@@ -23,14 +23,7 @@ interface MovableAreaProps {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaProps>((props: MovableAreaProps, ref): JSX.Element => {
|
|
26
|
-
const { style = {},
|
|
27
|
-
const [areaWidth, setAreaWidth] = useState(0)
|
|
28
|
-
const [areaHeight, setAreaHeight] = useState(0)
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
setAreaWidth(width)
|
|
32
|
-
setAreaHeight(height)
|
|
33
|
-
}, [width, height])
|
|
26
|
+
const { style = {}, 'enable-var': enableVar, 'external-var-context': externalVarContext, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight } = props
|
|
34
27
|
|
|
35
28
|
const {
|
|
36
29
|
hasSelfPercent,
|
|
@@ -44,22 +37,21 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
|
|
|
44
37
|
const movableViewRef = useRef(null)
|
|
45
38
|
useNodesRef(props, ref, movableViewRef)
|
|
46
39
|
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
40
|
+
const contextValue = useMemo(() => ({
|
|
41
|
+
height: normalStyle.height || 10,
|
|
42
|
+
width: normalStyle.width || 10
|
|
43
|
+
}), [normalStyle.width, normalStyle.height])
|
|
52
44
|
|
|
53
|
-
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef
|
|
45
|
+
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: movableViewRef })
|
|
54
46
|
|
|
55
47
|
const innerProps = useInnerProps(props, {
|
|
56
|
-
style: { height:
|
|
48
|
+
style: { height: contextValue.height, width: contextValue.width, overflow: 'hidden', ...normalStyle, ...layoutStyle },
|
|
57
49
|
ref: movableViewRef,
|
|
58
50
|
...layoutProps
|
|
59
51
|
}, [], { layoutRef })
|
|
60
52
|
|
|
61
53
|
return (
|
|
62
|
-
<MovableAreaContext.Provider value={
|
|
54
|
+
<MovableAreaContext.Provider value={contextValue}>
|
|
63
55
|
<View
|
|
64
56
|
{...innerProps}
|
|
65
57
|
>
|
|
@@ -77,6 +69,6 @@ const _MovableArea = forwardRef<HandlerRef<View, MovableAreaProps>, MovableAreaP
|
|
|
77
69
|
)
|
|
78
70
|
})
|
|
79
71
|
|
|
80
|
-
_MovableArea.displayName = '
|
|
72
|
+
_MovableArea.displayName = 'MpxMovableArea'
|
|
81
73
|
|
|
82
74
|
export default _MovableArea
|