Skip to content

Commit 0a78dbd

Browse files
authored
Merge branch 'master' into fix-sticky-position
2 parents 5b467ec + 33992dd commit 0a78dbd

File tree

23 files changed

+567
-142
lines changed

23 files changed

+567
-142
lines changed

docs-vitepress/api/app-config.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ mpx.config.webRouteConfig = {
158158
```
159159

160160
## webConfig
161-
web 环境下的一些配置,如路由模式,页面切换动画效果等
161+
web 环境下的一些配置,如路由模式
162162

163163
- **用法**:
164164
```js
@@ -169,3 +169,4 @@ mpx.config.webConfig.routeConfig = {
169169
// 禁用页面切换动画
170170
mpx.config.webConfig.disablePageTransition = true
171171
```
172+
此处的 `disablePageTransition` 后续将被废弃,请使用编译阶段的[disablePageTransition](./compile.md#webconfig)进行配置

docs-vitepress/api/compile.md

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

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

827+
`{useSSR: boolean}`
828+
829+
useSSR 默认值为 `false`,当 SSR 模式下使用异步分包时,需要将 useSSR 设置为 `true`, 其他场景不需要。
830+
831+
`{disablePageTransition: boolean}`
832+
833+
用于配置禁用/开启页面切换动画,默认禁用
834+
835+
827836
```js
828-
// vue.config.js
837+
// mpx.config.js
829838
module.exports = defineConfig({
830839
pluginOptions: {
831840
mpx: {
@@ -834,7 +843,11 @@ module.exports = defineConfig({
834843
transRpxFn: function (match, $1) {
835844
if ($1 === '0') return $1
836845
return `${$1 * +(100 / 750).toFixed(8)}vw`
837-
}
846+
},
847+
// 当 SSR 模式下使用异步分包时
848+
useSSR: true,
849+
// 开启页面切换动画
850+
disablePageTransition: false
838851
}
839852
}
840853
}

docs-vitepress/guide/advance/platform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ onShow|是
630630
onHide|是
631631
onUnload|是
632632
onError|是
633-
onServerPrefetch
633+
onServerPrefetch|
634634
created|是
635635
attached|是
636636
ready|是

docs-vitepress/guide/platform/rn.md

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ RN:
183183
> 1. 只有父级 view 节点的文本样式可以被子 text 节点继承;
184184
> 2. view 节点直接包裹文本实际上等同于 view>text>文本,Mpx 框架在编译时若检测到 view 节点直接包裹文本会自动添加一层 text 节点;
185185
> 3. 多级 text 节点可实现文本样式的继承,比如 text>text>文本 ;
186-
> 4. 若不想使用 Mpx 内部实现的 view>text>文本 这种文本样式继承,可设置`disable-default-style=true` 来关闭该继承逻辑;
187186
### 简写样式属性
188187
在 Mpx 内对于通过 class 类来定义的样式会按照 RN 的样式规则在编译处理一遍,其中最重要的一部分就是将 RN 不支持简写属性按约定的规则转换成 RN 能支持多属性结构。
189188

@@ -682,7 +681,7 @@ Mpx 输出 React Native 支持以下模版指令。
682681
注意事项
683682

684683
1. 目前不支持自定义下拉刷新节点,使用 slot="refresher" 声明无效,在 React Native 环境中还是会被当作普通节点渲染出来
685-
2. 若使用 scroll-into-view 属性,需要 id 对应的组件节点添加 wx:ref 标记,否则无法正常滚动
684+
2. 若使用 scroll-into-view 属性,需要 id 对应的组件节点添加 wx:ref 标记,否则无法正常滚动。另外组件节点需要是内置基础组件,自定义组件暂不支持。
686685
3. simultaneous-handlers 为 RN 环境特有属性,具体含义可参考[react-native-gesture-handler](https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#simultaneouswithexternalgesture)
687686
4. wait-for 为 RN 环境特有属性,具体含义可参考[react-native-gesture-handler](https://docs.swmansion.com/react-native-gesture-handler/docs/fundamentals/gesture-composition/#requireexternalgesturetofail)
688687

@@ -707,7 +706,9 @@ Mpx 输出 React Native 支持以下模版指令。
707706
| next-margin | String | `0` | 后边距,可用于露出后一项的一小部分,接受px |
708707
| scale | Boolean | `false` | 滑动时是否开启前后元素缩小,默认是缩放0.7倍, 暂不支持自定义 |
709708
| easing-function | String | `linear` | 支持 linear、easeInCubic、easeOutCubic、easeInOutCubic|
710-
| bindchange | eventhandle|| current 改变时会触发 change 事件,`event.detail = {current, source}`|
709+
| simultaneous-handlers | `Array<object>`| [] | RN环境特有属性,主要用于组件嵌套场景,允许多个手势同时识别和处理并触发,这个属性可以指定一个或多个手势处理器,处理器支持使用 this.$refs.xxx 获取组件实例来作为数组参数传递给 swiper 组件|
710+
| wait-for | `Array<object>`| [] | RN环境特有属性,主要用于组件嵌套场景,允许延迟激活处理某些手势,这个属性可以指定一个或多个手势处理器,处理器支持使用 this.$refs.xxx 获取组件实例来作为数组参数传递给 swiper 组件|
711+
| disableGesture | Boolean| false | 禁用 swiper 滑动手势。若开启用户无法通过手势滑动 swiper,只能通过开启 autoPlay 进行自动轮播|
711712

712713

713714

@@ -979,6 +980,34 @@ movable-view的可移动区域。
979980
| bindlinechange | 输入框行数变化时调用,`event.detail = { height: 0, lineCount: 0 }`,不支持 `heightRpx` |
980981
| bind:selectionchange | 选区改变事件, `event.detail = {selectionStart, selectionEnd}` |
981982

983+
#### progress
984+
进度条。
985+
986+
属性
987+
988+
| 属性名 | 类型 | 默认值 | 说明 |
989+
| ----------------------- | ------- | ------------- | ---------------------------------------------------------- |
990+
| percent | Number | `0` | 百分比进度,范围0-100 |
991+
| stroke-width | Number\|String | `6` | 进度条线的宽度,单位px |
992+
| color | String | | 进度条颜色(已废弃,请使用 activeColor) |
993+
| activeColor | String | `#09BB07` | 已选择的进度条的颜色 |
994+
| backgroundColor | String | `#EBEBEB` | 未选择的进度条的颜色 |
995+
| active | Boolean | `false` | 进度条从左往右的动画 |
996+
| active-mode | String | `backwards` | 动画播放模式,`backwards`: 从头开始播放;`forwards`: 从上次结束点接着播放 |
997+
| duration | Number | `30` | 进度增加1%所需毫秒数 |
998+
999+
事件
1000+
1001+
| 事件名 | 说明 |
1002+
| ----------------| --------------------------------------------------- |
1003+
| bindactiveend | 动画完成时触发,`event.detail = { percent }` |
1004+
1005+
注意事项
1006+
1007+
1. 不支持 `show-info` 属性,即不支持在进度条右侧显示百分比
1008+
2. 不支持 `border-radius` 属性自定义圆角大小
1009+
3. 不支持 `font-size` 属性设置右侧百分比字体大小
1010+
9821011
#### picker-view
9831012

9841013
嵌入页面的滚动选择器。其中只可放置 [*picker-view-column*](#picker-view-column) 组件,其它节点不会显示
@@ -1001,11 +1030,11 @@ movable-view的可移动区域。
10011030

10021031
- 触感反馈回调方法
10031032

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

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

10101039
#### picker-view-column
10111040

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

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

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ interface Context {
121121
createSelectorQuery: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createSelectorQuery']
122122
createIntersectionObserver: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createIntersectionObserver'],
123123
getPageId: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['getPageId']
124+
getOpenerEventChannel: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['getOpenerEventChannel']
124125
}
125126
type ExtendedComponentOptions = {
126127
disconnectOnUnmounted?: boolean
@@ -274,7 +275,7 @@ export interface RnConfig {
274275
*
275276
* @param state 当前的导航状态对象
276277
*/
277-
onStateChange?: (state: Record<string, any>) => void;
278+
onStateChange?: (state: Record<string, any>) => void
278279

279280
/**
280281
* 用于获取初始路由配置的函数。
@@ -286,7 +287,7 @@ export interface RnConfig {
286287
*/
287288
parseAppProps?: (
288289
props: Record<string, any>
289-
) => { initialRouteName?: string; initialParams?: any } | void;
290+
) => { initialRouteName?: string; initialParams?: any } | void
290291

291292
/**
292293
* 页面栈长度为 1(即根页面)且用户尝试退出 App 时触发。
@@ -295,20 +296,20 @@ export interface RnConfig {
295296
* - `true`:允许退出应用
296297
* - `false`:阻止退出应用
297298
*/
298-
onAppBack?: () => boolean;
299+
onAppBack?: () => boolean
299300

300301
/**
301302
* 是否禁用框架内部的 AppStateChange 监听。
302303
*/
303-
disableAppStateListener?: boolean;
304+
disableAppStateListener?: boolean
304305

305306
/**
306307
* 控制首页回退按钮是否展示,并监听点击事件。
307308
*
308309
* 如果绑定该函数,则首页显示返回按钮,点击后调用该函数作为回调。
309310
* 如需返回,请在函数内部手动调用 `back()`。
310311
*/
311-
onStackTopBack?: () => void;
312+
onStackTopBack?: () => void
312313

313314
/**
314315
* 容器实现的 open-type 能力集合。
@@ -324,16 +325,26 @@ export interface RnConfig {
324325
* @returns `void`
325326
*/
326327
onShareAppMessage?: (shareInfo: {
327-
title: string;
328-
path: string;
329-
imageUrl?: string;
330-
}) => void;
331-
};
328+
title: string
329+
path: string
330+
imageUrl?: string
331+
}) => void
332+
}
332333

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

338349
/**
339350
* 自定义屏幕尺寸信息,用于 mpx style 渲染等依赖尺寸的功能。
@@ -343,7 +354,7 @@ export interface RnConfig {
343354
*/
344355
customDimensions?: <T extends { window: ScaledSize; screen: ScaledSize }>(
345356
dimensions: T
346-
) => T | void;
357+
) => T | void
347358

348359
/**
349360
* 异步分包加载配置。
@@ -352,18 +363,18 @@ export interface RnConfig {
352363
/**
353364
* 加载超时时长配置,单位为毫秒。
354365
*/
355-
timeout: number;
366+
timeout: number
356367

357368
/**
358369
* 异步分包页面加载超时或失败时,自定义兜底页面文件路径。
359370
*/
360-
fallback: string;
371+
fallback: string
361372

362373
/**
363374
* 异步分包页面加载时,自定义 loading 页面文件路径。
364375
*/
365-
loading: string;
366-
};
376+
loading: string
377+
}
367378

368379
/**
369380
* 加载并执行异步分包的方法。
@@ -373,14 +384,14 @@ export interface RnConfig {
373384
* @param params.package 分包名
374385
* @returns Promise,表示加载完成
375386
*/
376-
loadChunkAsync?: (params: { url: string; package: string }) => Promise<any>;
387+
loadChunkAsync?: (params: { url: string; package: string }) => Promise<any>
377388

378389
/**
379390
* 下载多个异步分包的方法(不执行)。
380391
*
381392
* @param packages 分包名数组
382393
*/
383-
downloadChunkAsync?: (packages: Array<string>) => void;
394+
downloadChunkAsync?: (packages: Array<string>) => void
384395
}
385396

