@mpxjs/webpack-plugin 2.10.14-beta.14 → 2.10.14-beta.15

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.
@@ -47,6 +47,8 @@ interface SwiperProps {
47
47
  'simultaneous-handlers'?: Array<GestureHandler>;
48
48
  disableGesture?: boolean;
49
49
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
50
+ bindtransition?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
51
+ bindanimationfinish?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void;
50
52
  }
51
53
  declare const SwiperWrapper: React.ForwardRefExoticComponent<SwiperProps & React.RefAttributes<HandlerRef<View, SwiperProps>>>;
52
54
  export default SwiperWrapper;
@@ -71,7 +71,7 @@ const easeMap = {
71
71
  easeInOutCubic: Easing.inOut(Easing.cubic)
72
72
  };
73
73
  const SwiperWrapper = forwardRef((props, ref) => {
74
- const { 'indicator-dots': showPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false, disableGesture = false, current: propCurrent = 0, bindchange } = props;
74
+ const { 'indicator-dots': showPagination, 'indicator-color': dotColor = 'rgba(0, 0, 0, .3)', 'indicator-active-color': activeDotColor = '#000000', 'enable-var': enableVar = false, 'parent-font-size': parentFontSize, 'parent-width': parentWidth, 'parent-height': parentHeight, 'external-var-context': externalVarContext, 'simultaneous-handlers': originSimultaneousHandlers = [], 'wait-for': waitFor = [], style = {}, autoplay = false, circular = false, disableGesture = false, current: propCurrent = 0, bindchange, bindtransition, bindanimationfinish } = props;
75
75
  const easeingFunc = props['easing-function'] || 'default';
76
76
  const easeDuration = props.duration || 500;
77
77
  const horizontal = props.vertical !== undefined ? !props.vertical : true;
@@ -275,6 +275,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
275
275
  }, () => {
276
276
  currentIndex.value = nextIndex;
277
277
  runOnJS(runOnJSCallback)('loop');
278
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', nextIndex);
278
279
  });
279
280
  }
280
281
  else {
@@ -291,6 +292,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
291
292
  offset.value = initOffset;
292
293
  currentIndex.value = nextIndex;
293
294
  runOnJS(runOnJSCallback)('loop');
295
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', nextIndex);
294
296
  });
295
297
  }
296
298
  else {
@@ -303,6 +305,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
303
305
  }, () => {
304
306
  currentIndex.value = nextIndex;
305
307
  runOnJS(runOnJSCallback)('loop');
308
+ runOnJS(runOnJSCallback)('handleAnimationfinish', nextIndex);
306
309
  });
307
310
  }
308
311
  }
@@ -331,11 +334,21 @@ const SwiperWrapper = forwardRef((props, ref) => {
331
334
  const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
332
335
  bindchange && bindchange(eventData);
333
336
  }
337
+ function handleTransition(transData) {
338
+ const eventData = getCustomEvent('change', {}, { detail: transData, layoutRef: layoutRef });
339
+ bindtransition && bindtransition(eventData);
340
+ }
341
+ function handleAnimationfinish(current) {
342
+ const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
343
+ bindanimationfinish && bindanimationfinish(eventData);
344
+ }
334
345
  const runOnJSCallbackRef = useRef({
335
346
  loop,
336
347
  pauseLoop,
337
348
  resumeLoop,
338
- handleSwiperChange
349
+ handleSwiperChange,
350
+ handleTransition,
351
+ handleAnimationfinish
339
352
  });
340
353
  const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef);
341
354
  function getOffset(index, stepValue) {
@@ -361,6 +374,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
361
374
  easing: easeMap[easeingFunc]
362
375
  }, () => {
363
376
  currentIndex.value = propCurrent;
377
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', propCurrent);
364
378
  });
365
379
  }
366
380
  else {
@@ -383,6 +397,28 @@ const SwiperWrapper = forwardRef((props, ref) => {
383
397
  runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent);
384
398
  }
385
399
  });
400
+ useAnimatedReaction(() => offset.value, (curOffset, preOffset) => {
401
+ const curAbsOffset = Math.abs(curOffset);
402
+ const preAbsOffset = Math.abs(preOffset || 0);
403
+ const computeOffset = step.value * (currentIndex.value + patchElmNumShared.value);
404
+ // 有小数点的情况
405
+ const isEqual = Math.abs(Math.floor(computeOffset) - Math.floor(Math.abs(offset.value))) <= 2;
406
+ if (curAbsOffset !== preAbsOffset && curAbsOffset && !isEqual) {
407
+ // 移动的距离,手向左滑动正数( curAbsOffset >= preAbsOffset),右右滑动是负数( curAbsOffset < preAbsOffset)
408
+ let trans = 0;
409
+ if (curAbsOffset >= preAbsOffset) {
410
+ trans = curAbsOffset % step.value;
411
+ }
412
+ else {
413
+ trans = -(step.value - curAbsOffset % step.value);
414
+ }
415
+ const transData = {
416
+ dx: dir === 'x' ? trans : 0,
417
+ dy: dir === 'y' ? trans : 0
418
+ };
419
+ bindtransition && runOnJS(runOnJSCallback)('handleTransition', transData);
420
+ }
421
+ });
386
422
  useEffect(() => {
387
423
  let patchStep = 0;
388
424
  if (preMargin !== preMarginShared.value) {
@@ -510,6 +546,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
510
546
  currentIndex.value = selectedIndex;
511
547
  offset.value = resetOffset;
512
548
  runOnJS(runOnJSCallback)('resumeLoop');
549
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', selectedIndex);
513
550
  }
514
551
  });
