@mpxjs/webpack-plugin 2.9.66 → 2.9.69
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 +29 -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 +15 -10
- package/lib/platform/template/wx/component-config/canvas.js +8 -0
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- 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/processStyles.js +14 -4
- package/lib/react/processTemplate.js +2 -2
- package/lib/resolver/AddModePlugin.js +20 -7
- package/lib/runtime/components/react/context.ts +2 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +3 -12
- package/lib/runtime/components/react/dist/mpx-button.jsx +44 -9
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.js +60 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.js +84 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.js +87 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.js +15 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.js +28 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +343 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +214 -0
- package/lib/runtime/components/react/dist/mpx-canvas/utils.jsx +89 -0
- 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-picker-view-column.jsx +143 -84
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +69 -113
- 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 +49 -29
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +1 -1
- 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 +46 -27
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +20 -6
- package/lib/runtime/components/react/dist/pickerFaces.js +75 -0
- package/lib/runtime/components/react/dist/pickerOverlay.jsx +21 -0
- package/lib/runtime/components/react/dist/useAnimationHooks.js +96 -8
- package/lib/runtime/components/react/dist/utils.jsx +66 -6
- package/lib/runtime/components/react/getInnerListeners.ts +3 -16
- package/lib/runtime/components/react/mpx-button.tsx +42 -9
- package/lib/runtime/components/react/mpx-canvas/Bus.ts +70 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasGradient.ts +18 -0
- package/lib/runtime/components/react/mpx-canvas/CanvasRenderingContext2D.ts +87 -0
- package/lib/runtime/components/react/mpx-canvas/Image.ts +102 -0
- package/lib/runtime/components/react/mpx-canvas/ImageData.ts +23 -0
- package/lib/runtime/components/react/mpx-canvas/constructorsRegistry.ts +38 -0
- package/lib/runtime/components/react/mpx-canvas/html.ts +343 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +302 -0
- package/lib/runtime/components/react/mpx-canvas/utils.tsx +150 -0
- 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-picker-view-column.tsx +232 -103
- package/lib/runtime/components/react/mpx-picker-view.tsx +126 -122
- 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 +81 -36
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +2 -2
- 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 +58 -28
- package/lib/runtime/components/react/mpx-web-view.tsx +23 -6
- package/lib/runtime/components/react/pickerFaces.ts +104 -0
- package/lib/runtime/components/react/pickerOverlay.tsx +32 -0
- package/lib/runtime/components/react/types/common.ts +2 -0
- package/lib/runtime/components/react/types/global.d.ts +2 -0
- package/lib/runtime/components/react/useAnimationHooks.ts +97 -13
- package/lib/runtime/components/react/useNodesRef.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +94 -8
- 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 +47 -16
- package/lib/template-compiler/gen-node-react.js +2 -2
- 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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* ✔ lower-threshold
|
|
6
6
|
* ✔ scroll-top
|
|
7
7
|
* ✔ scroll-left
|
|
8
|
-
*
|
|
8
|
+
* ✔ scroll-into-view
|
|
9
9
|
* ✔ scroll-with-animation
|
|
10
10
|
* ✔ enable-back-to-top
|
|
11
11
|
* ✘ enable-passive
|
|
@@ -38,7 +38,7 @@ import { useAnimatedRef } from 'react-native-reanimated'
|
|
|
38
38
|
import { warn } from '@mpxjs/utils'
|
|
39
39
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
40
40
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
41
|
-
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren } from './utils'
|
|
41
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, flatGesture, GestureHandler } from './utils'
|
|
42
42
|
import { IntersectionObserverContext } from './context'
|
|
43
43
|
|
|
44
44
|
interface ScrollViewProps {
|
|
@@ -61,12 +61,15 @@ interface ScrollViewProps {
|
|
|
61
61
|
'scroll-top'?: number;
|
|
62
62
|
'scroll-left'?: number;
|
|
63
63
|
'enable-offset'?: boolean;
|
|
64
|
+
'scroll-into-view'?: string;
|
|
64
65
|
'enable-trigger-intersection-observer'?: boolean;
|
|
65
66
|
'enable-var'?: boolean;
|
|
66
67
|
'external-var-context'?: Record<string, any>;
|
|
67
68
|
'parent-font-size'?: number;
|
|
68
69
|
'parent-width'?: number;
|
|
69
70
|
'parent-height'?: number;
|
|
71
|
+
'wait-for'?: Array<GestureHandler>;
|
|
72
|
+
'simultaneous-handlers'?: Array<GestureHandler>;
|
|
70
73
|
bindscrolltoupper?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
71
74
|
bindscrolltolower?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
72
75
|
bindscroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
@@ -78,6 +81,7 @@ interface ScrollViewProps {
|
|
|
78
81
|
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
79
82
|
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
80
83
|
bindscrollend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
84
|
+
__selectRef?: (selector: string, nodeType: 'node' | 'component', all?: boolean) => HandlerRef<any, any>
|
|
81
85
|
}
|
|
82
86
|
type ScrollAdditionalProps = {
|
|
83
87
|
pinchGestureEnabled: boolean;
|
|
@@ -97,6 +101,7 @@ type ScrollAdditionalProps = {
|
|
|
97
101
|
bindtouchstart?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
98
102
|
bindtouchmove?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
99
103
|
bindtouchend?: (event: NativeSyntheticEvent<TouchEvent>) => void;
|
|
104
|
+
onScrollBeginDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
100
105
|
onScrollEndDrag?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
101
106
|
onMomentumScrollEnd?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
102
107
|
};
|
|
@@ -106,6 +111,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
106
111
|
enhanced = false,
|
|
107
112
|
bounces = true,
|
|
108
113
|
style = {},
|
|
114
|
+
binddragstart,
|
|
115
|
+
binddragging,
|
|
116
|
+
binddragend,
|
|
117
|
+
bindtouchstart,
|
|
118
|
+
bindtouchmove,
|
|
119
|
+
bindtouchend,
|
|
109
120
|
'scroll-x': scrollX = false,
|
|
110
121
|
'scroll-y': scrollY = false,
|
|
111
122
|
'enable-back-to-top': enableBackToTop = false,
|
|
@@ -118,13 +129,23 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
118
129
|
'refresher-default-style': refresherDefaultStyle,
|
|
119
130
|
'refresher-background': refresherBackground,
|
|
120
131
|
'show-scrollbar': showScrollbar = true,
|
|
132
|
+
'scroll-into-view': scrollIntoView = '',
|
|
133
|
+
'scroll-top': scrollTop = 0,
|
|
134
|
+
'scroll-left': scrollLeft = 0,
|
|
135
|
+
'refresher-triggered': refresherTriggered,
|
|
121
136
|
'enable-var': enableVar,
|
|
122
137
|
'external-var-context': externalVarContext,
|
|
123
138
|
'parent-font-size': parentFontSize,
|
|
124
139
|
'parent-width': parentWidth,
|
|
125
|
-
'parent-height': parentHeight
|
|
140
|
+
'parent-height': parentHeight,
|
|
141
|
+
'simultaneous-handlers': originSimultaneousHandlers,
|
|
142
|
+
'wait-for': waitFor,
|
|
143
|
+
__selectRef
|
|
126
144
|
} = props
|
|
127
145
|
|
|
146
|
+
const simultaneousHandlers = flatGesture(originSimultaneousHandlers)
|
|
147
|
+
const waitForHandlers = flatGesture(waitFor)
|
|
148
|
+
|
|
128
149
|
const [refreshing, setRefreshing] = useState(true)
|
|
129
150
|
|
|
130
151
|
const snapScrollTop = useRef(0)
|
|
@@ -144,6 +165,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
144
165
|
const initialTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
145
166
|
const intersectionObservers = useContext(IntersectionObserverContext)
|
|
146
167
|
|
|
168
|
+
const snapScrollIntoView = useRef<string>('')
|
|
169
|
+
|
|
147
170
|
const {
|
|
148
171
|
normalStyle,
|
|
149
172
|
hasVarDec,
|
|
@@ -166,7 +189,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
166
189
|
fastDeceleration: false,
|
|
167
190
|
decelerationDisabled: false,
|
|
168
191
|
scrollTo: scrollToOffset
|
|
169
|
-
}
|
|
192
|
+
},
|
|
193
|
+
gestureRef: scrollViewRef
|
|
170
194
|
})
|
|
171
195
|
|
|
172
196
|
const { layoutRef, layoutStyle, layoutProps } = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef: scrollViewRef, onLayout })
|
|
@@ -176,27 +200,41 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
176
200
|
}
|
|
177
201
|
useEffect(() => {
|
|
178
202
|
if (
|
|
179
|
-
snapScrollTop.current !==
|
|
180
|
-
snapScrollLeft.current !== props['scroll-left']
|
|
203
|
+
snapScrollTop.current !== scrollTop || snapScrollLeft.current !== scrollLeft
|
|
181
204
|
) {
|
|
182
|
-
snapScrollTop.current = props['scroll-top'] || 0
|
|
183
|
-
snapScrollLeft.current = props['scroll-left'] || 0
|
|
184
|
-
|
|
185
205
|
initialTimeout.current = setTimeout(() => {
|
|
186
|
-
scrollToOffset(
|
|
206
|
+
scrollToOffset(scrollLeft, scrollTop)
|
|
187
207
|
}, 0)
|
|
188
208
|
|
|
189
209
|
return () => {
|
|
190
210
|
initialTimeout.current && clearTimeout(initialTimeout.current)
|
|
191
211
|
}
|
|
192
212
|
}
|
|
193
|
-
}, [
|
|
213
|
+
}, [scrollTop, scrollLeft])
|
|
194
214
|
|
|
195
215
|
useEffect(() => {
|
|
196
|
-
if (refreshing !==
|
|
197
|
-
setRefreshing(!!
|
|
216
|
+
if (refreshing !== refresherTriggered) {
|
|
217
|
+
setRefreshing(!!refresherTriggered)
|
|
218
|
+
}
|
|
219
|
+
}, [refresherTriggered])
|
|
220
|
+
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
if (scrollIntoView && __selectRef && snapScrollIntoView.current !== scrollIntoView) {
|
|
223
|
+
snapScrollIntoView.current = scrollIntoView || ''
|
|
224
|
+
setTimeout(() => {
|
|
225
|
+
const refs = __selectRef(`#${scrollIntoView}`, 'node')
|
|
226
|
+
if (refs) {
|
|
227
|
+
const { nodeRef } = refs.getNodeInstance()
|
|
228
|
+
nodeRef.current?.measureLayout(
|
|
229
|
+
scrollViewRef.current,
|
|
230
|
+
(left: number, top:number) => {
|
|
231
|
+
scrollToOffset(left, top)
|
|
232
|
+
}
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
})
|
|
198
236
|
}
|
|
199
|
-
}, [
|
|
237
|
+
}, [scrollIntoView])
|
|
200
238
|
|
|
201
239
|
function selectLength (size: { height: number; width: number }) {
|
|
202
240
|
return !scrollX ? size.height : size.width
|
|
@@ -322,6 +360,8 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
322
360
|
scrollViewRef.current.scrollTo({ x, y, animated: !!scrollWithAnimation })
|
|
323
361
|
scrollOptions.current.scrollLeft = x
|
|
324
362
|
scrollOptions.current.scrollTop = y
|
|
363
|
+
snapScrollLeft.current = x
|
|
364
|
+
snapScrollTop.current = y
|
|
325
365
|
}
|
|
326
366
|
}
|
|
327
367
|
|
|
@@ -334,7 +374,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
334
374
|
}
|
|
335
375
|
|
|
336
376
|
function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
|
|
337
|
-
const {
|
|
377
|
+
const { bindtouchstart } = props
|
|
338
378
|
bindtouchstart && bindtouchstart(e)
|
|
339
379
|
if (enhanced) {
|
|
340
380
|
binddragstart &&
|
|
@@ -350,7 +390,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
350
390
|
}
|
|
351
391
|
}
|
|
352
392
|
function onScrollTouchMove (e: NativeSyntheticEvent<TouchEvent>) {
|
|
353
|
-
const { binddragging, bindtouchmove, enhanced } = props
|
|
354
393
|
bindtouchmove && bindtouchmove(e)
|
|
355
394
|
if (enhanced) {
|
|
356
395
|
binddragging &&
|
|
@@ -366,27 +405,27 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
366
405
|
}
|
|
367
406
|
}
|
|
368
407
|
|
|
369
|
-
function
|
|
370
|
-
|
|
408
|
+
function onScrollTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
|
|
409
|
+
bindtouchend && bindtouchend(e)
|
|
371
410
|
if (enhanced) {
|
|
372
|
-
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
373
|
-
const { width: scrollWidth, height: scrollHeight } = e.nativeEvent.contentSize
|
|
374
411
|
binddragend &&
|
|
375
412
|
binddragend(
|
|
376
413
|
getCustomEvent('dragend', e, {
|
|
377
414
|
detail: {
|
|
378
|
-
scrollLeft: scrollLeft,
|
|
379
|
-
scrollTop: scrollTop
|
|
380
|
-
scrollHeight,
|
|
381
|
-
scrollWidth
|
|
415
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
416
|
+
scrollTop: scrollOptions.current.scrollTop || 0
|
|
382
417
|
},
|
|
383
418
|
layoutRef
|
|
384
419
|
}, props)
|
|
385
420
|
)
|
|
386
|
-
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
387
421
|
}
|
|
388
422
|
}
|
|
389
423
|
|
|
424
|
+
function onScrollDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
425
|
+
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
426
|
+
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
427
|
+
}
|
|
428
|
+
|
|
390
429
|
let scrollAdditionalProps: ScrollAdditionalProps = {
|
|
391
430
|
style: { ...innerStyle, ...layoutStyle },
|
|
392
431
|
pinchGestureEnabled: false,
|
|
@@ -399,11 +438,15 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
399
438
|
ref: scrollViewRef,
|
|
400
439
|
onScroll: onScroll,
|
|
401
440
|
onContentSizeChange: onContentSizeChange,
|
|
402
|
-
bindtouchstart: onScrollTouchStart,
|
|
403
|
-
bindtouchmove: onScrollTouchMove,
|
|
404
|
-
|
|
441
|
+
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) ? onScrollTouchStart : undefined,
|
|
442
|
+
bindtouchmove: ((enhanced && binddragging) || bindtouchend) ? onScrollTouchMove : undefined,
|
|
443
|
+
bindtouchend: ((enhanced && binddragend) || bindtouchend) ? onScrollTouchEnd : undefined,
|
|
444
|
+
onScrollBeginDrag: onScrollDrag,
|
|
445
|
+
onScrollEndDrag: onScrollDrag,
|
|
405
446
|
onMomentumScrollEnd: onScrollEnd,
|
|
406
|
-
...layoutProps
|
|
447
|
+
...layoutProps,
|
|
448
|
+
...(simultaneousHandlers ? { simultaneousHandlers } : {}),
|
|
449
|
+
...(waitForHandlers ? { waitFor: waitForHandlers } : {})
|
|
407
450
|
}
|
|
408
451
|
if (enhanced) {
|
|
409
452
|
scrollAdditionalProps = {
|
|
@@ -412,7 +455,9 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
412
455
|
pagingEnabled
|
|
413
456
|
}
|
|
414
457
|
}
|
|
458
|
+
|
|
415
459
|
const innerProps = useInnerProps(props, scrollAdditionalProps, [
|
|
460
|
+
'id',
|
|
416
461
|
'scroll-x',
|
|
417
462
|
'scroll-y',
|
|
418
463
|
'enable-back-to-top',
|
|
@@ -449,12 +494,12 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
449
494
|
{...innerProps}
|
|
450
495
|
refreshControl={refresherEnabled
|
|
451
496
|
? (
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
497
|
+
<RefreshControl
|
|
498
|
+
progressBackgroundColor={refresherBackground}
|
|
499
|
+
refreshing={refreshing}
|
|
500
|
+
onRefresh={onRefresh}
|
|
501
|
+
{...(refresherDefaultStyle && refresherDefaultStyle !== 'none' ? { colors: refreshColor[refresherDefaultStyle] } : {})}
|
|
502
|
+
/>
|
|
458
503
|
)
|
|
459
504
|
: undefined}
|
|
460
505
|
>
|
|
@@ -473,6 +518,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
473
518
|
)
|
|
474
519
|
})
|
|
475
520
|
|
|
476
|
-
_ScrollView.displayName = '
|
|
521
|
+
_ScrollView.displayName = 'MpxScrollView'
|
|
477
522
|
|
|
478
523
|
export default _ScrollView
|
|
@@ -488,7 +488,7 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
488
488
|
} else if (i === pages.length - 1 && typeof width === 'number') {
|
|
489
489
|
nextMargin && (extraStyle.marginRight = nextMargin)
|
|
490
490
|
}
|
|
491
|
-
return (<View style={[pageStyle, styles.slide, extraStyle]} key={
|
|
491
|
+
return (<View style={[pageStyle, styles.slide, extraStyle]} key={'page' + i}>
|
|
492
492
|
{wrapChildren(
|
|
493
493
|
{
|
|
494
494
|
children: children[+page]
|
|
@@ -520,6 +520,6 @@ const _Carouse = forwardRef<HandlerRef<ScrollView & View, CarouseProps>, Carouse
|
|
|
520
520
|
</View>)
|
|
521
521
|
})
|
|
522
522
|
|
|
523
|
-
_Carouse.displayName = '
|
|
523
|
+
_Carouse.displayName = 'MpxCarouse'
|
|
524
524
|
|
|
525
525
|
export default _Carouse
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* ✔ disabled
|
|
5
5
|
* ✔ color
|
|
6
6
|
*/
|
|
7
|
-
import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent
|
|
7
|
+
import { Switch, SwitchProps, ViewStyle, NativeSyntheticEvent } from 'react-native'
|
|
8
8
|
import { useRef, useEffect, forwardRef, JSX, useState, useContext } from 'react'
|
|
9
9
|
import { warn } from '@mpxjs/utils'
|
|
10
10
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
@@ -111,6 +111,14 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
return () => {
|
|
116
|
+
if (formValuesMap && props.name) {
|
|
117
|
+
formValuesMap.delete(props.name)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, [])
|
|
121
|
+
|
|
114
122
|
const innerProps = useInnerProps(props, {
|
|
115
123
|
ref: nodeRef,
|
|
116
124
|
style: { ...normalStyle, ...layoutStyle },
|
|
@@ -144,6 +152,6 @@ const _Switch = forwardRef<HandlerRef<Switch, _SwitchProps>, _SwitchProps>((prop
|
|
|
144
152
|
/>
|
|
145
153
|
})
|
|
146
154
|
|
|
147
|
-
_Switch.displayName = '
|
|
155
|
+
_Switch.displayName = 'MpxSwitch'
|
|
148
156
|
|
|
149
157
|
export default _Switch
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* ✔ hover-start-time
|
|
5
5
|
* ✔ hover-stay-time
|
|
6
6
|
*/
|
|
7
|
-
import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle,
|
|
8
|
-
import { useRef, useState, useEffect, forwardRef, ReactNode, JSX
|
|
7
|
+
import { View, TextStyle, NativeSyntheticEvent, ViewProps, ImageStyle, StyleSheet, Image, LayoutChangeEvent } from 'react-native'
|
|
8
|
+
import { useRef, useState, useEffect, forwardRef, ReactNode, JSX } from 'react'
|
|
9
9
|
import useInnerProps from './getInnerListeners'
|
|
10
10
|
import Animated from 'react-native-reanimated'
|
|
11
11
|
import useAnimationHooks from './useAnimationHooks'
|
|
12
12
|
import type { AnimationProp } from './useAnimationHooks'
|
|
13
13
|
import { ExtendedViewStyle } from './types/common'
|
|
14
14
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
15
|
-
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout } from './utils'
|
|
15
|
+
import { parseUrl, PERCENT_REGEX, splitStyle, splitProps, useTransformStyle, wrapChildren, useLayout, renderImage, pickStyle } from './utils'
|
|
16
16
|
import LinearGradient from 'react-native-linear-gradient'
|
|
17
17
|
|
|
18
18
|
export interface _ViewProps extends ViewProps {
|
|
@@ -24,6 +24,7 @@ export interface _ViewProps extends ViewProps {
|
|
|
24
24
|
'hover-stay-time'?: number
|
|
25
25
|
'enable-background'?: boolean
|
|
26
26
|
'enable-var'?: boolean
|
|
27
|
+
'enable-fast-image'?: boolean
|
|
27
28
|
'external-var-context'?: Record<string, any>
|
|
28
29
|
'parent-font-size'?: number
|
|
29
30
|
'parent-width'?: number
|
|
@@ -76,9 +77,11 @@ type PreImageInfo = {
|
|
|
76
77
|
type ImageProps = {
|
|
77
78
|
style: ImageStyle,
|
|
78
79
|
src?: string,
|
|
80
|
+
source?: {uri: string },
|
|
79
81
|
colors: Array<string>,
|
|
80
82
|
locations?: Array<number>
|
|
81
83
|
angle?: number
|
|
84
|
+
resizeMode?: 'cover' | 'stretch'
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
const linearMap = new Map([
|
|
@@ -280,13 +283,14 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
|
|
|
280
283
|
if (!dimensions) return
|
|
281
284
|
} else { // 数值类型 ImageStyle
|
|
282
285
|
// 数值类型设置为 stretch
|
|
283
|
-
|
|
286
|
+
imageProps.resizeMode = 'stretch'
|
|
284
287
|
dimensions = {
|
|
285
288
|
width: isPercent(width) ? width : +width,
|
|
286
289
|
height: isPercent(height) ? height : +height
|
|
287
290
|
} as { width: NumberVal, height: NumberVal }
|
|
288
291
|
}
|
|
289
292
|
}
|
|
293
|
+
|
|
290
294
|
// 样式合并
|
|
291
295
|
imageProps.style = {
|
|
292
296
|
...imageProps.style as ImageStyle,
|
|
@@ -296,8 +300,9 @@ function backgroundSize (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
|
|
|
296
300
|
|
|
297
301
|
// background-image转换为source
|
|
298
302
|
function backgroundImage (imageProps: ImageProps, preImageInfo: PreImageInfo) {
|
|
299
|
-
|
|
300
|
-
|
|
303
|
+
const src = preImageInfo.src
|
|
304
|
+
if (src) {
|
|
305
|
+
imageProps.source = { uri: src }
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
308
|
|
|
@@ -326,8 +331,8 @@ function linearGradient (imageProps: ImageProps, preImageInfo: PreImageInfo, ima
|
|
|
326
331
|
const imageStyleToProps = (preImageInfo: PreImageInfo, imageSize: Size, layoutInfo: Size) => {
|
|
327
332
|
// 初始化
|
|
328
333
|
const imageProps: ImageProps = {
|
|
334
|
+
resizeMode: 'cover',
|
|
329
335
|
style: {
|
|
330
|
-
resizeMode: 'cover' as ImageResizeMode,
|
|
331
336
|
position: 'absolute'
|
|
332
337
|
// ...StyleSheet.absoluteFillObject
|
|
333
338
|
},
|
|
@@ -533,7 +538,26 @@ function isDiagonalAngle (linearInfo?: LinearInfo): boolean {
|
|
|
533
538
|
return !!(linearInfo?.direction && diagonalAngleMap[linearInfo.direction])
|
|
534
539
|
}
|
|
535
540
|
|
|
536
|
-
function
|
|
541
|
+
function inheritStyle (innerStyle: ExtendedViewStyle = {}) {
|
|
542
|
+
const { borderWidth, borderRadius } = innerStyle
|
|
543
|
+
const borderStyles = ['borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomRightRadius', 'borderBottomLeftRadius']
|
|
544
|
+
return pickStyle(innerStyle,
|
|
545
|
+
borderStyles,
|
|
546
|
+
borderWidth && borderRadius
|
|
547
|
+
? (key, val) => {
|
|
548
|
+
// 盒子内圆角borderWith与borderRadius的关系
|
|
549
|
+
// 当borderRadius 小于 当borderWith 内边框为直角
|
|
550
|
+
// 当borderRadius 大于等于 当borderWith 内边框为圆角
|
|
551
|
+
if (borderStyles.includes(key)) {
|
|
552
|
+
const borderVal = +val - borderWidth
|
|
553
|
+
return borderVal > 0 ? borderVal : 0
|
|
554
|
+
}
|
|
555
|
+
return val
|
|
556
|
+
}
|
|
557
|
+
: undefined)
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function wrapImage (imageStyle?: ExtendedViewStyle, innerStyle?: Record<string, any>, enableFastImage?: boolean) {
|
|
537
561
|
// 预处理数据
|
|
538
562
|
const preImageInfo: PreImageInfo = preParseImage(imageStyle)
|
|
539
563
|
// 预解析
|
|
@@ -616,9 +640,9 @@ function wrapImage (imageStyle?: ExtendedViewStyle) {
|
|
|
616
640
|
}
|
|
617
641
|
}
|
|
618
642
|
|
|
619
|
-
return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
|
|
643
|
+
return <View key='backgroundImage' {...needLayout ? { onLayout } : null} style={{ ...inheritStyle(innerStyle), ...StyleSheet.absoluteFillObject, overflow: 'hidden' }}>
|
|
620
644
|
{show && type === 'linear' && <LinearGradient useAngle={true} {...imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size)} /> }
|
|
621
|
-
{show && type === 'image' &&
|
|
645
|
+
{show && type === 'image' && (renderImage(imageStyleToProps(preImageInfo, sizeInfo.current as Size, layoutInfo.current as Size), enableFastImage))}
|
|
622
646
|
</View>
|
|
623
647
|
}
|
|
624
648
|
|
|
@@ -629,9 +653,11 @@ interface WrapChildrenConfig {
|
|
|
629
653
|
backgroundStyle?: ExtendedViewStyle
|
|
630
654
|
varContext?: Record<string, any>
|
|
631
655
|
textProps?: Record<string, any>
|
|
656
|
+
innerStyle?: Record<string, any>
|
|
657
|
+
enableFastImage?: boolean
|
|
632
658
|
}
|
|
633
659
|
|
|
634
|
-
function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps }: WrapChildrenConfig) {
|
|
660
|
+
function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, textStyle, backgroundStyle, varContext, textProps, innerStyle, enableFastImage }: WrapChildrenConfig) {
|
|
635
661
|
const children = wrapChildren(props, {
|
|
636
662
|
hasVarDec,
|
|
637
663
|
varContext,
|
|
@@ -640,7 +666,7 @@ function wrapWithChildren (props: _ViewProps, { hasVarDec, enableBackground, tex
|
|
|
640
666
|
})
|
|
641
667
|
|
|
642
668
|
return [
|
|
643
|
-
enableBackground ? wrapImage(backgroundStyle) : null,
|
|
669
|
+
enableBackground ? wrapImage(backgroundStyle, innerStyle, enableFastImage) : null,
|
|
644
670
|
children
|
|
645
671
|
]
|
|
646
672
|
}
|
|
@@ -655,6 +681,7 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
655
681
|
'enable-var': enableVar,
|
|
656
682
|
'external-var-context': externalVarContext,
|
|
657
683
|
'enable-background': enableBackground,
|
|
684
|
+
'enable-fast-image': enableFastImage,
|
|
658
685
|
'enable-animation': enableAnimation,
|
|
659
686
|
'parent-font-size': parentFontSize,
|
|
660
687
|
'parent-width': parentWidth,
|
|
@@ -755,9 +782,22 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
755
782
|
} = useLayout({ props, hasSelfPercent, setWidth, setHeight, nodeRef })
|
|
756
783
|
|
|
757
784
|
const viewStyle = Object.assign({}, innerStyle, layoutStyle)
|
|
785
|
+
|
|
786
|
+
enableAnimation = enableAnimation || !!animation
|
|
787
|
+
const enableAnimationRef = useRef(enableAnimation)
|
|
788
|
+
if (enableAnimationRef.current !== enableAnimation) {
|
|
789
|
+
throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
|
|
790
|
+
}
|
|
791
|
+
const finalStyle = enableAnimation
|
|
792
|
+
? useAnimationHooks({
|
|
793
|
+
animation,
|
|
794
|
+
style: viewStyle
|
|
795
|
+
})
|
|
796
|
+
: viewStyle
|
|
797
|
+
|
|
758
798
|
const innerProps = useInnerProps(props, {
|
|
759
799
|
ref: nodeRef,
|
|
760
|
-
style:
|
|
800
|
+
style: finalStyle,
|
|
761
801
|
...layoutProps,
|
|
762
802
|
...(hoverStyle && {
|
|
763
803
|
bindtouchstart: onTouchStart,
|
|
@@ -772,29 +812,19 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
772
812
|
layoutRef
|
|
773
813
|
})
|
|
774
814
|
|
|
775
|
-
enableAnimation = enableAnimation || !!animation
|
|
776
|
-
const enableAnimationRef = useRef(enableAnimation)
|
|
777
|
-
if (enableAnimationRef.current !== enableAnimation) {
|
|
778
|
-
throw new Error('[Mpx runtime error]: animation use should be stable in the component lifecycle, or you can set [enable-animation] with true.')
|
|
779
|
-
}
|
|
780
|
-
const finalStyle = enableAnimation
|
|
781
|
-
? useAnimationHooks({
|
|
782
|
-
animation,
|
|
783
|
-
style: viewStyle
|
|
784
|
-
})
|
|
785
|
-
: viewStyle
|
|
786
815
|
const childNode = wrapWithChildren(props, {
|
|
787
816
|
hasVarDec,
|
|
788
817
|
enableBackground: enableBackgroundRef.current,
|
|
789
818
|
textStyle,
|
|
790
819
|
backgroundStyle,
|
|
791
820
|
varContext: varContextRef.current,
|
|
792
|
-
textProps
|
|
821
|
+
textProps,
|
|
822
|
+
innerStyle,
|
|
823
|
+
enableFastImage
|
|
793
824
|
})
|
|
794
|
-
return
|
|
825
|
+
return enableAnimation
|
|
795
826
|
? (<Animated.View
|
|
796
827
|
{...innerProps}
|
|
797
|
-
style={finalStyle}
|
|
798
828
|
>
|
|
799
829
|
{childNode}
|
|
800
830
|
</Animated.View>)
|
|
@@ -805,6 +835,6 @@ const _View = forwardRef<HandlerRef<View, _ViewProps>, _ViewProps>((viewProps, r
|
|
|
805
835
|
</View>)
|
|
806
836
|
})
|
|
807
837
|
|
|
808
|
-
_View.displayName = '
|
|
838
|
+
_View.displayName = 'MpxView'
|
|
809
839
|
|
|
810
840
|
export default _View
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { forwardRef, JSX, useEffect, useRef } from 'react'
|
|
1
|
+
import { forwardRef, JSX, useEffect, useRef, useContext, useMemo } from 'react'
|
|
2
2
|
import { noop, warn } from '@mpxjs/utils'
|
|
3
3
|
import { Portal } from '@ant-design/react-native'
|
|
4
4
|
import { getCustomEvent } from './getInnerListeners'
|
|
5
5
|
import { promisify, redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
6
6
|
import { WebView } from 'react-native-webview'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
8
|
-
import {
|
|
8
|
+
import { getCurrentPage } from './utils'
|
|
9
|
+
import { WebViewNavigationEvent, WebViewErrorEvent, WebViewMessageEvent, WebViewNavigation } from 'react-native-webview/lib/WebViewTypes'
|
|
10
|
+
import { RouteContext } from './context'
|
|
9
11
|
|
|
10
12
|
type OnMessageCallbackEvent = {
|
|
11
13
|
detail: {
|
|
@@ -51,6 +53,9 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
51
53
|
if (props.style) {
|
|
52
54
|
warn('The web-view component does not support the style prop.')
|
|
53
55
|
}
|
|
56
|
+
const pageId = useContext(RouteContext)
|
|
57
|
+
const currentPage = useMemo(() => getCurrentPage(pageId), [pageId])
|
|
58
|
+
|
|
54
59
|
const defaultWebViewStyle = {
|
|
55
60
|
position: 'absolute' as 'absolute' | 'relative' | 'static',
|
|
56
61
|
left: 0 as number,
|
|
@@ -64,17 +69,23 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
64
69
|
defaultStyle: defaultWebViewStyle
|
|
65
70
|
})
|
|
66
71
|
|
|
67
|
-
const _messageList
|
|
72
|
+
const _messageList = useRef<any[]>([])
|
|
68
73
|
const handleUnload = () => {
|
|
69
74
|
// 这里是 WebView 销毁前执行的逻辑
|
|
70
75
|
bindmessage(getCustomEvent('messsage', {}, {
|
|
71
76
|
detail: {
|
|
72
|
-
data: _messageList
|
|
77
|
+
data: _messageList.current
|
|
73
78
|
},
|
|
74
79
|
layoutRef: webViewRef
|
|
75
80
|
}))
|
|
76
81
|
}
|
|
77
82
|
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (currentPage) {
|
|
85
|
+
currentPage.__webViewUrl = src
|
|
86
|
+
}
|
|
87
|
+
}, [src, currentPage])
|
|
88
|
+
|
|
78
89
|
useEffect(() => {
|
|
79
90
|
// 组件卸载时执行
|
|
80
91
|
return () => {
|
|
@@ -101,6 +112,11 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
101
112
|
}
|
|
102
113
|
binderror(result)
|
|
103
114
|
}
|
|
115
|
+
const _changeUrl = function (navState: WebViewNavigation) {
|
|
116
|
+
if (currentPage) {
|
|
117
|
+
currentPage.__webViewUrl = navState.url
|
|
118
|
+
}
|
|
119
|
+
}
|
|
104
120
|
const _message = function (res: WebViewMessageEvent) {
|
|
105
121
|
let data: MessageData = {}
|
|
106
122
|
let asyncCallback
|
|
@@ -116,7 +132,7 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
116
132
|
const postData: PayloadData = data.payload || {}
|
|
117
133
|
switch (data.type) {
|
|
118
134
|
case 'postMessage':
|
|
119
|
-
_messageList.push(postData.data)
|
|
135
|
+
_messageList.current.push(postData.data)
|
|
120
136
|
asyncCallback = Promise.resolve({
|
|
121
137
|
errMsg: 'invokeWebappApi:ok'
|
|
122
138
|
})
|
|
@@ -157,11 +173,12 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
|
|
|
157
173
|
onLoad={_load}
|
|
158
174
|
onError={_error}
|
|
159
175
|
onMessage={_message}
|
|
176
|
+
onNavigationStateChange={_changeUrl}
|
|
160
177
|
javaScriptEnabled={true}
|
|
161
178
|
></WebView>
|
|
162
179
|
</Portal>)
|
|
163
180
|
})
|
|
164
181
|
|
|
165
|
-
_WebView.displayName = '
|
|
182
|
+
_WebView.displayName = 'MpxWebview'
|
|
166
183
|
|
|
167
184
|
export default _WebView
|