386397
interface MpxConfig {

packages/core/src/core/proxy.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ export default class MpxProxy {
334334
selectAllComponents: this.target.selectAllComponents.bind(this.target),
335335
createSelectorQuery: this.target.createSelectorQuery ? this.target.createSelectorQuery.bind(this.target) : envObj.createSelectorQuery.bind(envObj),
336336
createIntersectionObserver: this.target.createIntersectionObserver ? this.target.createIntersectionObserver.bind(this.target) : envObj.createIntersectionObserver.bind(envObj),
337-
getPageId: this.target.getPageId.bind(this.target)
337+
getPageId: this.target.getPageId.bind(this.target),
338+
getOpenerEventChannel: this.target.getOpenerEventChannel.bind(this.target)
338339
}
339340
])
340341
if (!isObject(setupResult)) {
@@ -501,11 +502,19 @@ export default class MpxProxy {
501502
const hooks = this.hooks[hookName] || []
502503
let result
503504
if (isFunction(hook) && !hooksOnly) {
505+
const setContext = hookName !== BEFORECREATE
506+
if (setContext) {
507+
setCurrentInstance(this)
508+
}
504509
result = callWithErrorHandling(hook.bind(this.target), this, `${hookName} hook`, params)
510+
if (setContext) {
511+
unsetCurrentInstance()
512+
}
505513
}
506514
hooks.forEach((hook) => {
507515
result = params ? hook(...params) : hook()
508516
})
517+
509518
return result
510519
}
511520

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/platform/template/wx/component-config/progress.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ module.exports = function ({ print }) {
1717
el.isBuiltIn = true
1818
return 'mpx-progress'
1919
},
20+
android (tag, { el }) {
21+
el.isBuiltIn = true
22+
return 'mpx-progress'
23+
},
24+
harmony (tag, { el }) {
25+
el.isBuiltIn = true
26+
return 'mpx-progress'
27+
},
28+
ios (tag, { el }) {
29+
el.isBuiltIn = true
30+
return 'mpx-progress'
31+
},
2032
props: [
2133
{
2234
test: /^(border-radius|font-size|color|active-mode|duration)$/,

packages/webpack-plugin/lib/platform/template/wx/component-config/unsupported.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const JD_UNSUPPORTED_TAG_NAME_ARR = ['functional-page-navigator', 'live-pusher',
1111
// 快应用不支持的标签集合
1212
const QA_UNSUPPORTED_TAG_NAME_ARR = ['movable-view', 'movable-area', 'open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'cover-image']
1313
// RN不支持的标签集合
14-
const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'progress', 'slider', 'audio', 'camera', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
14+
const RN_UNSUPPORTED_TAG_NAME_ARR = ['open-data', 'official-account', 'editor', 'functional-page-navigator', 'live-player', 'live-pusher', 'ad', 'slider', 'audio', 'camera', 'match-media', 'page-container', 'editor', 'keyboard-accessory', 'map']
1515

1616
/**
1717
* @param {function(object): function} print

0 commit comments

Comments
 (0)