Skip to content

Commit 58d4c97

Browse files
Merge pull request #2476 from didi/inner-master
update skills & rules
2 parents 98c3995 + a550bbb commit 58d4c97

9 files changed

Lines changed: 147 additions & 56 deletions

File tree

.agents/skills/mpx-rn-dev-guide/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Mpx 是一个以微信小程序语法为基础、进行了类 Vue 语法拓展
106106

107107
需遵循以下约束:
108108

109-
1. **最小化使用**非必要时减少使用条件编译,避免大面积连续的条件编译破坏代码可读性与后期维护性;条件编译应仅最小包裹不兼容的片段
109+
1. **最小化使用**条件编译是处理跨端不兼容的**最后手段**,不是首选方案。使用条件编译之前,应先确认是否存在无需条件编译的跨端兼容写法(参见[样式开发最佳实践](./references/rn-style-practice.md)与各能力参考)。需要用条件编译时,仅最小包裹真正不兼容的片段,不要整段代码都用条件编译分叉
110110
2. **避免空选择器**:样式条件编译产物中不得留下空选择器(无样式内容的选择器),整条规则(含选择器与花括号内容)须一并被条件编译包裹。详见 [条件编译 · 避免产物中出现空选择器](./references/conditional-compile.md#避免产物中出现空选择器)
111111

112112
完整语法(样式 `@mpx-if` / 模板 `@mode` & `@_mode` & `mpxTagName@mode` / 脚本 `__mpx_mode__` / JSON 配置)参考 [条件编译](./references/conditional-compile.md)

.agents/skills/mpx-rn-dev-guide/references/rn-style-reference.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ mpx.config.rnConfig = Object.assign({}, mpx.config.rnConfig, {
211211
<text parent-font-size="16" style="font-size: 120%;">文本内容</text>
212212
```
213213

214-
3. **基于自身宽高计算**: `translateX`、`translateY`、`border-radius` 的百分比都是根据自身宽高来计算的(首次渲染不展示,在 `onLayout` 后计算生效)。
214+
3. **基于自身宽高计算**: `translateX`、`translateY`、`border-radius` 的百分比都是根据自身宽高来计算的(首次渲染不展示,在 `onLayout` 后计算生效)。其中 `translateX` / `translateY` 的百分比计算依赖 class 样式的编译转换;内联 `style` 中的字符串 transform 不会触发该计算。
215215

216216
4. **calc() 函数内的百分比**:在 `calc()` 函数表达式内使用百分比时,需要开发者设置 `parent-width` 或 `parent-height` 属性。
217217

@@ -228,18 +228,18 @@ mpx.config.rnConfig = Object.assign({}, mpx.config.rnConfig, {
228228

229229
### 文本样式继承
230230

231-
Mpx 框架抹平了平台差异,使 `view` 节点可以直接包裹文本并继承样式
231+
Mpx 框架抹平了平台差异,使 `view` 等容器节点可以直接包裹文本并向直接子级文本组件透传文本样式
232232

233233
**继承规则:**
234234

235-
1. **view -> text 继承**:只有 `view` 节点下的**直接子** `text` 节点可以继承 `view` 节点上的文本样式
235+
1. **容器 -> text 继承**:只有容器节点下的**直接子** `text` 节点可以继承容器节点上的文本样式;中间存在非 text 节点时不会继续透传
236236
2. **text 嵌套继承**:父级 `text` 节点的样式可以被嵌套的子 `text` 节点继承。
237237
3. **自动包裹**:`view` 节点直接包裹文本时,Mpx 编译时会自动添加 `text` 节点包裹文本。
238238

239239
**透传属性:**
240240

241-
- Mpx 会从 `view` 上拆分文本组件属性并透传到直接子 `text` 节点,包括:`ellipsizeMode`、`numberOfLines`、`allowFontScaling`
242-
- Mpx 会从 `view` 的样式中拆分文本样式并透传到直接子 `text` 节点,包括:`color`、`font*`、`text*`、`letterSpacing`、`lineHeight`、`includeFontPadding`、`writingDirection`
241+
- Mpx 会从容器上拆分文本组件属性并透传到直接子 `text` 节点,包括:`ellipsizeMode`、`numberOfLines`、`allowFontScaling`
242+
- Mpx 会从容器的样式中拆分文本样式并透传到直接子 `text` 节点,包括:`color`、`font*`、`text*`、`letterSpacing`、`lineHeight`、`includeFontPadding`、`writingDirection`
243243

244244
### 简写属性支持
245245

@@ -332,14 +332,14 @@ Mpx 在 RN 平台支持 `@media` 规则,但能力受限。
332332

333333
**支持特性:**
334334

335-
- 媒体类型:`screen``all`
336-
- 媒体特性:`width``min-width``max-width`
335+
- 媒体类型:可书写 `screen`
336+
- 媒体特性:`min-width``max-width`
337337
- 逻辑运算符:`and`
338338

339339
**限制:**
340340

341-
- 媒体查询中的宽度条件仅支持 `px` 单位。
342-
- 不支持 `height``orientation` 等其他特性。
341+
- 媒体查询中的宽度条件仅支持 `px` 单位,并基于运行时 `screen.width` 判断
342+
- 不支持 `width` 精确匹配、`height``orientation``all` 等其他特性。
343343

344344
### 动画支持
345345

@@ -377,7 +377,7 @@ Mpx 在 RN 平台支持 CSS 背景图及渐变背景,框架会自动处理样
377377
**支持特性:**
378378

379379
- **背景颜色**:RN 原生支持 `background-color`
380-
- **背景图**:支持 `background-image: url()` 引用图片。
380+
- **背景图**:支持 `background-image: url()` 引用图片,也支持 `background-image: none` 清空背景图
381381
- **渐变背景**:支持 `background-image: linear-gradient()` 线性渐变。
382382
- **相关属性**:完整支持 `background-size``background-position`
383383

@@ -474,7 +474,7 @@ Mpx 在 RN 平台支持 CSS 背景图及渐变背景,框架会自动处理样
474474
| --- | --- | --- |
475475
| `background` | `<background-color>` \| `<background-image>` \| `<background-repeat>` | 背景简写,不支持 `background-position``background-size` 简写 |
476476
| `background-color` | `color` | 背景色 |
477-
| `background-image` | `url()` \| `linear-gradient()` | 背景图/渐变 |
477+
| `background-image` | `url()` \| `linear-gradient()` \| `none` | 背景图/渐变 |
478478
| `background-size` | `cover` \| `contain` \| `auto` \| `length` \| `%` | 背景尺寸 |
479479
| `background-repeat` | `no-repeat` | 仅支持不重复 |
480480
| `background-position` | `center` \| `left` \| `right` \| `top` \| `bottom` \| `number` \| `%` | 背景位置 |
@@ -491,9 +491,9 @@ Mpx 在 RN 平台支持 CSS 背景图及渐变背景,框架会自动处理样
491491
| `font-weight` | `normal` \| `bold` \| `100-900` | `normal` | 字体粗细 |
492492
| `font-style` | `normal` \| `italic` | `normal` | 字体样式 |
493493
| `line-height` | `length` \| `number` \| `%` | - | 行高 |
494-
| `text-align` | `auto` \| `left` \| `right` \| `center` \| `justify` | `auto` | 文本对齐 |
495-
| `vertical-align` | `auto` \| `top` \| `bottom` \| `middle` | - | 垂直对齐(Android) |
496-
| `text-decoration` | `line style color` | - | 装饰线简写 |
494+
| `text-align` | `left` \| `right` \| `center` \| `justify` | `auto` | 文本对齐`auto` 是 RN 默认值,不支持在用户源码中显式书写 |
495+
| `vertical-align` | `auto` \| `top` \| `bottom` \| `middle` | - | 垂直对齐(Android / Harmony 支持,iOS 不支持|
496+
| `text-decoration` | `line style color` | - | 装饰线简写`text-decoration-style` / `text-decoration-color` 仅 iOS 支持 |
497497
| `text-transform` | `none` \| `uppercase` \| `lowercase` \| `capitalize` | `none` | 大小写转换 |
498498
| `letter-spacing` | `length` | - | 字符间距 |
499499
| `text-shadow` | `offset-x offset-y blur color` | - | 文本阴影(Mpx 增强) |
@@ -514,7 +514,7 @@ Mpx 在 RN 平台支持 CSS 背景图及渐变背景,框架会自动处理样
514514

515515
| 属性 | 值类型 | 说明 |
516516
| --- | --- | --- |
517-
| `box-shadow` | `<offset-x> <offset-y> <blur-radius> <spread-radius> <color>` | 阴影简写(RN 0.76+ 原生支持|
517+
| `box-shadow` | `<offset-x> <offset-y> <blur-radius> <spread-radius> <color>` | 阴影简写(依赖宿主 RN/DRN 版本原生支持|
518518
| `opacity` | `0-1` | 不透明度 |
519519

520520
### 动画 (Animation)
@@ -552,3 +552,8 @@ Mpx 在 RN 平台支持 CSS 背景图及渐变背景,框架会自动处理样
552552
- `caret-color`
553553
- `float`
554554
- `clear`
555+
556+
以下属性存在平台差异:
557+
558+
- iOS 不支持 `vertical-align`
559+
- Android / Harmony 不支持 `text-decoration-style``text-decoration-color``shadow-offset``shadow-opacity``shadow-radius`

.agents/skills/mpx-rn-dev-guide/references/rn-template-reference.md

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@
4949
- [picker-view](#picker-view)
5050
- [picker-view-column](#picker-view-column)
5151
- [picker](#picker)
52+
- [slider](#slider)
5253
- [switch](#switch)
5354
- [navigator](#navigator)
5455
- [rich-text](#rich-text)
5556
- [canvas](#canvas)
57+
- [camera](#camera)
5658
- [video](#video)
5759
- [web-view](#web-view)
5860
- [root-portal](#root-portal)
@@ -650,13 +652,13 @@ Mpx 输出 RN 内置支持了大部分常用的基础组件,详情见下方文
650652
| bounces | boolean | `true` | iOS 下 scroll-view 边界弹性控制 (同时开启 enhanced 属性后生效) |
651653
| refresher-enabled | boolean | `false` | 开启自定义下拉刷新 |
652654
| refresher-threshold | number | `45` | 设置自定义下拉刷新阈值 |
653-
| scroll-into-view | boolean | `false` | 值应为某子元素 id(id 不能以数字开头) |
655+
| scroll-into-view | string | | 值应为某子元素 id(id 不能以数字开头) |
654656
| scroll-into-view-offset | number | `0` | 跳转到 scroll-into-view 目标节点时的额外偏移 |
655657
| refresher-default-style | string | `'black'` | 设置下拉刷新默认样式,支持 `black``white``none`,仅安卓支持 |
656658
| refresher-background | string | `'#fff'` | 设置自定义下拉刷新背景颜色,仅安卓支持 |
657659
| refresher-triggered | boolean | `false` | 设置当前下拉刷新状态,true 表示已触发 |
658-
| paging-enabled | number | `false` | 分页滑动效果 (同时开启 enhanced 属性后生效),当值为 true 时,滚动条会停在滚动视图的尺寸的整数倍位置 |
659-
| show-scrollbar | number | `true` | 滚动条显隐控制 (同时开启 enhanced 属性后生效) |
660+
| paging-enabled | boolean | `false` | 分页滑动效果 (同时开启 enhanced 属性后生效),当值为 true 时,滚动条会停在滚动视图的尺寸的整数倍位置 |
661+
| show-scrollbar | boolean | `true` | 滚动条显隐控制 (同时开启 enhanced 属性后生效) |
660662
| enable-trigger-intersection-observer | boolean | `false` | RN 环境特有属性,是否开启 intersection-observer |
661663
| simultaneous-handlers | array\<object> | `[]` | RN 环境特有属性,主要用于组件嵌套场景,允许多个手势同时识别和处理并触发,这个属性可以指定一个或多个手势处理器,处理器支持使用 this.$refs.xxx 获取组件实例来作为数组参数传递给 scroll-view 组件 |
662664
| wait-for | array\<object> | `[]` | RN 环境特有属性,主要用于组件嵌套场景,允许延迟激活处理某些手势,这个属性可以指定一个或多个手势处理器,处理器支持使用 this.$refs.xxx 获取组件实例来作为数组参数传递给 scroll-view 组件 |
@@ -915,7 +917,6 @@ movable-view 的可移动区域。
915917
| auto-focus | boolean | `false` | (即将废弃,请直接使用 focus )自动聚焦,拉起键盘 |
916918
| focus | boolean | `false` | 获取焦点 |
917919
| confirm-type | string | `done` | 设置键盘右下角按钮的文字,仅在 type='text' 时生效,可选值为 `send``search``next``go``done``return` |
918-
| confirm-hold | boolean | `false` | 点击键盘右下角按钮时是否保持键盘不收起 |
919920
| hold-keyboard | boolean | `false` | 输入框聚焦时,点击页面其他地方是否收起键盘 <badge type="tip" text="2.10.18+" /> |
920921
| cursor | number | | 指定 focus 时的光标位置 |
921922
| cursor-color | string | | 光标颜色 |
@@ -973,6 +974,10 @@ movable-view 的可移动区域。
973974
| bindlinechange | 输入框行数变化时调用,`event.detail = { height: 0, lineCount: 0 }`,不支持 `heightRpx` |
974975
| bind:selectionchange | 选区改变事件, `event.detail = {selectionStart, selectionEnd}` |
975976

977+
#### 注意事项
978+
979+
- textarea 组件不支持 `confirm-hold` 属性。
980+
976981
### progress
977982

978983
进度条。
@@ -1116,6 +1121,37 @@ level 有效值:
11161121
| city | 市级选择器 |
11171122
| region | 区级选择器 |
11181123

1124+
### slider
1125+
1126+
滑动选择器。
1127+
1128+
#### 属性
1129+
1130+
| 属性名 | 类型 | 默认值 | 说明 |
1131+
| --- | --- | --- | --- |
1132+
| min | number | `0` | 最小值 |
1133+
| max | number | `100` | 最大值 |
1134+
| step | number | `1` | 步长 |
1135+
| disabled | boolean | `false` | 是否禁用 |
1136+
| value | number | `min` | 当前取值 |
1137+
| color | string | | 背景条颜色(已废弃,请使用 backgroundColor) |
1138+
| selected-color | string | | 已选择颜色(已废弃,请使用 activeColor) |
1139+
| activeColor | string | `#1aad19` | 已选择颜色 |
1140+
| backgroundColor | string | `#e9e9e9` | 背景条颜色 |
1141+
| block-size | number | `28` | 滑块大小,RN 侧会限制在 12 到 28 之间 |
1142+
| block-color | string | `#ffffff` | 滑块颜色 |
1143+
1144+
#### 事件
1145+
1146+
| 事件名 | 说明 |
1147+
| --- | --- |
1148+
| bindchange | 完成一次拖动后触发,`event.detail = { value }` |
1149+
| bindchanging | 拖动过程中触发,`event.detail = { value }` |
1150+
1151+
#### 注意事项
1152+
1153+
- 不支持 `show-value` 属性,即不支持在滑动条右侧显示当前 value。
1154+
11191155
### switch
11201156

11211157
开关选择器。
@@ -1191,6 +1227,42 @@ level 有效值:
11911227
- canvas 的实现主要借助于 PostMessage 方式与 webview 容器通信进行绘制,所以对于严格依赖方法执行时机的场景,如调用 drawImage 绘图,再通过 getImageData 获取图片数据的场景,调用时需要使用 await 等方式来保证方法的执行时机
11921228
- 通过 Canvas.createImage 画图,图片的链接不能有特殊字符,安卓手机可能会 load 失败
11931229

1230+
### camera
1231+
1232+
系统相机。
1233+
1234+
#### 属性
1235+
1236+
| 属性名 | 类型 | 默认值 | 说明 |
1237+
| --- | --- | --- | --- |
1238+
| mode | string | `normal` | 应用模式,可选值为 `normal``scanCode` |
1239+
| resolution | string | `medium` | 分辨率,可选值为 `low``medium``high` |
1240+
| device-position | string | `back` | 摄像头朝向,可选值为 `front``back` |
1241+
| flash | string | `auto` | 闪光灯,可选值为 `auto``on``off` |
1242+
| frame-size | string | `medium` | 指定期望的相机帧数据尺寸,可选值为 `small``medium``large` |
1243+
1244+
#### 事件
1245+
1246+
| 事件名 | 说明 |
1247+
| --- | --- |
1248+
| bindinitdone | 相机初始化完成时触发,`event.detail = { maxZoom }` |
1249+
| bindstop | 摄像头在非正常终止时触发 |
1250+
| binderror | 相机发生错误时触发 |
1251+
| bindscancode |`scanCode` 模式下识别到二维码时触发,`event.detail = { result, type, scanArea }` |
1252+
1253+
#### API
1254+
1255+
| 方法名 | 说明 |
1256+
| --- | --- |
1257+
| setZoom | 设置缩放级别 |
1258+
| takePhoto | 拍照,仅支持在 `normal` 模式中使用 |
1259+
| startRecord | 开始录像 |
1260+
| stopRecord | 结束录像 |
1261+
1262+
#### 注意事项
1263+
1264+
- camera 组件基于第三方库 `react-native-vision-camera` 来实现,需要容器中安装此依赖包并完成相机权限配置。
1265+
11941266
### video
11951267

11961268
视频

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { parseValues } = require('../../../utils/string')
33

44
module.exports = function getSpec({ warn, error }) {
55
// React Native 双端都不支持的 CSS property
6-
const unsupportedPropExp = /^(white-space|text-overflow|animation|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures|caret-color)$/
6+
const unsupportedPropExp = /^(white-space|text-overflow|animation|font-variant-caps|font-variant-numeric|font-variant-east-asian|font-variant-alternates|font-variant-ligatures|caret-color|float|clear)$/
77
const unsupportedPropMode = {
88
// React Native ios 不支持的 CSS property
99
ios: /^(vertical-align)$/,
@@ -50,7 +50,7 @@ module.exports = function getSpec({ warn, error }) {
5050
'flex-direction': ['row', 'row-reverse', 'column', 'column-reverse'],
5151
'flex-wrap': ['wrap', 'nowrap', 'wrap-reverse'],
5252
'pointer-events': ['auto', 'box-none', 'box-only', 'none'],
53-
'vertical-align': ['auto', 'top', 'bottom', 'center'],
53+
'vertical-align': ['auto', 'top', 'bottom', 'middle'],
5454
position: ['relative', 'absolute', 'fixed'],
5555
'font-variant': ['small-caps', 'oldstyle-nums', 'lining-nums', 'tabular-nums', 'proportional-nums'],
5656
'text-align': ['left', 'right', 'center', 'justify'],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module.exports = function ({ print }) {
101101
qa: qaPropLog
102102
},
103103
{
104-
test: /^(always-embed|hold-keyboard|safe-password-.+)$/,
104+
test: /^(always-embed|safe-password-.+)$/,
105105
ios: iosPropLog,
106106
android: androidPropLog,
107107
harmony: harmonyPropLog

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,14 @@ module.exports = function ({ print }) {
3333
props: [
3434
{
3535
test: /^(out-of-bounds)$/,
36-
ali: qaPropLog,
37-
ios: iosPropLog,
38-
android: androidPropLog,
39-
harmony: harmonyPropLog
36+
ali: qaPropLog
4037
},
4138
{
4239
test: /^(inertia)$/,
4340
ks: ksPropLog
4441
},
4542
{
4643
test: /^(damping|friction)$/,
47-
ios: iosPropLog,
48-
android: androidPropLog,
49-
harmony: harmonyPropLog,
5044
ks: ksPropLog
5145
},
5246
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = function ({ print }) {
4949
qa: qaPropLog
5050
},
5151
{
52-
test: /^(space|decode)$/,
52+
test: /^(space)$/,
5353
ios: iosPropLog,
5454
android: androidPropLog,
5555
harmony: harmonyPropLog

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ module.exports = function ({ print }) {
1414
const qqEventLog = print({ platform: 'qq', tag: TAG_NAME, isError: false, type: 'event' })
1515
const qqPropLog = print({ platform: 'qq', tag: TAG_NAME, isError: false })
1616
const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
17-
const iosValueLogError = print({ platform: 'ios', tag: TAG_NAME, isError: true, type: 'value' })
1817
const iosPropLog = print({ platform: 'ios', tag: TAG_NAME, isError: false })
1918
const iosEventLog = print({ platform: 'ios', tag: TAG_NAME, isError: false, type: 'event' })
20-
const androidValueLogError = print({ platform: 'android', tag: TAG_NAME, isError: true, type: 'value' })
2119
const androidPropLog = print({ platform: 'android', tag: TAG_NAME, isError: false })
2220
const androidEventLog = print({ platform: 'android', tag: TAG_NAME, isError: false, type: 'event' })
23-
const harmonyValueLogError = print({ platform: 'harmony', tag: TAG_NAME, isError: true, type: 'value' })
2421
const harmonyPropLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false })
2522
const harmonyEventLog = print({ platform: 'harmony', tag: TAG_NAME, isError: false, type: 'event' })
2623
const ksPropLog = print({ platform: 'ks', tag: TAG_NAME, isError: false })
@@ -72,28 +69,7 @@ module.exports = function ({ print }) {
7269
qa: qaPropLog
7370
},
7471
{
75-
test: 'confirm-type',
76-
ios ({ name, value }) {
77-
const notSupported = ['return']
78-
if (notSupported.includes(value)) {
79-
iosValueLogError({ name, value })
80-
}
81-
},
82-
android ({ name, value }) {
83-
const notSupported = ['return']
84-
if (notSupported.includes(value)) {
85-
androidValueLogError({ name, value })
86-
}
87-
},
88-
harmony ({ name, value }) {
89-
const notSupported = ['return']
90-
if (notSupported.includes(value)) {
91-
harmonyValueLogError({ name, value })
92-
}
93-
}
94-
},
95-
{
96-
test: /^(always-embed|hold-keyboard|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
72+
test: /^(always-embed|confirm-hold|disable-default-padding|adjust-keyboard-to|fixed|show-confirm-bar)$/,
9773
ios: iosPropLog,
9874
android: androidPropLog,
9975
harmony: harmonyPropLog

0 commit comments

Comments
 (0)