515
552
  }
@@ -521,6 +558,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
521
558
  if (touchfinish.value !== false) {
522
559
  currentIndex.value = selectedIndex;
523
560
  runOnJS(runOnJSCallback)('resumeLoop');
561
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', selectedIndex);
524
562
  }
525
563
  });
526
564
  }
@@ -543,6 +581,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
543
581
  if (touchfinish.value !== false) {
544
582
  currentIndex.value = moveToIndex;
545
583
  runOnJS(runOnJSCallback)('resumeLoop');
584
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', moveToIndex);
546
585
  }
547
586
  });
548
587
  }
@@ -90,11 +90,12 @@ const MpxNav = memo(({ pageConfig, navigation }) => {
90
90
  const navigationBarTextStyle = useMemo(() => validBarTextStyle(innerPageConfig.navigationBarTextStyle), [innerPageConfig.navigationBarTextStyle]);
91
91
  // 状态栏的颜色
92
92
  const statusBarElement = (<StatusBar translucent backgroundColor='transparent' barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>);
93
- if (isCustom)
93
+ if (isCustom) {
94
94
  return (<>
95
95
  {statusBarElement}
96
96
  {customNav}
97
97
  </>);
98
+ }
98
99
  // 假设是栈导航,获取栈的长度
99
100
  const stackLength = navigation.getState()?.routes?.length;
100
101
  const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack;
@@ -9,7 +9,7 @@ interface MpxNavContainerProps {
9
9
  children?: React.ReactNode
10
10
  }
11
11
 
12
- export default function MpxNavContainer(props: MpxNavContainerProps) {
12
+ export default function MpxNavContainer (props: MpxNavContainerProps) {
13
13
  const [, setCustomNav] = useNavShared()
14
14
 
15
15
  useLayoutEffect(() => {
@@ -26,7 +26,7 @@ export default function MpxNavContainer(props: MpxNavContainerProps) {
26
26
  return isAndroid ? null : props.children
27
27
  }
28
28
 
29
- export function NavSharedProvider({ children }: { children?: React.ReactNode }) {
29
+ export function NavSharedProvider ({ children }: { children?: React.ReactNode }) {
30
30
  const [customNav, setCustomNav] = useState()
31
31
  const value = useMemo(() => ({ customNav, setCustomNav } as NavSharedValue), [customNav])
32
32
  return <NavSharedContext.Provider value={value}>{children}</NavSharedContext.Provider>
@@ -33,6 +33,11 @@ type EventDataType = {
33
33
  // onUpdate时根据上一个判断方向,onFinalize根据transformStart判断
34
34
  transdir: number
35
35
  }
36
+ // bindtransition回调的参数
37
+ type EventTransition = {
38
+ dx: number
39
+ dy: number
40
+ }
36
41
 
37
42
  interface SwiperProps {
38
43
  children?: ReactNode
@@ -64,6 +69,8 @@ interface SwiperProps {
64
69
  'simultaneous-handlers'?: Array<GestureHandler>
65
70
  disableGesture?: boolean
66
71
  bindchange?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
72
+ bindtransition?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
73
+ bindanimationfinish?: (event: NativeSyntheticEvent<TouchEvent> | unknown) => void
67
74
  }
68
75
 
69
76
  /**
@@ -149,7 +156,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
149
156
  circular = false,
150
157
  disableGesture = false,
151
158
  current: propCurrent = 0,
152
- bindchange
159
+ bindchange,
160
+ bindtransition,
161
+ bindanimationfinish
153
162
  } = props
154
163
  const easeingFunc = props['easing-function'] || 'default'
155
164
  const easeDuration = props.duration || 500
@@ -378,6 +387,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
378
387
  }, () => {
379
388
  currentIndex.value = nextIndex
380
389
  runOnJS(runOnJSCallback)('loop')
390
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', nextIndex)
381
391
  })
382
392
  } else {
383
393
  // 默认向右, 向下
@@ -393,6 +403,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
393
403
  offset.value = initOffset
394
404
  currentIndex.value = nextIndex
395
405
  runOnJS(runOnJSCallback)('loop')
406
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', nextIndex)
396
407
  })
397
408
  } else {
398
409
  nextIndex = currentIndex.value + 1
@@ -404,6 +415,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
404
415
  }, () => {
405
416
  currentIndex.value = nextIndex
406
417
  runOnJS(runOnJSCallback)('loop')
418
+ runOnJS(runOnJSCallback)('handleAnimationfinish', nextIndex)
407
419
  })
408
420
  }
409
421
  }
@@ -436,11 +448,23 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
436
448
  bindchange && bindchange(eventData)
437
449
  }
438
450
 
451
+ function handleTransition (transData: EventTransition) {
452
+ const eventData = getCustomEvent('change', {}, { detail: transData, layoutRef: layoutRef })
453
+ bindtransition && bindtransition(eventData)
454
+ }
455
+
456
+ function handleAnimationfinish (current: number) {
457
+ const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
458
+ bindanimationfinish && bindanimationfinish(eventData)
459
+ }
460
+
439
461
  const runOnJSCallbackRef = useRef({
440
462
  loop,
441
463
  pauseLoop,
442
464
  resumeLoop,
443
- handleSwiperChange
465
+ handleSwiperChange,
466
+ handleTransition,
467
+ handleAnimationfinish
444
468
  })
445
469
  const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
446
470
 
@@ -466,6 +490,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
466
490
  easing: easeMap[easeingFunc]
467
491
  }, () => {
468
492
  currentIndex.value = propCurrent
493
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', propCurrent)
469
494
  })
470
495
  } else {
471
496
  offset.value = targetOffset
@@ -486,7 +511,27 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
486
511
  runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
487
512
  }
488
513
  })
489
-
514
+ useAnimatedReaction(() => offset.value, (curOffset, preOffset) => {
515
+ const curAbsOffset = Math.abs(curOffset)
516
+ const preAbsOffset = Math.abs(preOffset || 0)
517
+ const computeOffset = step.value * (currentIndex.value + patchElmNumShared.value)
518
+ // 有小数点的情况
519
+ const isEqual = Math.abs(Math.floor(computeOffset) - Math.floor(Math.abs(offset.value))) <= 2
520
+ if (curAbsOffset !== preAbsOffset && curAbsOffset && !isEqual) {
521
+ // 移动的距离,手向左滑动正数( curAbsOffset >= preAbsOffset),右右滑动是负数( curAbsOffset < preAbsOffset)
522
+ let trans = 0
523
+ if (curAbsOffset >= preAbsOffset) {
524
+ trans = curAbsOffset % step.value
525
+ } else {
526
+ trans = -(step.value - curAbsOffset % step.value)
527
+ }
528
+ const transData = {
529
+ dx: dir === 'x' ? trans : 0,
530
+ dy: dir === 'y' ? trans : 0
531
+ }
532
+ bindtransition && runOnJS(runOnJSCallback)('handleTransition', transData)
533
+ }
534
+ })
490
535
  useEffect(() => {
491
536
  let patchStep = 0
492
537
  if (preMargin !== preMarginShared.value) {
@@ -613,6 +658,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
613
658
  currentIndex.value = selectedIndex
614
659
  offset.value = resetOffset
615
660
  runOnJS(runOnJSCallback)('resumeLoop')
661
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', selectedIndex)
616
662
  }
617
663
  })
618
664
  } else {
@@ -623,6 +669,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
623
669
  if (touchfinish.value !== false) {
624
670
  currentIndex.value = selectedIndex
625
671
  runOnJS(runOnJSCallback)('resumeLoop')
672
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', selectedIndex)
626
673
  }
627
674
  })
628
675
  }
@@ -645,6 +692,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
645
692
  if (touchfinish.value !== false) {
646
693
  currentIndex.value = moveToIndex
647
694
  runOnJS(runOnJSCallback)('resumeLoop')
695
+ bindanimationfinish && runOnJS(runOnJSCallback)('handleAnimationfinish', moveToIndex)
648
696
  }
649
697
  })
650
698
  }
@@ -105,13 +105,14 @@ const MpxNav = memo(({ pageConfig, navigation }: MpxNavProps) => {
105
105
  barStyle={navigationBarTextStyle === NavColor.White ? 'light-content' : 'dark-content'}></StatusBar>
106
106
  )
107
107
 
108
- if (isCustom)
108
+ if (isCustom) {
109
109
  return (
110
110
  <>
111
111
  {statusBarElement}
112
112
  {customNav}
113
113
  </>
114
114
  )
115
+ }
115
116
  // 假设是栈导航,获取栈的长度
116
117
  const stackLength = navigation.getState()?.routes?.length
117
118
  const onStackTopBack = mpxGlobal?.__mpx?.config?.rnConfig?.onStackTopBack
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.14-beta.14",
3
+ "version": "2.10.14-beta.15",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"