Skip to content

支持 transition-duration delay easing等动态设置 - #2457

Open
wenwenhua wants to merge 31 commits into
masterfrom
fix-transform-order
Open

支持 transition-duration delay easing等动态设置#2457
wenwenhua wants to merge 31 commits into
masterfrom
fix-transform-order

Conversation

@wenwenhua

Copy link
Copy Markdown
Collaborator

No description provided.

// 记录上次style map
// const lastStyleRef = useRef({} as {[propName: keyof ExtendedViewStyle]: number|string})
// ** 从 style 中获取动画数据
const transitionMap = useMemo(() => {

@hiyuki hiyuki Apr 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接返回个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] })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

比较和更新这两事情不能放一个循环里解决么

const transitionMap = useMemo(() => {
return parseTransitionStyle(originalStyle)
}, [])
const newTransitionMap = parseTransitionStyle(originalStyle)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这堆逻辑到底在干嘛?为啥需要这么复杂?

return newTransitionMap
}
// 检测 transitionProperty 是否变化
if (newPropertyKeys !== initialPropertyKeysRef.current) {

@hiyuki hiyuki May 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个检测不能再上面做么,你上面本来也在遍历比较属性

@hiyuki hiyuki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有两项问题需要在合入前处理:

  1. [P1] 同步更新 Mpx2RN Skill

    该 PR 改变了 RN 对动态 transition-durationtransition-delaytransition-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

  2. [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` |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认值还是false

```js
this.dynamicStyle = {
transition: this.enableTransition ? 'transform 0.5s ease-out 0.1s' : 'transform 0s linear 0s',
transform: this.enableTransition ? 'translateX(100px)' : 'translateX(0)'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个transform和开关transition没有关系啊

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

而且上面的示例里已经有这个了

- 仅 `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` 从首次渲染起保持稳定

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有transition-property了为啥还需要设置enable-animation啊?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants