Skip to content

Commit 61288de

Browse files
authored
Merge branch 'master' into fix-scroll-view-drag
2 parents 8db3442 + 4503e34 commit 61288de

File tree

13 files changed

+159
-83
lines changed

13 files changed

+159
-83
lines changed

docs-vitepress/api/compile.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,13 @@ module.exports = defineConfig({
824824

825825
transRpxFn 配置用于自定义输出 web 时对于 rpx 样式单位的转换逻辑,常见的方式有转换为 vw 或转换为 rem
826826

827+
`{useSSR: boolean}`
828+
829+
useSSR 默认值为 `false`,当 SSR 模式下使用异步分包时,需要将 useSSR 设置为 `true`, 其他场景不需要。
830+
831+
827832
```js
828-
// vue.config.js
833+
// mpx.config.js
829834
module.exports = defineConfig({
830835
pluginOptions: {
831836
mpx: {
@@ -834,7 +839,9 @@ module.exports = defineConfig({
834839
transRpxFn: function (match, $1) {
835840
if ($1 === '0') return $1
836841
return `${$1 * +(100 / 750).toFixed(8)}vw`
837-
}
842+
},
843+
// 当 SSR 模式下使用异步分包时
844+
useSSR: true
838845
}
839846
}
840847
}

docs-vitepress/guide/platform/rn.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,11 +1001,11 @@ movable-view的可移动区域。
10011001

10021002
- 触感反馈回调方法
10031003

1004-
通过在全局注册 `mpx.config.rnConfig.pickerVibrate` 方法,在每次滚动选择时会调用该方法。
1004+
通过在全局注册 `mpx.config.rnConfig.onPickerVibrate` 方法,在每次滚动选择时会调用该方法。
10051005

10061006
| 注册触感方法名 | 类型 | 说明 |
10071007
| ----------------------| --------------| ------------------- |
1008-
| pickerVibrate | Function | 注册自定义触感反馈方法。调用时机:在每次滚动选择时会调用该方法。可以在方法内自定义实现类似 iOS 端原生表盘的振动触感。 |
1008+
| onPickerVibrate | Function | 注册自定义触感反馈方法。调用时机:在每次滚动选择时会调用该方法。可以在方法内自定义实现类似 iOS 端原生表盘的振动触感。 |
10091009

10101010
#### picker-view-column
10111011

@@ -2597,7 +2597,7 @@ mpx.config.rnConfig.downloadChunkAsync = function (packages) {
25972597

25982598
```javascript
25992599
// RN 场景下监听异步页面加载失败的全局配置
2600-
mpx.config.rnConfig.lazyLoadPageErrorHandler = function (error) {
2600+
mpx.config.rnConfig.onLazyLoadPageError = function (error) {
26012601
console.log(
26022602
error.subpackage, // 加载失败的分包名
26032603
error.errType // 加载失败的类型:'timeout' | 'fail'

packages/core/@types/index.d.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export interface RnConfig {
274274
*
275275
* @param state 当前的导航状态对象
276276
*/
277-
onStateChange?: (state: Record<string, any>) => void;
277+
onStateChange?: (state: Record<string, any>) => void
278278

279279
/**
280280
* 用于获取初始路由配置的函数。
@@ -286,7 +286,7 @@ export interface RnConfig {
286286
*/
287287
parseAppProps?: (
288288
props: Record<string, any>
289-
) => { initialRouteName?: string; initialParams?: any } | void;
289+
) => { initialRouteName?: string; initialParams?: any } | void
290290

291291
/**
292292
* 页面栈长度为 1(即根页面)且用户尝试退出 App 时触发。
@@ -295,20 +295,20 @@ export interface RnConfig {
295295
* - `true`:允许退出应用
296296
* - `false`:阻止退出应用
297297
*/
298-
onAppBack?: () => boolean;
298+
onAppBack?: () => boolean
299299

300300
/**
301301
* 是否禁用框架内部的 AppStateChange 监听。
302302
*/
303-
disableAppStateListener?: boolean;
303+
disableAppStateListener?: boolean
304304

305305
/**
306306
* 控制首页回退按钮是否展示,并监听点击事件。
307307
*
308308
* 如果绑定该函数,则首页显示返回按钮,点击后调用该函数作为回调。
309309
* 如需返回,请在函数内部手动调用 `back()`。
310310
*/
311-
onStackTopBack?: () => void;
311+
onStackTopBack?: () => void
312312

313313
/**
314314
* 容器实现的 open-type 能力集合。
@@ -324,16 +324,26 @@ export interface RnConfig {
324324
* @returns `void`
325325
*/
326326
onShareAppMessage?: (shareInfo: {
327-
title: string;
328-
path: string;
329-
imageUrl?: string;
330-
}) => void;
331-
};
327+
title: string
328+
path: string
329+
imageUrl?: string
330+
}) => void
331+
}
332332

333333
/**
334334
* 在使用 picker-view-column 时,触发短震动反馈。
335335
*/
336-
pickerVibrate?: () => void;
336+
onPickerVibrate?: () => void
337+
338+
/**
339+
* 分包页面加载失败时触发
340+
* @param subpackage 失败分包名
341+
* @param errType 失败类型
342+
*/
343+
onLazyLoadPageError?: (error: {
344+
subpackage: string
345+
errType: 'timeout' | 'fail'
346+
}) => void
337347

338348
/**
339349
* 自定义屏幕尺寸信息,用于 mpx style 渲染等依赖尺寸的功能。
@@ -343,7 +353,7 @@ export interface RnConfig {
343353
*/
344354
customDimensions?: <T extends { window: ScaledSize; screen: ScaledSize }>(
345355
dimensions: T
346-
) => T | void;
356+
) => T | void
347357

