@mpxjs/webpack-plugin 2.10.15-1 → 2.10.15-3
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-picker-view-column/index.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +25 -30
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +16 -9
- package/lib/runtime/components/react/mpx-async-suspense.tsx +2 -2
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +3 -3
- package/lib/runtime/components/react/mpx-scroll-view.tsx +30 -35
- package/lib/runtime/components/react/mpx-swiper.tsx +16 -9
- package/lib/runtime/optionProcessor.js +11 -3
- package/lib/runtime/optionProcessorReact.js +2 -2
- package/lib/web/processMainScript.js +2 -1
- package/package.json +1 -1
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
|
-
|
|
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?.
|
|
104
|
-
mpxGlobal.__mpx.config.rnConfig.
|
|
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
|
});
|
|
@@ -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
|
|
161
|
-
if (typeof
|
|
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
|
-
|
|
175
|
+
onPickerVibrate();
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
}
|
|
@@ -292,20 +292,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
292
292
|
snapScrollTop.current = y;
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
function onScrollTouchStart(e) {
|
|
296
|
-
const { bindtouchstart } = props;
|
|
297
|
-
bindtouchstart && bindtouchstart(e);
|
|
298
|
-
if (enhanced) {
|
|
299
|
-
binddragstart &&
|
|
300
|
-
binddragstart(getCustomEvent('dragstart', e, {
|
|
301
|
-
detail: {
|
|
302
|
-
scrollLeft: scrollOptions.current.scrollLeft,
|
|
303
|
-
scrollTop: scrollOptions.current.scrollTop
|
|
304
|
-
},
|
|
305
|
-
layoutRef
|
|
306
|
-
}, props));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
295
|
function onScrollTouchMove(e) {
|
|
310
296
|
bindtouchmove && bindtouchmove(e);
|
|
311
297
|
if (enhanced) {
|
|
@@ -319,19 +305,6 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
319
305
|
}, props));
|
|
320
306
|
}
|
|
321
307
|
}
|
|
322
|
-
function onScrollTouchEnd(e) {
|
|
323
|
-
bindtouchend && bindtouchend(e);
|
|
324
|
-
if (enhanced) {
|
|
325
|
-
binddragend &&
|
|
326
|
-
binddragend(getCustomEvent('dragend', e, {
|
|
327
|
-
detail: {
|
|
328
|
-
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
329
|
-
scrollTop: scrollOptions.current.scrollTop || 0
|
|
330
|
-
},
|
|
331
|
-
layoutRef
|
|
332
|
-
}, props));
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
308
|
function onScrollDrag(e) {
|
|
336
309
|
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset;
|
|
337
310
|
updateScrollOptions(e, { scrollLeft, scrollTop });
|
|
@@ -347,6 +320,30 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
347
320
|
hasCallScrollToLower.current = false;
|
|
348
321
|
hasCallScrollToUpper.current = false;
|
|
349
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
|
+
}
|
|
350
347
|
}
|
|
351
348
|
// 处理刷新
|
|
352
349
|
function onRefresh() {
|
|
@@ -505,11 +502,9 @@ const _ScrollView = forwardRef((scrollViewProps = {}, ref) => {
|
|
|
505
502
|
ref: scrollViewRef,
|
|
506
503
|
onScroll: enableSticky ? scrollHandler : onScroll,
|
|
507
504
|
onContentSizeChange: onContentSizeChange,
|
|
508
|
-
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
|
|
509
505
|
bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
|
|
510
|
-
bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
|
|
511
506
|
onScrollBeginDrag: onScrollDragStart,
|
|
512
|
-
onScrollEndDrag:
|
|
507
|
+
onScrollEndDrag: onScrollDragEnd,
|
|
513
508
|
onMomentumScrollEnd: onScrollEnd
|
|
514
509
|
}, (simultaneousHandlers ? { simultaneousHandlers } : {}), (waitForHandlers ? { waitFor: waitForHandlers } : {}), layoutProps);
|
|
515
510
|
if (enhanced) {
|
|
@@ -120,6 +120,8 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
120
120
|
const strVelocity = 'velocity' + dir.toUpperCase();
|
|
121
121
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
122
122
|
const touchfinish = useSharedValue(true);
|
|
123
|
+
// 记录onUpdate时的方向,用于进行onFinalize中的值修正
|
|
124
|
+
const preUpdateTransDir = useSharedValue(0);
|
|
123
125
|
// 记录上一帧的绝对定位坐标
|
|
124
126
|
const preAbsolutePos = useSharedValue(0);
|
|
125
127
|
// 记录从onBegin 到 onTouchesUp 时移动的距离
|
|
@@ -325,11 +327,9 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
325
327
|
resumeLoop
|
|
326
328
|
};
|
|
327
329
|
}, []);
|
|
328
|
-
function handleSwiperChange(current
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
bindchange && bindchange(eventData);
|
|
332
|
-
}
|
|
330
|
+
function handleSwiperChange(current) {
|
|
331
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef });
|
|
332
|
+
bindchange && bindchange(eventData);
|
|
333
333
|
}
|
|
334
334
|
const runOnJSCallbackRef = useRef({
|
|
335
335
|
loop,
|
|
@@ -379,7 +379,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
379
379
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
380
380
|
useAnimatedReaction(() => currentIndex.value, (newIndex, preIndex) => {
|
|
381
381
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
382
|
-
if (newIndex !== preIndex && bindchange) {
|
|
382
|
+
if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
|
|
383
383
|
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent);
|
|
384
384
|
}
|
|
385
385
|
});
|
|
@@ -411,9 +411,9 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
411
411
|
}
|
|
412
412
|
}, [children.length]);
|
|
413
413
|
useEffect(() => {
|
|
414
|
-
// 1. 如果用户在touch的过程中, 外部更新了current
|
|
414
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
|
|
415
415
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
416
|
-
if (propCurrent !== currentIndex.value) {
|
|
416
|
+
if (propCurrent !== currentIndex.value && touchfinish.value) {
|
|
417
417
|
updateCurrent(propCurrent, step.value);
|
|
418
418
|
}
|
|
419
419
|
}, [propCurrent]);
|
|
@@ -662,6 +662,7 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
662
662
|
translation: moveDistance,
|
|
663
663
|
transdir: moveDistance
|
|
664
664
|
};
|
|
665
|
+
preUpdateTransDir.value = moveDistance;
|
|
665
666
|
// 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
|
|
666
667
|
const { half } = computeHalf(eventData);
|
|
667
668
|
if (childrenLength.value > 1 && half) {
|
|
@@ -702,11 +703,17 @@ const SwiperWrapper = forwardRef((props, ref) => {
|
|
|
702
703
|
if (touchfinish.value)
|
|
703
704
|
return;
|
|
704
705
|
touchfinish.value = true;
|
|
706
|
+
/**
|
|
707
|
+
* 安卓修正
|
|
708
|
+
* 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
|
|
709
|
+
* 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
|
|
710
|
+
* 解决方式:修正
|
|
711
|
+
*/
|
|
705
712
|
// 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
|
|
706
713
|
const moveDistance = e[strAbso] - preAbsolutePos.value;
|
|
707
714
|
const eventData = {
|
|
708
715
|
translation: moveDistance,
|
|
709
|
-
transdir: moveDistance
|
|
716
|
+
transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
|
|
710
717
|
};
|
|
711
718
|
// 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
|
|
712
719
|
if (childrenLength.value === 1) {
|
|
@@ -146,8 +146,8 @@ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
|
|
|
146
146
|
})
|
|
147
147
|
})
|
|
148
148
|
}
|
|
149
|
-
if (type === 'page' && typeof mpxGlobal.__mpx.config?.rnConfig?.
|
|
150
|
-
mpxGlobal.__mpx.config.rnConfig.
|
|
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
|
})
|
|
@@ -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
|
}
|
|
@@ -455,22 +455,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
function onScrollTouchStart (e: NativeSyntheticEvent<TouchEvent>) {
|
|
459
|
-
const { bindtouchstart } = props
|
|
460
|
-
bindtouchstart && bindtouchstart(e)
|
|
461
|
-
if (enhanced) {
|
|
462
|
-
binddragstart &&
|
|
463
|
-
binddragstart(
|
|
464
|
-
getCustomEvent('dragstart', e, {
|
|
465
|
-
detail: {
|
|
466
|
-
scrollLeft: scrollOptions.current.scrollLeft,
|
|
467
|
-
scrollTop: scrollOptions.current.scrollTop
|
|
468
|
-
},
|
|
469
|
-
layoutRef
|
|
470
|
-
}, props)
|
|
471
|
-
)
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
458
|
function onScrollTouchMove (e: NativeSyntheticEvent<TouchEvent>) {
|
|
475
459
|
bindtouchmove && bindtouchmove(e)
|
|
476
460
|
if (enhanced) {
|
|
@@ -487,22 +471,6 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
487
471
|
}
|
|
488
472
|
}
|
|
489
473
|
|
|
490
|
-
function onScrollTouchEnd (e: NativeSyntheticEvent<TouchEvent>) {
|
|
491
|
-
bindtouchend && bindtouchend(e)
|
|
492
|
-
if (enhanced) {
|
|
493
|
-
binddragend &&
|
|
494
|
-
binddragend(
|
|
495
|
-
getCustomEvent('dragend', e, {
|
|
496
|
-
detail: {
|
|
497
|
-
scrollLeft: scrollOptions.current.scrollLeft || 0,
|
|
498
|
-
scrollTop: scrollOptions.current.scrollTop || 0
|
|
499
|
-
},
|
|
500
|
-
layoutRef
|
|
501
|
-
}, props)
|
|
502
|
-
)
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
474
|
function onScrollDrag (e: NativeSyntheticEvent<NativeScrollEvent>) {
|
|
507
475
|
const { x: scrollLeft, y: scrollTop } = e.nativeEvent.contentOffset
|
|
508
476
|
updateScrollOptions(e, { scrollLeft, scrollTop })
|
|
@@ -523,6 +491,35 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
523
491
|
hasCallScrollToLower.current = false
|
|
524
492
|
hasCallScrollToUpper.current = false
|
|
525
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
|
+
}
|
|
526
523
|
}
|
|
527
524
|
|
|
528
525
|
// 处理刷新
|
|
@@ -695,11 +692,9 @@ const _ScrollView = forwardRef<HandlerRef<ScrollView & View, ScrollViewProps>, S
|
|
|
695
692
|
ref: scrollViewRef,
|
|
696
693
|
onScroll: enableSticky ? scrollHandler : onScroll,
|
|
697
694
|
onContentSizeChange: onContentSizeChange,
|
|
698
|
-
bindtouchstart: ((enhanced && binddragstart) || bindtouchstart) && onScrollTouchStart,
|
|
699
695
|
bindtouchmove: ((enhanced && binddragging) || bindtouchmove) && onScrollTouchMove,
|
|
700
|
-
bindtouchend: ((enhanced && binddragend) || bindtouchend) && onScrollTouchEnd,
|
|
701
696
|
onScrollBeginDrag: onScrollDragStart,
|
|
702
|
-
onScrollEndDrag:
|
|
697
|
+
onScrollEndDrag: onScrollDragEnd,
|
|
703
698
|
onMomentumScrollEnd: onScrollEnd
|
|
704
699
|
},
|
|
705
700
|
(simultaneousHandlers ? { simultaneousHandlers } : {}),
|
|
@@ -207,6 +207,8 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
207
207
|
const strVelocity = 'velocity' + dir.toUpperCase() as StrVelocityType
|
|
208
208
|
// 标识手指触摸和抬起, 起点在onBegin
|
|
209
209
|
const touchfinish = useSharedValue(true)
|
|
210
|
+
// 记录onUpdate时的方向,用于进行onFinalize中的值修正
|
|
211
|
+
const preUpdateTransDir = useSharedValue(0)
|
|
210
212
|
// 记录上一帧的绝对定位坐标
|
|
211
213
|
const preAbsolutePos = useSharedValue(0)
|
|
212
214
|
// 记录从onBegin 到 onTouchesUp 时移动的距离
|
|
@@ -429,11 +431,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
429
431
|
}
|
|
430
432
|
}, [])
|
|
431
433
|
|
|
432
|
-
function handleSwiperChange (current: number
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
bindchange && bindchange(eventData)
|
|
436
|
-
}
|
|
434
|
+
function handleSwiperChange (current: number) {
|
|
435
|
+
const eventData = getCustomEvent('change', {}, { detail: { current, source: 'touch' }, layoutRef: layoutRef })
|
|
436
|
+
bindchange && bindchange(eventData)
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
const runOnJSCallbackRef = useRef({
|
|
@@ -482,7 +482,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
482
482
|
// 1. 用户在当前页切换选中项,动画;用户携带选中index打开到swiper页直接选中不走动画
|
|
483
483
|
useAnimatedReaction(() => currentIndex.value, (newIndex: number, preIndex: number) => {
|
|
484
484
|
// 这里必须传递函数名, 直接写()=> {}形式会报 访问了未sharedValue信息
|
|
485
|
-
if (newIndex !== preIndex && bindchange) {
|
|
485
|
+
if (newIndex !== preIndex && preIndex !== null && preIndex !== undefined && bindchange) {
|
|
486
486
|
runOnJS(runOnJSCallback)('handleSwiperChange', newIndex, propCurrent)
|
|
487
487
|
}
|
|
488
488
|
})
|
|
@@ -517,9 +517,9 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
517
517
|
}, [children.length])
|
|
518
518
|
|
|
519
519
|
useEffect(() => {
|
|
520
|
-
// 1. 如果用户在touch的过程中, 外部更新了current
|
|
520
|
+
// 1. 如果用户在touch的过程中, 外部更新了current以内部为准(小程序表现)
|
|
521
521
|
// 2. 手指滑动过程中更新索引,外部会把current再传入进来,导致offset直接更新,增加判断不同才更新
|
|
522
|
-
if (propCurrent !== currentIndex.value) {
|
|
522
|
+
if (propCurrent !== currentIndex.value && touchfinish.value) {
|
|
523
523
|
updateCurrent(propCurrent, step.value)
|
|
524
524
|
}
|
|
525
525
|
}, [propCurrent])
|
|
@@ -757,6 +757,7 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
757
757
|
translation: moveDistance,
|
|
758
758
|
transdir: moveDistance
|
|
759
759
|
}
|
|
760
|
+
preUpdateTransDir.value = moveDistance
|
|
760
761
|
// 1. 支持滑动中超出一半更新索引的能力:只更新索引并不会影响onFinalize依据当前offset计算的索引
|
|
761
762
|
const { half } = computeHalf(eventData)
|
|
762
763
|
if (childrenLength.value > 1 && half) {
|
|
@@ -794,11 +795,17 @@ const SwiperWrapper = forwardRef<HandlerRef<View, SwiperProps>, SwiperProps>((pr
|
|
|
794
795
|
'worklet'
|
|
795
796
|
if (touchfinish.value) return
|
|
796
797
|
touchfinish.value = true
|
|
798
|
+
/**
|
|
799
|
+
* 安卓修正
|
|
800
|
+
* 问题:部分安卓机型onFinalize中拿到的absoluteX 有问题
|
|
801
|
+
* 案例:比如手指从右向左滑的时候,onUpdate拿到的是241.64346313476562, 而onFinalize中拿到的是241.81817626953125,理论上onFinalize中应该比onUpdate小才对吧
|
|
802
|
+
* 解决方式:修正
|
|
803
|
+
*/
|
|
797
804
|
// 触发过onUpdate正常情况下e[strAbso] - preAbsolutePos.value=0; 未触发过onUpdate的情况下e[strAbso] - preAbsolutePos.value 不为0
|
|
798
805
|
const moveDistance = e[strAbso] - preAbsolutePos.value
|
|
799
806
|
const eventData = {
|
|
800
807
|
translation: moveDistance,
|
|
801
|
-
transdir: moveDistance
|
|
808
|
+
transdir: Math.abs(moveDistance) > 1 ? moveDistance : preUpdateTransDir.value
|
|
802
809
|
}
|
|
803
810
|
// 1. 只有一个元素:循环 和 非循环状态,都走回弹效果
|
|
804
811
|
if (childrenLength.value === 1) {
|
|
@@ -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, {
|