Skip to content

Commit 1731e80

Browse files
committed
adjust rnConfig
1 parent 2edc7d2 commit 1731e80

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

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/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-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)