348358
/**
349359
* 异步分包加载配置。
@@ -352,18 +362,18 @@ export interface RnConfig {
352362
/**
353363
* 加载超时时长配置,单位为毫秒。
354364
*/
355-
timeout: number;
365+
timeout: number
356366

357367
/**
358368
* 异步分包页面加载超时或失败时,自定义兜底页面文件路径。
359369
*/
360-
fallback: string;
370+
fallback: string
361371

362372
/**
363373
* 异步分包页面加载时,自定义 loading 页面文件路径。
364374
*/
365-
loading: string;
366-
};
375+
loading: string
376+
}
367377

368378
/**
369379
* 加载并执行异步分包的方法。
@@ -373,14 +383,14 @@ export interface RnConfig {
373383
* @param params.package 分包名
374384
* @returns Promise,表示加载完成
375385
*/
376-
loadChunkAsync?: (params: { url: string; package: string }) => Promise<any>;
386+
loadChunkAsync?: (params: { url: string; package: string }) => Promise<any>
377387

378388
/**
379389
* 下载多个异步分包的方法(不执行)。
380390
*
381391
* @param packages 分包名数组
382392
*/
383-
downloadChunkAsync?: (packages: Array<string>) => void;
393+
downloadChunkAsync?: (packages: Array<string>) => void
384394
}
385395

