@mpxjs/webpack-plugin 2.10.14 → 2.10.15-2
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 +23 -1
- package/lib/platform/style/wx/index.js +17 -0
- package/lib/react/processScript.js +4 -2
- package/lib/react/script-helper.js +3 -3
- package/lib/runtime/components/react/dist/mpx-async-suspense.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +16 -9
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +38 -36
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +32 -34
- package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -2
- package/lib/runtime/components/react/mpx-movable-view.tsx +17 -11
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +3 -3
- package/lib/runtime/components/react/mpx-scroll-view.tsx +45 -41
- package/lib/runtime/components/react/mpx-swiper.tsx +32 -32
- package/lib/runtime/optionProcessor.js +11 -3
- package/lib/runtime/optionProcessorReact.js +2 -2
- package/lib/web/processMainScript.js +2 -1
- package/package.json +2 -2
- package/LICENSE +0 -433
|
@@ -22,7 +22,7 @@ import { StyleSheet, View, LayoutChangeEvent } from 'react-native'
|
|
|
22
22
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
23
23
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
24
24
|
import { MovableAreaContext } from './context'
|
|
25
|
-
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture, extendObject, omit, useNavigation } from './utils'
|
|
25
|
+
import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, GestureHandler, flatGesture, extendObject, omit, useNavigation, useRunOnJSCallback } from './utils'
|
|
26
26
|
import { GestureDetector, Gesture, GestureTouchEvent, GestureStateChangeEvent, PanGestureHandlerEventPayload, PanGesture } from 'react-native-gesture-handler'
|
|
27
27
|
import Animated, {
|
|
28
28
|
useSharedValue,
|
|
@@ -30,7 +30,6 @@ import Animated, {
|
|
|
30
30
|
withDecay,
|
|
31
31
|
runOnJS,
|
|
32
32
|
runOnUI,
|
|
33
|
-
useAnimatedReaction,
|
|
34
33
|
withSpring
|
|
35
34
|
} from 'react-native-reanimated'
|
|
36
35
|
import { collectDataset, noop } from '@mpxjs/utils'
|
|
@@ -87,7 +86,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
87
86
|
const layoutRef = useRef<any>({})
|
|
88
87
|
const changeSource = useRef<any>('')
|
|
89
88
|
const hasLayoutRef = useRef(false)
|
|
90
|
-
|
|
91
89
|
const propsRef = useRef<any>({})
|
|
92
90
|
propsRef.current = (props || {}) as MovableViewProps
|
|
93
91
|
|
|
@@ -208,7 +206,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
208
206
|
const now = Date.now()
|
|
209
207
|
if (now - lastChangeTime.value >= changeThrottleTime) {
|
|
210
208
|
lastChangeTime.value = now
|
|
211
|
-
runOnJS(
|
|
209
|
+
runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type })
|
|
212
210
|
}
|
|
213
211
|
}, [changeThrottleTime])
|
|
214
212
|
|
|
@@ -233,7 +231,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
233
231
|
: newY
|
|
234
232
|
}
|
|
235
233
|
if (bindchange) {
|
|
236
|
-
runOnJS(
|
|
234
|
+
runOnJS(runOnJSCallback)('handleTriggerChange', {
|
|
237
235
|
x: newX,
|
|
238
236
|
y: newY,
|
|
239
237
|
type: 'setData'
|
|
@@ -408,13 +406,21 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
408
406
|
catchtouchend && catchtouchend(e)
|
|
409
407
|
}
|
|
410
408
|
|
|
409
|
+
const runOnJSCallbackRef = useRef({
|
|
410
|
+
handleTriggerChange,
|
|
411
|
+
triggerStartOnJS,
|
|
412
|
+
triggerMoveOnJS,
|
|
413
|
+
triggerEndOnJS
|
|
414
|
+
})
|
|
415
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
|
|
416
|
+
|
|
411
417
|
const gesture = useMemo(() => {
|
|
412
418
|
const handleTriggerMove = (e: GestureTouchEvent) => {
|
|
413
419
|
'worklet'
|
|
414
420
|
const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove
|
|
415
421
|
const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove
|
|
416
422
|
if (hasTouchmove || hasCatchTouchmove) {
|
|
417
|
-
runOnJS(
|
|
423
|
+
runOnJS(runOnJSCallback)('triggerMoveOnJS', {
|
|
418
424
|
e,
|
|
419
425
|
touchEvent: touchEvent.value,
|
|
420
426
|
hasTouchmove,
|
|
@@ -433,7 +439,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
433
439
|
y: changedTouches.y
|
|
434
440
|
}
|
|
435
441
|
if (bindtouchstart || catchtouchstart) {
|
|
436
|
-
runOnJS(
|
|
442
|
+
runOnJS(runOnJSCallback)('triggerStartOnJS', { e })
|
|
437
443
|
}
|
|
438
444
|
})
|
|
439
445
|
.onStart(() => {
|
|
@@ -487,7 +493,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
487
493
|
isFirstTouch.value = true
|
|
488
494
|
isMoving.value = false
|
|
489
495
|
if (bindtouchend || catchtouchend) {
|
|
490
|
-
runOnJS(
|
|
496
|
+
runOnJS(runOnJSCallback)('triggerEndOnJS', { e })
|
|
491
497
|
}
|
|
492
498
|
})
|
|
493
499
|
.onEnd((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
@@ -515,7 +521,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
515
521
|
: y
|
|
516
522
|
}
|
|
517
523
|
if (bindchange) {
|
|
518
|
-
runOnJS(
|
|
524
|
+
runOnJS(runOnJSCallback)('handleTriggerChange', {
|
|
519
525
|
x,
|
|
520
526
|
y
|
|
521
527
|
})
|
|
@@ -532,7 +538,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
532
538
|
}, () => {
|
|
533
539
|
xInertialMotion.value = false
|
|
534
540
|
if (bindchange) {
|
|
535
|
-
runOnJS(
|
|
541
|
+
runOnJS(runOnJSCallback)('handleTriggerChange', {
|
|
536
542
|
x: offsetX.value,
|
|
537
543
|
y: offsetY.value
|
|
538
544
|
})
|
|
@@ -548,7 +554,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
|
|
|
548
554
|
}, () => {
|
|
549
555
|
yInertialMotion.value = false
|
|
550
556
|
if (bindchange) {
|
|
551
|
-
runOnJS(
|
|
557
|
+
runOnJS(runOnJSCallback)('handleTriggerChange', {
|
|
552
558
|
x: offsetX.value,
|
|
553
559
|
y: offsetY.value
|
|
554
560
|
})
|
|
@@ -223,8 +223,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
223
223
|
|
|
224
224
|
const onScroll = useCallback((e: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
225
225
|
// 全局注册的振动触感 hook
|
|
226
|
-
const
|
|
227
|
-
if (typeof
|
|
226
|
+
const onPickerVibrate = global.__mpx?.config?.rnConfig?.onPickerVibrate
|
|
227
|
+
if (typeof onPickerVibrate !== 'function') {
|
|
228
228
|
return
|
|
229
229
|
}
|
|
230
230
|
const { y } = e.nativeEvent.contentOffset
|
|
@@ -238,7 +238,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
|
|
|
238
238
|
y: currentId * itemRawH
|
|
239
239
|
}
|
|
240
240
|
// vibrateShort({ type: 'selection' })
|
|
241
|
-
|
|
241
|
+
onPickerVibrate()
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
}
|
|
@@ -38,7 +38,7 @@ import Animated, { useSharedValue, withTiming, useAnimatedStyle, runOnJS } from
|
|
|
38
38
|
import { warn, hasOwn } from '@mpxjs/utils'
|
|
39
39
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
40
40
|
import useNodesRef, { HandlerRef } from './useNodesRef'
|
|
41
|
-
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler, HIDDEN_STYLE } from './utils'
|
|
41
|
+
import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, GestureHandler, HIDDEN_STYLE, useRunOnJSCallback } from './utils'
|
|
42
42
|
import { IntersectionObserverContext, ScrollViewContext } from './context'
|
|
43
43
|
import Portal from './mpx-portal'
|
|
44
44
|
|
|
@@ -210,6 +210,15 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
210
210
|
const { textStyle, innerStyle = {} } = splitStyle(normalStyle)
|
|
211
211
|
|
|
212
212
|
const scrollViewRef = useRef<ScrollView>(null)
|
|
213
|
+
|
|
214
|
+
const runOnJSCallbackRef = useRef({
|
|
215
|
+
setEnableScroll,
|
|
216
|
+
setScrollBounces,
|
|
217
|
+
setRefreshing,
|
|
218
|
+
onRefresh
|
|
219
|
+
})
|
|
220
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
|
|
221
|
+
|
|
213
222
|
useNodesRef(props, ref, scrollViewRef, {
|
|
214
223
|
style: normalStyle,
|
|
215
224
|
scrollOffset: scrollOptions,
|
|
@@ -446,22 +455,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
446
455
|
}
|
|
447
456
|
}
|
|
448
457
|
|
|
449
|
-
function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
|
|
450
|
-
const { bindtouchstart } = props
|
|
451
|
-
bindtouchstart && bindtouchstart(e)
|
|
452
|
-
if (enhanced) {
|
|
453
|
-
binddragstart &&
|
|
454
|
-
binddragstart(
|
|
455
|
-
getCustomEvent('dragstart', e, {
|
|
456
|
-
detail: {
|
|
457
|
-
scrollLeft: scrollOptions.current.scrollLeft,
|
|
458
|
-
scrollTop: scrollOptions.current.scrollTop
|
|
459
|
-
},
|
|
460
|
-
layoutRef
|
|
461
|
-
}, props)
|
|
462
|
-
)
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
458
|
function onScrollTouchMove (e: NativeSyntheticEvent<TouchEvent>) {
|
|
466
459
|
bindtouchmove && bindtouchmove(e)
|
|
467
460
|
if (enhanced) {
|
|
@@ -478,22 +471,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
478
471
|
}
|
|
479
472
|
}
|
|
480
473
|
|
|
481
|
-
function onScrollTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
|
|
482
|
-
bindtouchend && bindtouchend(e)
|
|
483
|
-
if (enhanced) {
|
|
484
|
-
binddragend &&
|
|
485
|
-
binddragend(
|
|
486
|
-
getCustomEvent('dragend', e, {
|
|
487
|
-
detail: {
|
|
488
|
-
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
489
|
-
scrollTop: scrollOptions.current.scrollTop || 0
|
|
490
|
-
},
|
|
491
|
-
layoutRef
|
|
492
|
-
}, props)
|
|
493
|
-
)
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
|
|
497
474
|
function onScrollDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
498
475
|
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
499
476
|
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
@@ -514,6 +491,35 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
514
491
|
hasCallScrollToLower.current = false
|
|
515
492
|
hasCallScrollToUpper.current = false
|
|
516
493
|
onScrollDrag(e)
|
|
494
|
+
if (enhanced) {
|
|
495
|
+
binddragstart &&
|
|
496
|
+
binddragstart(
|
|
497
|
+
getCustomEvent('dragstart', e, {
|
|
498
|
+
detail: {
|
|
499
|
+
scrollLeft: scrollOptions.current.scrollLeft,
|
|
500
|
+
scrollTop: scrollOptions.current.scrollTop
|
|
501
|
+
},
|
|
502
|
+
layoutRef
|
|
503
|
+
}, props)
|
|
504
|
+
)
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function onScrollDragEnd (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
509
|
+
onScrollDrag(e)
|
|
510
|
+
if (enhanced) {
|
|
511
|
+
// 安卓上如果触发了默认的下拉刷新,binddragend可能不触发,只会触发 binddragstart
|
|
512
|
+
binddragend &&
|
|
513
|
+
binddragend(
|
|
514
|
+
getCustomEvent('dragend', e, {
|
|
515
|
+
detail: {
|
|
516
|
+
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
517
|
+
scrollTop: scrollOptions.current.scrollTop || 0
|
|
518
|
+
},
|
|
519
|
+
layoutRef
|
|
520
|
+
}, props)
|
|
521
|
+
)
|
|
522
|
+
}
|
|
517
523
|
}
|
|
518
524
|
|
|
519
525
|
// 处理刷新
|
|
@@ -587,7 +593,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
587
593
|
'worklet'
|
|
588
594
|
if (enableScrollValue.value !== newValue) {
|
|
589
595
|
enableScrollValue.value = newValue
|
|
590
|
-
runOnJS(
|
|
596
|
+
runOnJS(runOnJSCallback)('setEnableScroll', newValue)
|
|
591
597
|
}
|
|
592
598
|
}
|
|
593
599
|
|
|
@@ -600,7 +606,7 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
600
606
|
'worklet'
|
|
601
607
|
if (bouncesValue.value !== newValue) {
|
|
602
608
|
bouncesValue.value = newValue
|
|
603
|
-
runOnJS(
|
|
609
|
+
runOnJS(runOnJSCallback)('setScrollBounces', newValue)
|
|
604
610
|
}
|
|
605
611
|
}
|
|
606
612
|
|
|
@@ -649,19 +655,19 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
649
655
|
if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
|
|
650
656
|
translateY.value = withTiming(0)
|
|
651
657
|
updateScrollState(true)
|
|
652
|
-
runOnJS(
|
|
658
|
+
runOnJS(runOnJSCallback)('setRefreshing', false)
|
|
653
659
|
} else {
|
|
654
660
|
translateY.value = withTiming(refresherHeight.value)
|
|
655
661
|
}
|
|
656
662
|
} else if (event.translationY >= refresherHeight.value) {
|
|
657
663
|
// 触发刷新
|
|
658
664
|
translateY.value = withTiming(refresherHeight.value)
|
|
659
|
-
runOnJS(
|
|
665
|
+
runOnJS(runOnJSCallback)('onRefresh')
|
|
660
666
|
} else {
|
|
661
667
|
// 回弹
|
|
662
668
|
translateY.value = withTiming(0)
|
|
663
669
|
updateScrollState(true)
|
|
664
|
-
runOnJS(
|
|
670
|
+
runOnJS(runOnJSCallback)('setRefreshing', false)
|
|
665
671
|
}
|
|
666
672
|
})
|
|
667
673
|
.simultaneousWithExternalGesture(scrollViewRef)
|
|
@@ -686,11 +692,9 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
686
692
|
ref: scrollViewRef,
|
|
687
693
|
onScroll: enableSticky ? scrollHandler : onScroll,
|
|
688
694
|
onContentSizeChange: onContentSizeChange,
|
|
689
|
-
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
|
|
690
695
|
bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
|
|
691
|
-
bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
|
|
692
696
|
onScrollBeginDrag: onScrollDragStart,
|
|
693
|
-
onScrollEndDrag:
|
|
697
|
+
onScrollEndDrag: onScrollDragEnd,
|
|
694
698
|
onMomentumScrollEnd: onScrollEnd
|
|
695
699
|
},
|
|
696
700
|
(simultaneousHandlers ? { simultaneousHandlers } : {}),
|
|
@@ -5,7 +5,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS
|
|
|
5
5
|
import React, { JSX, forwardRef, useRef, useEffect, ReactNode, ReactElement, useMemo, createElement } from 'react'
|
|
6
6
|
import useInnerProps, { getCustomEvent } from './getInnerListeners'
|
|
7
7
|
import useNodesRef, { HandlerRef } from './useNodesRef' // 引入辅助函数
|
|
8
|
-
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, GestureHandler, flatGesture } from './utils'
|
|
8
|
+
import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, GestureHandler, flatGesture, useRunOnJSCallback } from './utils'
|
|
9
9
|
import { SwiperContext } from './context'
|
|
10
10
|
import Portal from './mpx-portal'
|
|
11
11
|
/**
|
|
@@ -148,6 +148,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
148
148
|
autoplay = false,
|
|
149
149
|
circular = false,
|
|
150
150
|
disableGesture = false,
|
|
151
|
+
current: propCurrent = 0,
|
|
151
152
|
bindchange
|
|
152
153
|
} = props
|
|
153
154
|
const easeingFunc = props['easing-function'] || 'default'
|
|
@@ -198,10 +199,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
198
199
|
// 每个元素的宽度 or 高度,有固定值直接初始化无则0
|
|
199
200
|
const step = useSharedValue(initStep)
|
|
200
201
|
// 记录选中元素的索引值
|
|
201
|
-
const currentIndex = useSharedValue(
|
|
202
|
+
const currentIndex = useSharedValue(propCurrent)
|
|
202
203
|
// const initOffset = getOffset(props.current || 0, initStep)
|
|
203
204
|
// 记录元素的偏移量
|
|
204
|
-
const offset = useSharedValue(getOffset(
|
|
205
|
+
const offset = useSharedValue(getOffset(propCurrent, initStep))
|
|
205
206
|
const strAbso = 'absolute' + dir.toUpperCase() as StrAbsoType
|
|
206
207
|
const strVelocity = 'velocity' + dir.toUpperCase() as StrVelocityType
|
|
207
208
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
@@ -270,7 +271,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
270
271
|
const iStep = dir === 'x' ? realWidth : realHeight
|
|
271
272
|
if (iStep !== step.value) {
|
|
272
273
|
step.value = iStep
|
|
273
|
-
updateCurrent(
|
|
274
|
+
updateCurrent(propCurrent, iStep)
|
|
274
275
|
updateAutoplay()
|
|
275
276
|
}
|
|
276
277
|
}
|
|
@@ -374,7 +375,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
374
375
|
easing: easeMap[easeingFunc]
|
|
375
376
|
}, () => {
|
|
376
377
|
currentIndex.value = nextIndex
|
|
377
|
-
runOnJS(
|
|
378
|
+
runOnJS(runOnJSCallback)('loop')
|
|
378
379
|
})
|
|
379
380
|
} else {
|
|
380
381
|
// 默认向右, 向下
|
|
@@ -389,7 +390,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
389
390
|
// 将开始位置设置为真正的位置
|
|
390
391
|
offset.value = initOffset
|
|
391
392
|
currentIndex.value = nextIndex
|
|
392
|
-
runOnJS(
|
|
393
|
+
runOnJS(runOnJSCallback)('loop')
|
|
393
394
|
})
|
|
394
395
|
} else {
|
|
395
396
|
nextIndex = currentIndex.value + 1
|
|
@@ -400,7 +401,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
400
401
|
easing: easeMap[easeingFunc]
|
|
401
402
|
}, () => {
|
|
402
403
|
currentIndex.value = nextIndex
|
|
403
|
-
runOnJS(
|
|
404
|
+
runOnJS(runOnJSCallback)('loop')
|
|
404
405
|
})
|
|
405
406
|
}
|
|
406
407
|
}
|
|
@@ -428,13 +429,21 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
428
429
|
}
|
|
429
430
|
}, [])
|
|
430
431
|
|
|
431
|
-
function handleSwiperChange (current: number) {
|
|
432
|
-
if (
|
|
432
|
+
function handleSwiperChange (current: number, pCurrent: number) {
|
|
433
|
+
if (pCurrent !== currentIndex.value) {
|
|
433
434
|
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
|
|
434
435
|
bindchange && bindchange(eventData)
|
|
435
436
|
}
|
|
436
437
|
}
|
|
437
438
|
|
|
439
|
+
const runOnJSCallbackRef = useRef({
|
|
440
|
+
loop,
|
|
441
|
+
pauseLoop,
|
|
442
|
+
resumeLoop,
|
|
443
|
+
handleSwiperChange
|
|
444
|
+
})
|
|
445
|
+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
|
|
446
|
+
|
|
438
447
|
function getOffset (index: number, stepValue: number) {
|
|
439
448
|
if (!stepValue) return 0
|
|
440
449
|
let targetOffset = 0
|
|
@@ -451,12 +460,12 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
451
460
|
const targetOffset = getOffset(index || 0, stepValue)
|
|
452
461
|
if (targetOffset !== offset.value) {
|
|
453
462
|
// 内部基于props.current!==currentIndex.value决定是否使用动画及更新currentIndex.value
|
|
454
|
-
if (
|
|
463
|
+
if (propCurrent !== undefined && propCurrent !== currentIndex.value) {
|
|
455
464
|
offset.value = withTiming(targetOffset, {
|
|
456
465
|
duration: easeDuration,
|
|
457
466
|
easing: easeMap[easeingFunc]
|
|
458
467
|
}, () => {
|
|
459
|
-
currentIndex.value =
|
|
468
|
+
currentIndex.value = propCurrent
|
|
460
469
|
})
|
|
461
470
|
} else {
|
|
462
471
|
offset.value = targetOffset
|
|
@@ -474,7 +483,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
474
483
|
useAnimatedReaction(() => currentIndex.value, (newIndex: number, preIndex: number) => {
|
|
475
484
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
476
485
|
if (newIndex !== preIndex && bindchange) {
|
|
477
|
-
runOnJS(
|
|
486
|
+
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
|
|
478
487
|
}
|
|
479
488
|
})
|
|
480
489
|
|
|
@@ -510,10 +519,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
510
519
|
useEffect(() => {
|
|
511
520
|
// 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
|
|
512
521
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
513
|
-
if (
|
|
514
|
-
updateCurrent(
|
|
522
|
+
if (propCurrent !== currentIndex.value) {
|
|
523
|
+
updateCurrent(propCurrent, step.value)
|
|
515
524
|
}
|
|
516
|
-
}, [
|
|
525
|
+
}, [propCurrent])
|
|
517
526
|
|
|
518
527
|
useEffect(() => {
|
|
519
528
|
autoplayShared.value = autoplay
|
|
@@ -603,7 +612,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
603
612
|
if (touchfinish.value !== false) {
|
|
604
613
|
currentIndex.value = selectedIndex
|
|
605
614
|
offset.value = resetOffset
|
|
606
|
-
runOnJS(
|
|
615
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
607
616
|
}
|
|
608
617
|
})
|
|
609
618
|
} else {
|
|
@@ -613,7 +622,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
613
622
|
}, () => {
|
|
614
623
|
if (touchfinish.value !== false) {
|
|
615
624
|
currentIndex.value = selectedIndex
|
|
616
|
-
runOnJS(
|
|
625
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
617
626
|
}
|
|
618
627
|
})
|
|
619
628
|
}
|
|
@@ -635,7 +644,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
635
644
|
}, () => {
|
|
636
645
|
if (touchfinish.value !== false) {
|
|
637
646
|
currentIndex.value = moveToIndex
|
|
638
|
-
runOnJS(
|
|
647
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
639
648
|
}
|
|
640
649
|
})
|
|
641
650
|
}
|
|
@@ -662,19 +671,10 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
662
671
|
'worklet'
|
|
663
672
|
const { diffOffset, half, isTriggerUpdateHalf } = computeHalf(eventData)
|
|
664
673
|
if (+diffOffset === 0) {
|
|
665
|
-
runOnJS(
|
|
674
|
+
runOnJS(runOnJSCallback)('resumeLoop')
|
|
666
675
|
} else if (isTriggerUpdateHalf) {
|
|
667
|
-
// 如果触发了onUpdate
|
|
668
|
-
|
|
669
|
-
offset.value = withTiming(-targetIndex * step.value, {
|
|
670
|
-
duration: easeDuration,
|
|
671
|
-
easing: easeMap[easeingFunc]
|
|
672
|
-
}, () => {
|
|
673
|
-
if (touchfinish.value !== false) {
|
|
674
|
-
currentIndex.value = targetIndex
|
|
675
|
-
runOnJS(resumeLoop)()
|
|
676
|
-
}
|
|
677
|
-
})
|
|
676
|
+
// 如果触发了onUpdate时的索引变更
|
|
677
|
+
handleEnd(eventData)
|
|
678
678
|
} else if (half) {
|
|
679
679
|
handleEnd(eventData)
|
|
680
680
|
} else {
|
|
@@ -745,14 +745,14 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
745
745
|
if (!step.value) return
|
|
746
746
|
touchfinish.value = false
|
|
747
747
|
cancelAnimation(offset)
|
|
748
|
-
runOnJS(
|
|
748
|
+
runOnJS(runOnJSCallback)('pauseLoop')
|
|
749
749
|
preAbsolutePos.value = e[strAbso]
|
|
750
750
|
moveTranstion.value = e[strAbso]
|
|
751
751
|
})
|
|
752
752
|
.onUpdate((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
|
|
753
753
|
'worklet'
|
|
754
|
-
if (touchfinish.value) return
|
|
755
754
|
const moveDistance = e[strAbso] - preAbsolutePos.value
|
|
755
|
+
if (touchfinish.value || moveDistance === 0) return
|
|
756
756
|
const eventData = {
|
|
757
757
|
translation: moveDistance,
|
|
758
758
|
transdir: moveDistance
|
|
@@ -352,7 +352,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
|
|
|
352
352
|
return extend({ app }, option)
|
|
353
353
|
}
|
|
354
354
|
|
|
355
|
-
export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el }) {
|
|
355
|
+
export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el, useSSR }) {
|
|
356
356
|
if (!isBrowser) {
|
|
357
357
|
return context => {
|
|
358
358
|
const { app, router, pinia = {} } = createApp({
|
|
@@ -379,7 +379,7 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
|
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
} else {
|
|
382
|
-
const { app, pinia } = createApp({
|
|
382
|
+
const { app, pinia, router } = createApp({
|
|
383
383
|
App,
|
|
384
384
|
componentsMap,
|
|
385
385
|
Vue,
|
|
@@ -391,6 +391,14 @@ export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue
|
|
|
391
391
|
if (window.__INITIAL_STATE__ && pinia) {
|
|
392
392
|
pinia.state.value = window.__INITIAL_STATE__
|
|
393
393
|
}
|
|
394
|
-
|
|
394
|
+
if (useSSR) {
|
|
395
|
+
// https://v3.router.vuejs.org/api/#router-onready
|
|
396
|
+
// ssr 场景如果使用了异步组件,需要在 onReady 回调中挂载,否则 hydrate 可能会报错
|
|
397
|
+
router.onReady(() => {
|
|
398
|
+
app.$mount(el)
|
|
399
|
+
})
|
|
400
|
+
} else {
|
|
401
|
+
app.$mount(el)
|
|
402
|
+
}
|
|
395
403
|
}
|
|
396
404
|
}
|
|
@@ -14,7 +14,7 @@ export function getAsyncSuspense (commonProps) {
|
|
|
14
14
|
if (commonProps.type === 'component') {
|
|
15
15
|
result = memo(forwardRef(function (props, ref) {
|
|
16
16
|
return createElement(AsyncSuspense,
|
|
17
|
-
extend(commonProps, {
|
|
17
|
+
extend({}, commonProps, {
|
|
18
18
|
innerProps: Object.assign({}, props, { ref })
|
|
19
19
|
})
|
|
20
20
|
)
|
|
@@ -22,7 +22,7 @@ export function getAsyncSuspense (commonProps) {
|
|
|
22
22
|
} else {
|
|
23
23
|
result = memo(function (props) {
|
|
24
24
|
return createElement(AsyncSuspense,
|
|
25
|
-
extend(commonProps, {
|
|
25
|
+
extend({}, commonProps, {
|
|
26
26
|
innerProps: props
|
|
27
27
|
})
|
|
28
28
|
)
|
|
@@ -71,7 +71,8 @@ export default processAppOption({
|
|
|
71
71
|
componentsMap: ${shallowStringify(componentsMap)},
|
|
72
72
|
Vue: Vue,
|
|
73
73
|
VueRouter: VueRouter,
|
|
74
|
-
el: ${JSON.stringify(webConfig.el || '#app')}
|
|
74
|
+
el: ${JSON.stringify(webConfig.el || '#app')},
|
|
75
|
+
useSSR: ${JSON.stringify(!!webConfig.useSSR)}
|
|
75
76
|
})\n`
|
|
76
77
|
|
|
77
78
|
callback(null, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.15-2",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"engines": {
|
|
101
101
|
"node": ">=14.14.0"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
|
|
104
104
|
}
|