Skip to content

Commit 02ef76c

Browse files
authored
Merge branch 'master' into fix-page-params
2 parents 6a6ab8e + 93f9f7a commit 02ef76c

4 files changed

Lines changed: 98 additions & 16 deletions

File tree

docs-vitepress/guide/extend/webview-bridge.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ webviewBridge.navigateTo({
112112

113113
针对这类需求,Mpx 框架内部已提供「宿主环境能力挂载」机制,同时在 webview-bridge 中支持 invoke 通信方法,可实现 H5 与宿主环境的双向调用。
114114

115+
`webviewConfig` 需要按宿主环境配置在 `mpx.config.webConfig``mpx.config.rnConfig` 下。
116+
115117
**宿主环境中挂载getLocation**
116118
```javascript
117119
import mpx from '@mpxjs/core'

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

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,101 @@ interface AnyConstructor {
270270
prototype: any
271271
}
272272

273+
export interface WebRouteConfig {
274+
/**
275+
* Web 路由模式。
276+
*
277+
* @default 'hash'
278+
*/
279+
mode?: 'hash' | 'history' | 'abstract'
280+
281+
/**
282+
* 应用的基路径。
283+
*/
284+
base?: string
285+
286+
/**
287+
* history 模式不可用时是否回退到 hash 模式。
288+
*
289+
* @default true
290+
*/
291+
fallback?: boolean
292+
293+
/**
294+
* 全局激活链接的 CSS 类名。
295+
*/
296+
linkActiveClass?: string
297+
298+
/**
299+
* 全局精确激活链接的 CSS 类名。
300+
*/
301+
linkExactActiveClass?: string
302+
303+
/**
304+
* 自定义查询字符串解析函数。
305+
*/
306+
parseQuery?: (query: string) => Record<string, any>
307+
308+
/**
309+
* 自定义查询参数序列化函数。
310+
*/
311+
stringifyQuery?: (query: Record<string, any>) => string
312+
313+
/**
314+
* 自定义页面滚动行为。
315+
*/
316+
scrollBehavior?: (
317+
to: Record<string, any>,
318+
from: Record<string, any>,
319+
savedPosition: { x: number; y: number } | null
320+
) => any
321+
322+
[key: string]: any
323+
}
324+
273325
export interface WebviewConfig {
326+
/**
327+
* 允许加载的 H5 域名白名单。
328+
*/
274329
hostWhitelists?: Array<string>
275-
apiImplementations?: object
330+
331+
/**
332+
* WebView 调用的宿主 API 实现。
333+
*/
334+
apiImplementations?: Record<string, (...args: Array<any>) => any>
335+
}
336+
337+
export interface WebConfig {
338+
/**
339+
* Web 路由配置。
340+
*/
341+
routeConfig?: WebRouteConfig
342+
343+
/**
344+
* 是否禁用页面切换动画。
345+
*
346+
* @deprecated 请使用编译阶段的 webConfig.disablePageTransition。
347+
*/
348+
disablePageTransition?: boolean
349+
350+
/**
351+
* 是否在 Web 输出时启用内置标题栏。
352+
*
353+
* @default false
354+
*/
355+
enableTitleBar?: boolean
356+
357+
/**
358+
* Android 设备上标题栏顶部安全区的高度,单位为 px。
359+
*
360+
* @default 24
361+
*/
362+
safeAreaInsetTop?: number
363+
364+
/**
365+
* WebView 宿主能力配置。
366+
*/
367+
webviewConfig?: WebviewConfig
276368
}
277369

278370
/**
@@ -459,14 +551,8 @@ interface MpxConfig {
459551
proxyEventHandler: (e: WechatMiniprogram.CustomEvent, target: ComponentIns<{}, {}, {}, {}, []>) => void
460552
setDataHandler: (data: object, target: ComponentIns<{}, {}, {}, {}, []>) => void
461553
forceFlushSync: boolean,
462-
webRouteConfig: object,
463-
webConfig: object,
464-
/*
465-
* 支持两个属性
466-
* hostWhitelists Array 类型 支持h5域名白名单安全校验
467-
* apiImplementations webview JSSDK接口 例如getlocation
468-
*/
469-
webviewConfig: WebviewConfig,
554+
webRouteConfig: WebRouteConfig,
555+
webConfig: WebConfig,
470556
/** react-native 相关配置,用于挂载事件等,如 onShareAppMessage */
471557
rnConfig: RnConfig,
472558
}

packages/core/src/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ Mpx.config = {
145145
forceFlushSync: false,
146146
webRouteConfig: {},
147147
webConfig: {},
148-
/*
149-
支持两个属性
150-
hostWhitelists Array 类型 支持h5域名白名单安全校验
151-
apiImplementations webview JSSDK接口 例如getlocation
152-
*/
153-
webviewConfig: {},
154148
/**
155149
* react-native 相关配置,用于挂载事件等,如 onShareAppMessage
156150
*/

packages/webview-bridge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ navigateBack()
6868
```js
6969
// webapp app.web.js
7070
...
71-
mpx.config.webviewConfig = {
71+
mpx.config.webConfig.webviewConfig = {
7272
// 必须在webapp进行挂载否则h5中调用不到getLocation的返回
7373
apiImplementations: {
7474
getLocation () {

0 commit comments

Comments
 (0)