386396
interface MpxConfig {

packages/webpack-plugin/lib/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,23 @@ class MpxWebpackPlugin {
17261726
source.add('// inject pageconfigmap for screen\n' +
17271727
'var context = (function() { return this })() || Function("return this")();\n')
17281728
source.add(`context.__mpxPageConfigsMap = ${JSON.stringify(mpx.pageConfigsMap)};\n`)
1729+
1730+
if (process.env.NODE_ENV !== 'production') {
1731+
source.add(`
1732+
${globalObject}.__mpxClearAsyncChunkCache = ${globalObject}.__mpxClearAsyncChunkCache || function (ids) {
1733+
ids = JSON.stringify(ids)
1734+
var arr = ${globalObject}['${chunkLoadingGlobal}'] || []
1735+
for (var i = arr.length - 1; i >= 0; i--) {
1736+
if (JSON.stringify(arr[i][0]) === ids) {
1737+
arr.splice(i, 1)
1738+
}
1739+
}
1740+
};\n`)
1741+
}
1742+
} else {
1743+
if (process.env.NODE_ENV !== 'production') {
1744+
source.add(`${globalObject}.__mpxClearAsyncChunkCache && ${globalObject}.__mpxClearAsyncChunkCache(${JSON.stringify(chunk.ids)});\n`)
1745+
}
17291746
}
17301747
source.add(originalSource)
17311748
compilation.assets[chunkFile] = source
@@ -1825,6 +1842,7 @@ try {
18251842

18261843
compilation.chunkGroups.forEach((chunkGroup) => {
18271844
if (!chunkGroup.isInitial()) {
1845+
isReact(mpx.mode) && chunkGroup.chunks.forEach((chunk) => processChunk(chunk, false, []))
18281846
return
18291847
}
18301848

packages/webpack-plugin/lib/platform/style/wx/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,17 @@ module.exports = function getSpec ({ warn, error }) {
547547
// })
548548
// return cssMap
549549
// }
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+
}
550561

551562
return {
552563
supportedModes: ['ios', 'android', 'harmony'],
@@ -593,6 +604,12 @@ module.exports = function getSpec ({ warn, error }) {
593604
// android: formatBoxShadow,
594605
// harmony: formatBoxShadow
595606
// },
607+
{
608+
test: 'border',
609+
ios: formatBorder,
610+
android: formatBorder,
611+
harmony: formatBorder
612+
},
596613
// 通用的简写格式匹配
597614
{
598615
test: new RegExp('^(' + Object.keys(AbbreviationMap).join('|') + ')$'),

packages/webpack-plugin/lib/runtime/components/react/mpx-async-suspense.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ const AsyncSuspense: React.FC<AsyncSuspenseProps> = ({
146146
})
147147
})
148148
}
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({
151151
subpackage: chunkName,
152152
errType: e.type
153153
})

packages/webpack-plugin/lib/runtime/components/react/mpx-movable-view.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ import { StyleSheet, View, LayoutChangeEvent } from 'react-native'
2222
import useInnerProps, { getCustomEvent } from './getInnerListeners'
2323
import useNodesRef, { HandlerRef } from './useNodesRef'
2424
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'
2626
import { GestureDetector, Gesture, GestureTouchEvent, GestureStateChangeEvent, PanGestureHandlerEventPayload, PanGesture } from 'react-native-gesture-handler'
2727
import Animated, {
2828
useSharedValue,
2929
useAnimatedStyle,
3030
withDecay,
3131
runOnJS,
3232
runOnUI,
33-
useAnimatedReaction,
3433
withSpring
3534
} from 'react-native-reanimated'
3635
import { collectDataset, noop } from '@mpxjs/utils'
@@ -87,7 +86,6 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
8786
const layoutRef = useRef<any>({})
8887
const changeSource = useRef<any>('')
8988
const hasLayoutRef = useRef(false)
90-
9189
const propsRef = useRef<any>({})
9290
propsRef.current = (props || {}) as MovableViewProps
9391

@@ -208,7 +206,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
208206
const now = Date.now()
209207
if (now - lastChangeTime.value >= changeThrottleTime) {
210208
lastChangeTime.value = now
211-
runOnJS(handleTriggerChange)({ x, y, type })
209+
runOnJS(runOnJSCallback)('handleTriggerChange', { x, y, type })
212210
}
213211
}, [changeThrottleTime])
214212

@@ -233,7 +231,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
233231
: newY
234232
}
235233
if (bindchange) {
236-
runOnJS(handleTriggerChange)({
234+
runOnJS(runOnJSCallback)('handleTriggerChange', {
237235
x: newX,
238236
y: newY,
239237
type: 'setData'
@@ -408,13 +406,21 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
408406
catchtouchend && catchtouchend(e)
409407
}
410408

409+
const runOnJSCallbackRef = useRef({
410+
handleTriggerChange,
411+
triggerStartOnJS,
412+
triggerMoveOnJS,
413+
triggerEndOnJS
414+
})
415+
const runOnJSCallback = useRunOnJSCallback(runOnJSCallbackRef)
416+
411417
const gesture = useMemo(() => {
412418
const handleTriggerMove = (e: GestureTouchEvent) => {
413419
'worklet'
414420
const hasTouchmove = !!bindhtouchmove || !!bindvtouchmove || !!bindtouchmove
415421
const hasCatchTouchmove = !!catchhtouchmove || !!catchvtouchmove || !!catchtouchmove
416422
if (hasTouchmove || hasCatchTouchmove) {
417-
runOnJS(triggerMoveOnJS)({
423+
runOnJS(runOnJSCallback)('triggerMoveOnJS', {
418424
e,
419425
touchEvent: touchEvent.value,
420426
hasTouchmove,
@@ -433,7 +439,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
433439
y: changedTouches.y
434440
}
435441
if (bindtouchstart || catchtouchstart) {
436-
runOnJS(triggerStartOnJS)({ e })
442+
runOnJS(runOnJSCallback)('triggerStartOnJS', { e })
437443
}
438444
})
439445
.onStart(() => {
@@ -487,7 +493,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
487493
isFirstTouch.value = true
488494
isMoving.value = false
489495
if (bindtouchend || catchtouchend) {
490-
runOnJS(triggerEndOnJS)({ e })
496+
runOnJS(runOnJSCallback)('triggerEndOnJS', { e })
491497
}
492498
})
493499
.onEnd((e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
@@ -515,7 +521,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
515521
: y
516522
}
517523
if (bindchange) {
518-
runOnJS(handleTriggerChange)({
524+
runOnJS(runOnJSCallback)('handleTriggerChange', {
519525
x,
520526
y
521527
})
@@ -532,7 +538,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
532538
}, () => {
533539
xInertialMotion.value = false
534540
if (bindchange) {
535-
runOnJS(handleTriggerChange)({
541+
runOnJS(runOnJSCallback)('handleTriggerChange', {
536542
x: offsetX.value,
537543
y: offsetY.value
538544
})
@@ -548,7 +554,7 @@ const _MovableView = forwardRef<HandlerRef<View, MovableViewProps>, MovableViewP
548554
}, () => {
549555
yInertialMotion.value = false
550556
if (bindchange) {
551-
runOnJS(handleTriggerChange)({
557+
runOnJS(runOnJSCallback)('handleTriggerChange', {
552558
x: offsetX.value,
553559
y: offsetY.value
554560
})

packages/webpack-plugin/lib/runtime/components/react/mpx-picker-view-column/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
223223

224224
const onScroll = useCallback((e: NativeSyntheticEvent<NativeScrollEvent>) => {
225225
// 全局注册的振动触感 hook
226-
const pickerVibrate = global.__mpx?.config?.rnConfig?.pickerVibrate
227-
if (typeof pickerVibrate !== 'function') {
226+
const onPickerVibrate = global.__mpx?.config?.rnConfig?.onPickerVibrate
227+
if (typeof onPickerVibrate !== 'function') {
228228
return
229229
}
230230
const { y } = e.nativeEvent.contentOffset
@@ -238,7 +238,7 @@ const _PickerViewColumn = forwardRef<HandlerRef<ScrollView & View, ColumnProps>,
238238
y: currentId * itemRawH
239239
}
240240
// vibrateShort({ type: 'selection' })
241-
pickerVibrate()
241+
onPickerVibrate()
242242
}
243243
}
244244
}

0 commit comments

Comments
 (0)