支持 transition-duration delay easing等动态设置 - #2457
Conversation
| // 记录上次style map | ||
| // const lastStyleRef = useRef({} as {[propName: keyof ExtendedViewStyle]: number|string}) | ||
| // ** 从 style 中获取动画数据 | ||
| const transitionMap = useMemo(() => { |
There was a problem hiding this comment.
const transitionMapVersion = useMemo(()=>{
const changed = compare()
return changed ? newVersion : oldVersion
}, [originalStyle])
const transitionMap = useMemo(() => {...}, [transitionMapVersion])| const hasChanged = transitionKeys.some(key => prevStyle[key] !== originalStyle[key]) | ||
| if (hasChanged) { | ||
| transitionKeys.forEach(key => { lastTransitionStyleRef.current[key] = originalStyle[key] }) | ||
| transitionMapVersionRef.current++ |
There was a problem hiding this comment.
直接返回个new Symbol就行,不需要用这个ref自增
| const prevStyle = lastTransitionStyleRef.current | ||
| const hasChanged = transitionKeys.some(key => prevStyle[key] !== originalStyle[key]) | ||
| if (hasChanged) { | ||
| transitionKeys.forEach(key => { lastTransitionStyleRef.current[key] = originalStyle[key] }) |
| const transitionMap = useMemo(() => { | ||
| return parseTransitionStyle(originalStyle) | ||
| }, []) | ||
| const newTransitionMap = parseTransitionStyle(originalStyle) |
| return newTransitionMap | ||
| } | ||
| // 检测 transitionProperty 是否变化 | ||
| if (newPropertyKeys !== initialPropertyKeysRef.current) { |
There was a problem hiding this comment.
这个检测不能再上面做么,你上面本来也在遍历比较属性
hiyuki
left a comment
There was a problem hiding this comment.
有两项问题需要在合入前处理:
-
[P1] 同步更新 Mpx2RN Skill
该 PR 改变了 RN 对动态
transition-duration、transition-delay、transition-timing-function以及enable-animation枚举值的对外支持方式,但目前只更新了 VitePress 文档。根据仓库“文档与 Skill 同步约束”,请同步更新:.agents/skills/mpx2rn/references/rn-style-reference.md.agents/skills/mpx2rn/references/rn-template-reference.md
其中
rn-template-reference.md当前仍将enable-animation声明为boolean。 -
[P2] 修正文档示例中的无效属性
docs-vitepress/guide/rn/style.md新增的 Good 示例使用了transform-duration:transition-property:transform; transform-duration: 0;
CSS 及运行时识别的属性应为
transition-duration,当前示例无法实现动态控制过渡时长。
另外建议为动态 transition 配置补充核心单测,至少覆盖 duration 从正数切换为 0、delay/easing 更新,以及 property 变化被拒绝。当前 unit CI 的失败原因是缺少 @unocss/core,与本 PR 改动无直接关系。
| | animation | object | | 传递动画的实例, 可配合 mpx.createAnimation 方法一起使用 | | ||
| | enable-background | boolean | `false ` | RN 环境特有属性,是否要开启 background-image、background-size 和 background-position 的相关计算或渲染,请根据实际情况开启 | | ||
| | enable-animation | boolean | `false` | RN 环境特有属性,开启要开启动画渲染,请根据实际情况开启 | | ||
| | enable-animation | boolean \| `api` \| `transition` | 根据首次渲染的 `animation` 属性或 transition 样式自动检测 | RN 环境特有属性,显式指定 Animation API 或 CSS Transition 动画类型;`true` 等价于 `api` | |
| ```js | ||
| this.dynamicStyle = { | ||
| transition: this.enableTransition ? 'transform 0.5s ease-out 0.1s' : 'transform 0s linear 0s', | ||
| transform: this.enableTransition ? 'translateX(100px)' : 'translateX(0)' |
There was a problem hiding this comment.
这个transform和开关transition没有关系啊
| - 仅 `view` 组件支持动画相关属性。 | ||
|
|
||
| **自动检测与 enable-animation:** 框架会自动检测样式和属性中的动画定义来确定动画类型(如检测到 `transition` 样式或 `animation` 属性)。如果样式中一开始不存在动画定义,但后续需要动态添加(如通过 `wx:style` 动态添加 `transition`),建议使用 `enable-animation` 属性预先声明动画类型。 | ||
| **自动检测与 enable-animation:** 框架会在首次渲染时根据样式和属性中的动画定义确定动画类型(如检测到 `transition` 样式或 `animation` 属性),动画类型在组件生命周期内必须保持稳定。也可通过 `enable-animation="api"` / `enable-animation="transition"` 显式指定使用 Animation API / CSS Transition;布尔值 `true` 等价于 `api`,不能用于预声明 CSS Transition。如果首次渲染时只有 `transition-property`,时长等参数后续才通过 `wx:style` 动态设置,需使用 `enable-animation="transition"` 预先声明动画类型,同时保证 `transition-property` 从首次渲染起保持稳定。 |
There was a problem hiding this comment.
有transition-property了为啥还需要设置enable-animation啊?
No description provided.