feat: RN 新增 notifyDimensionsChange 配置,支持手动触发 dimensions 更新 - #2485
mackwang112 wants to merge 7 commits into
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
# Conflicts: # packages/core/src/platform/builtInMixins/styleHelperMixin.ios.js
| // 懒初始化:首次调用时将初始 dimensions 写入全局(触发 customDimensions 处理) | ||
| if (!dimensionsApplied) { | ||
| dimensionsApplied = true | ||
| applyDimensionsInfo(global.__mpxAppDimensionsInfo) |
There was a problem hiding this comment.
[P2] 首次样式计算前发生尺寸通知,会重复应用 customDimensions
dimensionsApplied 只在 formatValue() 中置为 true。如果此前收到原生 Dimensions change 事件或调用 notifyDimensionsChange(),onDimensionsChange() 已经应用了 customDimensions,但这里仍会对转换后的全局尺寸再次执行转换。
已用 PR 与基线对照复现:配置 customDimensions 为 dimensions => { dimensions.screen.width /= 2 },原始宽度 800,通知后宽度为 400,首次计算 750rpx 时却得到 200;基线在相同原生事件顺序下正确得到 400。这会导致布局与媒体查询使用错误尺寸,也影响已有的原生尺寸事件路径。
建议在 applyDimensionsInfo() 中统一维护初始化标记,恢复原实现“任何入口应用尺寸后均视为已初始化”的语义,并补充尺寸事件发生在首次样式计算前的回归测试。
|
|
||
| - 勿在 App 构造函数执行完成前依赖 `getApp()` 内业务字段已赋值完毕;与路由相关的初始化宜放在 `onLaunch` / `onShow`。 | ||
| - `getCurrentPages()` 依赖 React Navigation 焦点与 `__mpxPagesMap`,与原生小程序栈细节不完全相同。 | ||
| - `notifyDimensionsChange` 由框架在首次样式计算时自动注入,需在开始渲染后才可调用。 |
There was a problem hiding this comment.
[P3] 修正 API 注入时机,并补齐用户文档
这里写的是“首次样式计算时自动注入”,但实现是在 styleHelperMixin.ios.js 模块加载时直接执行 global.notifyDimensionsChange = onDimensionsChange,与首次 formatValue() 调用无关,建议按实际实现修正说明。
此外,docs-vitepress/guide/rn/application-api.md 在本 PR 中仅删除空行,没有新增 notifyDimensionsChange 的使用说明,尚未满足仓库对新增公开 API 的文档同步要求。建议在折叠屏适配章节补充参数、无参时从 Dimensions.get 读取原始尺寸并重新执行 customDimensions 的行为,以及调用示例。
Integrate PR #2485 and address its review feedback.
|
已合并到 #2418 |
Integrate PR #2485 and address its review feedback.
Summary
notifyDimensionsChange方法,允许手动通知框架重新计算 rpx、vw、vh、媒体查询、onResize 等依赖尺寸的功能customDimensions转换逻辑customDimensions类型定义,去除无实际约束意义的泛型参数TTest plan
notifyDimensionsChange验证 rpx/媒体查询更新customDimensions重新执行