@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 CHANGED
@@ -199,6 +199,7 @@ class MpxWebpackPlugin {
199
199
  }, options.nativeConfig)
200
200
  options.webConfig = options.webConfig || {}
201
201
  options.rnConfig = options.rnConfig || {}
202
+ options.rnConfig.supportSubpackage = options.rnConfig.supportSubpackage !== undefined ? options.rnConfig.supportSubpackage : true
202
203
  options.partialCompileRules = options.partialCompileRules || null
203
204
  options.asyncSubpackageRules = options.asyncSubpackageRules || []
204
205
  options.optimizeRenderRules = options.optimizeRenderRules ? (Array.isArray(options.optimizeRenderRules) ? options.optimizeRenderRules : [options.optimizeRenderRules]) : []
@@ -1447,7 +1448,10 @@ class MpxWebpackPlugin {
1447
1448
  // 删除root query
1448
1449
  if (queryObj.root) request = addQuery(request, {}, false, ['root'])
1449
1450
  // wx、ali和web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
1450
- if (mpx.supportRequireAsync) {
1451
+ const supportRequireAsync = isReact(mpx.mode)
1452
+ ? (mpx.supportRequireAsync && this.options.rnConfig.supportSubpackage)
1453
+ : mpx.supportRequireAsync
1454
+ if (supportRequireAsync) {
1451
1455
  if (isWeb(mpx.mode) || isReact(mpx.mode)) {
1452
1456
  if (isReact(mpx.mode)) tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
1453
1457
  request = addQuery(request, {
@@ -1726,6 +1730,23 @@ class MpxWebpackPlugin {
1726
1730
  source.add('// inject pageconfigmap for screen\n' +
1727
1731
  'var context = (function() { return this })() || Function("return this")();\n')
1728
1732
  source.add(`context.__mpxPageConfigsMap = ${JSON.stringify(mpx.pageConfigsMap)};\n`)
1733
+
1734
+ if (process.env.NODE_ENV !== 'production') {
1735
+ source.add(`
1736
+ ${globalObject}.__mpxClearAsyncChunkCache = ${globalObject}.__mpxClearAsyncChunkCache || function (ids) {
1737
+ ids = JSON.stringify(ids)
1738
+ var arr = ${globalObject}['${chunkLoadingGlobal}'] || []
1739
+ for (var i = arr.length - 1; i >= 0; i--) {
1740
+ if (JSON.stringify(arr[i][0]) === ids) {
1741
+ arr.splice(i, 1)
1742
+ }
1743
+ }
1744
+ };\n`)
1745
+ }
1746
+ } else {
1747
+ if (process.env.NODE_ENV !== 'production') {
1748
+ source.add(`${globalObject}.__mpxClearAsyncChunkCache && ${globalObject}.__mpxClearAsyncChunkCache(${JSON.stringify(chunk.ids)});\n`)
1749
+ }
1729
1750
  }
1730
1751
  source.add(originalSource)
1731
1752
  compilation.assets[chunkFile] = source
@@ -1825,6 +1846,7 @@ try {
1825
1846
 
1826
1847
  compilation.chunkGroups.forEach((chunkGroup) => {
1827
1848
  if (!chunkGroup.isInitial()) {
1849
+ isReact(mpx.mode) && chunkGroup.chunks.forEach((chunk) => processChunk(chunk, false, []))
1828
1850
  return
1829
1851
  }
1830
1852
 
@@ -547,6 +547,17 @@ module.exports = function getSpec ({ warn, error }) {
547
547
  // })
548
548
  // return cssMap
549
549
  // }
550
+ const formatBorder = ({ prop, value, selector }, { mode }) => {
551
+ value = value.trim()
552
+ if (value === 'none') {
553
+ return {
554
+ prop: 'borderWidth',
555
+ value: 0
556
+ }
557
+ } else {
558
+ return formatAbbreviation({ prop, value, selector }, { mode })
559
+ }
560
+ }
550
561
 
551
562
  return {
552
563
  supportedModes: ['ios', 'android', 'harmony'],
@@ -593,6 +604,12 @@ module.exports = function getSpec ({ warn, error }) {
593
604
  // android: formatBoxShadow,
594
605
  // harmony: formatBoxShadow
595
606
  // },
607
+ {
608
+ test: 'border',
609
+ ios: formatBorder,
610
+ android: formatBorder,
611
+ harmony: formatBorder
612
+ },
596
613
  // 通用的简写格式匹配
597
614
  {
598
615
  test: new RegExp('^(' + Object.keys(AbbreviationMap).join('|') + ')$'),
@@ -46,7 +46,8 @@ import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext,
46
46
  const componentsMap = buildComponentsMap({
47
47
  localComponentsMap,
48
48
  loaderContext,
49
- jsonConfig
49
+ jsonConfig,
50
+ rnConfig
50
51
  })
51
52
  output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, pagesMap, firstPage, hasApp })
52
53
  output += getRequireScript({ ctorType, script, loaderContext })
@@ -58,7 +59,8 @@ import { getComponent, getAsyncSuspense } from ${stringifyRequest(loaderContext,
58
59
  localComponentsMap,
59
60
  builtInComponentsMap,
60
61
  loaderContext,
61
- jsonConfig
62
+ jsonConfig,
63
+ rnConfig
62
64
  })
63
65
 
64
66
  output += buildGlobalParams({ moduleId, scriptSrcMode, loaderContext, isProduction, ctorType, jsonConfig, componentsMap, outputPath, genericsInfo, componentGenerics, hasApp })
@@ -59,7 +59,7 @@ function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig, rnConfig })
59
59
  Object.keys(localPagesMap).forEach((pagePath) => {
60
60
  const pageCfg = localPagesMap[pagePath]
61
61
  const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
62
- if (pageCfg.async) {
62
+ if (pageCfg.async && rnConfig.supportSubpackage) {
63
63
  const moduleId = mpx.getModuleId(pageCfg.resource)
64
64
  const getFallback = rnConfig.asyncChunk && rnConfig.asyncChunk.fallback && getComponentGetter(getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.fallback, { isComponent: true })), 'PageFallback'))
65
65
  const getLoading = rnConfig.asyncChunk && rnConfig.asyncChunk.loading && getComponentGetter(getComponent(stringifyRequest(loaderContext, addQuery(rnConfig.asyncChunk.loading, { isComponent: true })), 'PageLoading'))
@@ -81,14 +81,14 @@ function buildPagesMap ({ localPagesMap, loaderContext, jsonConfig, rnConfig })
81
81
  }
82
82
  }
83
83
 
84
- function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig }) {
84
+ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig, rnConfig }) {
85
85
  const componentsMap = {}
86
86
  const mpx = loaderContext.getMpx()
87
87
  if (localComponentsMap) {
88
88
  Object.keys(localComponentsMap).forEach((componentName) => {
89
89
  const componentCfg = localComponentsMap[componentName]
90
90
  const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
91
- if (componentCfg.async) {
91
+ if (componentCfg.async && rnConfig.supportSubpackage) {
92
92
  const moduleId = mpx.getModuleId(componentCfg.resource)
93
93
  const placeholder = jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName]
94
94
  let getFallback
@@ -100,8 +100,8 @@ const AsyncSuspense = ({ type, chunkName, moduleId, innerProps, getLoading, getF
100
100
  });
101
101
  });
102
102
  }
103
- if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.lazyLoadPageErrorHandler === 'function') {
104
- mpxGlobal.__mpx.config.rnConfig.lazyLoadPageErrorHandler({
103
+ if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.onLazyLoadPageError === 'function') {
104
+ mpxGlobal.__mpx.config.rnConfig.onLazyLoadPageError({
105
105
  subpackage: chunkName,
106
106
  errType: e.type
107
107
  });
@@ -22,7 +22,7 @@ import { StyleSheet } from 'react-native';
22
22
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
23
23
  import useNodesRef from './useNodesRef';
24
24
  import { MovableAreaContext } from './context';
25
- import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, flatGesture, extendObject, omit, useNavigation } from './utils';
25
+ import { useTransformStyle, splitProps, splitStyle, HIDDEN_STYLE, wrapChildren, flatGesture, extendObject, omit, useNavigation, useRunOnJSCallback } from './utils';
26
26
  import { GestureDetector, Gesture } from 'react-native-gesture-handler';
27
27
  import Animated, { useSharedValue, useAnimatedStyle, withDecay, runOnJS, runOnUI, withSpring } from 'react-native-reanimated';
28
28
  import { collectDataset, noop } from '@mpxjs/utils';
@@ -106,7 +106,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
106
106
  const now = Date.now();
107
107
  if (now - lastChangeTime.value >= changeThrottleTime) {
108
108
  lastChangeTime.value = now;
109
- runOnJS(handleTriggerChange)({ x, y, type });
109
+ runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type });
110
110
  }
111
111
  }, [changeThrottleTime]);
112
112
  useEffect(() => {
@@ -130,7 +130,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
130
130
  : newY;
131
131
  }
132
132
  if (bindchange) {
133
- runOnJS(handleTriggerChange)({
133
+ runOnJS(runOnJSCallback)('handleTriggerChange', {
134
134
  x: newX,
135
135
  y: newY,
136
136
  type: 'setData'
@@ -295,13 +295,20 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
295
295
  bindtouchend && bindtouchend(e);
296
296
  catchtouchend && catchtouchend(e);
297
297
  };
298
+ const runOnJSCallbackRef = useRef({
299
+ handleTriggerChange,
300
+ triggerStartOnJS,
301
+ triggerMoveOnJS,
302
+ triggerEndOnJS
303
+ });
304
+ const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef);
298
305
  const gesture = useMemo(() => {
299
306
  const handleTriggerMove = (e) => {
300
307
  'worklet';
301
308
  const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove;
302
309
  const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove;
303
310
  if (hasTouchmove || hasCatchTouchmove) {
304
- runOnJS(triggerMoveOnJS)({
311
+ runOnJS(runOnJSCallback)('triggerMoveOnJS', {
305
312
  e,
306
313
  touchEvent: touchEvent.value,
307
314
  hasTouchmove,
@@ -319,7 +326,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
319
326
  y: changedTouches.y
320
327
  };
321
328
  if (bindtouchstart || catchtouchstart) {
322
- runOnJS(triggerStartOnJS)({ e });
329
+ runOnJS(runOnJSCallback)('triggerStartOnJS', { e });
323
330
  }
324
331
  })
325
332
  .onStart(() => {
@@ -376,7 +383,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
376
383
  isFirstTouch.value = true;
377
384
  isMoving.value = false;
378
385
  if (bindtouchend || catchtouchend) {
379
- runOnJS(triggerEndOnJS)({ e });
386
+ runOnJS(runOnJSCallback)('triggerEndOnJS', { e });
380
387
  }
381
388
  })
382
389
  .onEnd((e) => {
@@ -405,7 +412,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
405
412
  : y;
406
413
  }
407
414
  if (bindchange) {
408
- runOnJS(handleTriggerChange)({
415
+ runOnJS(runOnJSCallback)('handleTriggerChange', {
409
416
  x,
410
417
  y
411
418
  });
@@ -423,7 +430,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
423
430
  }, () => {
424
431
  xInertialMotion.value = false;
425
432
  if (bindchange) {
426
- runOnJS(handleTriggerChange)({
433
+ runOnJS(runOnJSCallback)('handleTriggerChange', {
427
434
  x: offsetX.value,
428
435
  y: offsetY.value
429
436
  });
@@ -439,7 +446,7 @@ const _MovableView = forwardRef((movableViewProps, ref) => {
439
446
  }, () => {
440
447
  yInertialMotion.value = false;
441
448
  if (bindchange) {
442
- runOnJS(handleTriggerChange)({
449
+ runOnJS(runOnJSCallback)('handleTriggerChange', {
443
450
  x: offsetX.value,
444
451
  y: offsetY.value
445
452
  });
@@ -157,8 +157,8 @@ const _PickerViewColumn = forwardRef((props, ref) => {
157
157
  }, [itemRawH, maxIndex, snapToOffsets, onMomentumScrollEnd, resetScrollPosition]);
158
158
  const onScroll = useCallback((e) => {
159
159
  // 全局注册的振动触感 hook
160
- const pickerVibrate = global.__mpx?.config?.rnConfig?.pickerVibrate;
161
- if (typeof pickerVibrate !== 'function') {
160
+ const onPickerVibrate = global.__mpx?.config?.rnConfig?.onPickerVibrate;
161
+ if (typeof onPickerVibrate !== 'function') {
162
162
  return;
163
163
  }
164
164
  const { y } = e.nativeEvent.contentOffset;
@@ -172,7 +172,7 @@ const _PickerViewColumn = forwardRef((props, ref) => {
172
172
  y: currentId * itemRawH
173
173
  };
174
174
  // vibrateShort({ type: 'selection' })
175
- pickerVibrate();
175
+ onPickerVibrate();
176
176
  }
177
177
  }
178
178
  }
@@ -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 from './useNodesRef';
41
- import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, HIDDEN_STYLE } from './utils';
41
+ import { splitProps, splitStyle, useTransformStyle, useLayout, wrapChildren, extendObject, flatGesture, HIDDEN_STYLE, useRunOnJSCallback } from './utils';
42
42
  import { IntersectionObserverContext, ScrollViewContext } from './context';
43
43
  import Portal from './mpx-portal';
44
44
  const AnimatedScrollView = RNAnimated.createAnimatedComponent(ScrollView);
@@ -79,6 +79,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
79
79
  const { normalStyle, hasVarDec, varContextRef, hasSelfPercent, hasPositionFixed, setWidth, setHeight } = useTransformStyle(style, { enableVar, externalVarContext, parentFontSize, parentWidth, parentHeight });
80
80
  const { textStyle, innerStyle = {} } = splitStyle(normalStyle);
81
81
  const scrollViewRef = useRef(null);
82
+ const runOnJSCallbackRef = useRef({
83
+ setEnableScroll,
84
+ setScrollBounces,
85
+ setRefreshing,
86
+ onRefresh
87
+ });
88
+ const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef);
82
89
  useNodesRef(props, ref, scrollViewRef, {
83
90
  style: normalStyle,
84
91
  scrollOffset: scrollOptions,
@@ -285,20 +292,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
285
292
  snapScrollTop.current = y;
286
293
  }
287
294
  }
288
- function onScrollTouchStart(e) {
289
- const { bindtouchstart } = props;
290
- bindtouchstart && bindtouchstart(e);
291
- if (enhanced) {
292
- binddragstart &&
293
- binddragstart(getCustomEvent('dragstart', e, {
294
- detail: {
295
- scrollLeft: scrollOptions.current.scrollLeft,
296
- scrollTop: scrollOptions.current.scrollTop
297
- },
298
- layoutRef
299
- }, props));
300
- }
301
- }
302
295
  function onScrollTouchMove(e) {
303
296
  bindtouchmove && bindtouchmove(e);
304
297
  if (enhanced) {
@@ -312,19 +305,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
312
305
  }, props));
313
306
  }
314
307
  }
315
- function onScrollTouchEnd(e) {
316
- bindtouchend && bindtouchend(e);
317
- if (enhanced) {
318
- binddragend &&
319
- binddragend(getCustomEvent('dragend', e, {
320
- detail: {
321
- scrollLeft: scrollOptions.current.scrollLeft || 0,
322
- scrollTop: scrollOptions.current.scrollTop || 0
323
- },
324
- layoutRef
325
- }, props));
326
- }
327
- }
328
308
  function onScrollDrag(e) {
329
309
  const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
330
310
  updateScrollOptions(e, { scrollLeft, scrollTop });
@@ -340,6 +320,30 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
340
320
  hasCallScrollToLower.current = false;
341
321
  hasCallScrollToUpper.current = false;
342
322
  onScrollDrag(e);
323
+ if (enhanced) {
324
+ binddragstart &&
325
+ binddragstart(getCustomEvent('dragstart', e, {
326
+ detail: {
327
+ scrollLeft: scrollOptions.current.scrollLeft,
328
+ scrollTop: scrollOptions.current.scrollTop
329
+ },
330
+ layoutRef
331
+ }, props));
332
+ }
333
+ }
334
+ function onScrollDragEnd(e) {
335
+ onScrollDrag(e);
336
+ if (enhanced) {
337
+ // 安卓上如果触发了默认的下拉刷新,binddragend可能不触发,只会触发 binddragstart
338
+ binddragend &&
339
+ binddragend(getCustomEvent('dragend', e, {
340
+ detail: {
341
+ scrollLeft: scrollOptions.current.scrollLeft || 0,
342
+ scrollTop: scrollOptions.current.scrollTop || 0
343
+ },
344
+ layoutRef
345
+ }, props));
346
+ }
343
347
  }
344
348
  // 处理刷新
345
349
  function onRefresh() {
@@ -404,7 +408,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
404
408
  'worklet';
405
409
  if (enableScrollValue.value !== newValue) {
406
410
  enableScrollValue.value = newValue;
407
- runOnJS(setEnableScroll)(newValue);
411
+ runOnJS(runOnJSCallback)('setEnableScroll', newValue);
408
412
  }
409
413
  }
410
414
  const resetScrollState = (value) => {
@@ -415,7 +419,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
415
419
  'worklet';
416
420
  if (bouncesValue.value !== newValue) {
417
421
  bouncesValue.value = newValue;
418
- runOnJS(setScrollBounces)(newValue);
422
+ runOnJS(runOnJSCallback)('setScrollBounces', newValue);
419
423
  }
420
424
  }
421
425
  // 处理下拉刷新的手势
@@ -460,7 +464,7 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
460
464
  if ((event.translationY > 0 && translateY.value < refresherThreshold) || event.translationY < 0) {
461
465
  translateY.value = withTiming(0);
462
466
  updateScrollState(true);
463
- runOnJS(setRefreshing)(false);
467
+ runOnJS(runOnJSCallback)('setRefreshing', false);
464
468
  }
465
469
  else {
466
470
  translateY.value = withTiming(refresherHeight.value);
@@ -469,13 +473,13 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
469
473
  else if (event.translationY >= refresherHeight.value) {
470
474
  // 触发刷新
471
475
  translateY.value = withTiming(refresherHeight.value);
472
- runOnJS(onRefresh)();
476
+ runOnJS(runOnJSCallback)('onRefresh');
473
477
  }
474
478
  else {
475
479
  // 回弹
476
480
  translateY.value = withTiming(0);
477
481
  updateScrollState(true);
478
- runOnJS(setRefreshing)(false);
482
+ runOnJS(runOnJSCallback)('setRefreshing', false);
479
483
  }
480
484
  })
481
485
  .simultaneousWithExternalGesture(scrollViewRef);
@@ -498,11 +502,9 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
498
502
  ref: scrollViewRef,
499
503
  onScroll: enableSticky ? scrollHandler : onScroll,
500
504
  onContentSizeChange: onContentSizeChange,
501
- bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
502
505
  bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
503
- bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
504
506
  onScrollBeginDrag: onScrollDragStart,
505
- onScrollEndDrag: onScrollDrag,
507
+ onScrollEndDrag: onScrollDragEnd,
506
508
  onMomentumScrollEnd: onScrollEnd
507
509
  }, (simultaneousHandlers ? { simultaneousHandlers } : {}), (waitForHandlers ? { waitFor: waitForHandlers } : {}), layoutProps);
508
510
  if (enhanced) {
@@ -4,7 +4,7 @@ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing, runOnJS
4
4
  import React, { forwardRef, useRef, useEffect, useMemo, createElement } from 'react';
5
5
  import useInnerProps, { getCustomEvent } from './getInnerListeners';
6
6
  import useNodesRef from './useNodesRef'; // 引入辅助函数
7
- import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, flatGesture } from './utils';
7
+ import { useTransformStyle, splitStyle, splitProps, useLayout, wrapChildren, extendObject, flatGesture, useRunOnJSCallback } from './utils';
8
8
  import { SwiperContext } from './context';
9
9
  import Portal from './mpx-portal';
10
10
  /**
@@ -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, 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 } = 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;
@@ -112,10 +112,10 @@ const SwiperWrapper = forwardRef((props, ref) => {
112
112
  // 每个元素的宽度 or 高度,有固定值直接初始化无则0
113
113
  const step = useSharedValue(initStep);
114
114
  // 记录选中元素的索引值
115
- const currentIndex = useSharedValue(props.current || 0);
115
+ const currentIndex = useSharedValue(propCurrent);
116
116
  // const initOffset = getOffset(props.current || 0, initStep)
117
117
  // 记录元素的偏移量
118
- const offset = useSharedValue(getOffset(props.current || 0, initStep));
118
+ const offset = useSharedValue(getOffset(propCurrent, initStep));
119
119
  const strAbso = 'absolute' + dir.toUpperCase();
120
120
  const strVelocity = 'velocity' + dir.toUpperCase();
121
121
  // 标识手指触摸和抬起, 起点在onBegin
@@ -170,7 +170,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
170
170
  const iStep = dir === 'x' ? realWidth : realHeight;
171
171
  if (iStep !== step.value) {
172
172
  step.value = iStep;
173
- updateCurrent(props.current || 0, iStep);
173
+ updateCurrent(propCurrent, iStep);
174
174
  updateAutoplay();
175
175
  }
176
176
  }
@@ -272,7 +272,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
272
272
  easing: easeMap[easeingFunc]
273
273
  }, () => {
274
274
  currentIndex.value = nextIndex;
275
- runOnJS(loop)();
275
+ runOnJS(runOnJSCallback)('loop');
276
276
  });
277
277
  }
278
278
  else {
@@ -288,7 +288,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
288
288
  // 将开始位置设置为真正的位置
289
289
  offset.value = initOffset;
290
290
  currentIndex.value = nextIndex;
291
- runOnJS(loop)();
291
+ runOnJS(runOnJSCallback)('loop');
292
292
  });
293
293
  }
294
294
  else {
@@ -300,7 +300,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
300
300
  easing: easeMap[easeingFunc]
301
301
  }, () => {
302
302
  currentIndex.value = nextIndex;
303
- runOnJS(loop)();
303
+ runOnJS(runOnJSCallback)('loop');
304
304
  });
305
305
  }
306
306
  }
@@ -325,12 +325,19 @@ const SwiperWrapper = forwardRef((props, ref) => {
325
325
  resumeLoop
326
326
  };
327
327
  }, []);
328
- function handleSwiperChange(current) {
329
- if (props.current !== currentIndex.value) {
328
+ function handleSwiperChange(current, pCurrent) {
329
+ if (pCurrent !== currentIndex.value) {
330
330
  const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
331
331
  bindchange && bindchange(eventData);
332
332
  }
333
333
  }
334
+ const runOnJSCallbackRef = useRef({
335
+ loop,
336
+ pauseLoop,
337
+ resumeLoop,
338
+ handleSwiperChange
339
+ });
340
+ const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef);
334
341
  function getOffset(index, stepValue) {
335
342
  if (!stepValue)
336
343
  return 0;
@@ -348,12 +355,12 @@ const SwiperWrapper = forwardRef((props, ref) => {
348
355
  const targetOffset = getOffset(index || 0, stepValue);
349
356
  if (targetOffset !== offset.value) {
350
357
  // 内部基于props.current!==currentIndex.value决定是否使用动画及更新currentIndex.value
351
- if (props.current !== undefined && props.current !== currentIndex.value) {
358
+ if (propCurrent !== undefined && propCurrent !== currentIndex.value) {
352
359
  offset.value = withTiming(targetOffset, {
353
360
  duration: easeDuration,
354
361
  easing: easeMap[easeingFunc]
355
362
  }, () => {
356
- currentIndex.value = props.current || 0;
363
+ currentIndex.value = propCurrent;
357
364
  });
358
365
  }
359
366
  else {
@@ -373,7 +380,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
373
380
  useAnimatedReaction(() => currentIndex.value, (newIndex, preIndex) => {
374
381
  // 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
375
382
  if (newIndex !== preIndex && bindchange) {
376
- runOnJS(handleSwiperChange)(newIndex);
383
+ runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent);
377
384
  }
378
385
  });
379
386
  useEffect(() => {
@@ -406,10 +413,10 @@ const SwiperWrapper = forwardRef((props, ref) => {
406
413
  useEffect(() => {
407
414
  // 1. 如果用户在touch的过程中, 外部更新了current以外部为准(小程序表现)
408
415
  // 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
409
- if (props.current !== currentIndex.value) {
410
- updateCurrent(props.current || 0, step.value);
416
+ if (propCurrent !== currentIndex.value) {
417
+ updateCurrent(propCurrent, step.value);
411
418
  }
412
- }, [props.current]);
419
+ }, [propCurrent]);
413
420
  useEffect(() => {
414
421
  autoplayShared.value = autoplay;
415
422
  updateAutoplay();
@@ -502,7 +509,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
502
509
  if (touchfinish.value !== false) {
503
510
  currentIndex.value = selectedIndex;
504
511
  offset.value = resetOffset;
505
- runOnJS(resumeLoop)();
512
+ runOnJS(runOnJSCallback)('resumeLoop');
506
513
  }
507
514
  });
508
515
  }
@@ -513,7 +520,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
513
520
  }, () => {
514
521
  if (touchfinish.value !== false) {
515
522
  currentIndex.value = selectedIndex;
516
- runOnJS(resumeLoop)();
523
+ runOnJS(runOnJSCallback)('resumeLoop');
517
524
  }
518
525
  });
519
526
  }
@@ -535,7 +542,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
535
542
  }, () => {
536
543
  if (touchfinish.value !== false) {
537
544
  currentIndex.value = moveToIndex;
538
- runOnJS(resumeLoop)();
545
+ runOnJS(runOnJSCallback)('resumeLoop');
539
546
  }
540
547
  });
541
548
  }
@@ -562,20 +569,11 @@ const SwiperWrapper = forwardRef((props, ref) => {
562
569
  'worklet';
563
570
  const { diffOffset, half, isTriggerUpdateHalf } = computeHalf(eventData);
564
571
  if (+diffOffset === 0) {
565
- runOnJS(resumeLoop)();
572
+ runOnJS(runOnJSCallback)('resumeLoop');
566
573
  }
567
574
  else if (isTriggerUpdateHalf) {
568
- // 如果触发了onUpdate时的索引变更,则直接以update时的index为准
569
- const targetIndex = !circularShared.value ? currentIndex.value : currentIndex.value + patchElmNumShared.value - 1;
570
- offset.value = withTiming(-targetIndex * step.value, {
571
- duration: easeDuration,
572
- easing: easeMap[easeingFunc]
573
- }, () => {
574
- if (touchfinish.value !== false) {
575
- currentIndex.value = targetIndex;
576
- runOnJS(resumeLoop)();
577
- }
578
- });
575
+ // 如果触发了onUpdate时的索引变更
576
+ handleEnd(eventData);
579
577
  }
580
578
  else if (half) {
581
579
  handleEnd(eventData);
@@ -651,15 +649,15 @@ const SwiperWrapper = forwardRef((props, ref) => {
651
649
  return;
652
650
  touchfinish.value = false;
653
651
  cancelAnimation(offset);
654
- runOnJS(pauseLoop)();
652
+ runOnJS(runOnJSCallback)('pauseLoop');
655
653
  preAbsolutePos.value = e[strAbso];
656
654
  moveTranstion.value = e[strAbso];
657
655
  })
658
656
  .onUpdate((e) => {
659
657
  'worklet';
660
- if (touchfinish.value)
661
- return;
662
658
  const moveDistance = e[strAbso] - preAbsolutePos.value;
659
+ if (touchfinish.value || moveDistance === 0)
660
+ return;
663
661
  const eventData = {
664
662
  translation: moveDistance,
665
663
  transdir: moveDistance
@@ -146,8 +146,8 @@ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
146
146
  })
147
147
  })
148
148
  }
149
- if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.lazyLoadPageErrorHandler === 'function') {
150
- mpxGlobal.__mpx.config.rnConfig.lazyLoadPageErrorHandler({
149
+ if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.onLazyLoadPageError === 'function') {
150
+ mpxGlobal.__mpx.config.rnConfig.onLazyLoadPageError({
151
151
  subpackage: chunkName,
152
152
  errType: e.type
153
153
  })