Skip to content

Conversation

wenwenhua
Copy link
Collaborator

No description provided.

@wenwenhua wenwenhua changed the title transition 动画支持 【开发中】transition 动画支持 May 9, 2025
@wenwenhua wenwenhua changed the title 【开发中】transition 动画支持 transition 动画支持 Jun 3, 2025
if (enableAnimationRef.current !== enableStyleAnimation) {
error('[Mpx runtime error]: animation usage should be stable in the component lifecycle, or you can set [enable-animation] with true.')
}
if (!enableAnimationRef.current || animationTypeRef.current === AnimationType.None || animationTypeRef.current === AnimationType.CssAnimation) {
Copy link
Collaborator

@hiyuki hiyuki Aug 28, 2025

Choose a reason for hiding this comment

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

逻辑有问题,这个条件在整个生命周期内必须保持不变

Copy link
Collaborator

Choose a reason for hiding this comment

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

enableAnimationRef需要支持一个type,来声明当前的动画是走Animation API还是transition,确保钩子的执行是稳定的

None,
API,
CssTransition,
CssAnimation
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以先不用考虑None和Animation,减少复杂度

const enableStyleAnimation = enableAnimation || animationType !== AnimationType.None
const enableAnimationRef = useRef(enableStyleAnimation)
// console.log(`useAnimationHooks animationType=${animationTypeRef.current} animationType=${enableAnimationRef.current}`)
if (animationTypeRef.current !== AnimationType.None && animationTypeRef.current !== animationType) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

逻辑漏洞,从有type变为none应该是允许的

} else {
// css 动画依赖为 style 变更
// css transition 为 style 变更驱动,但首次不计入
animationDeps.current += 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

getStyle每次都会返回新对象,直接驱动动画有性能问题,需要判断transition的目标样式值是否发生变化来进行驱动

transition: all 0.5s ease-out
```
#### [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property)
不支持设置为 all,不支持自定义
Copy link
Collaborator

@hiyuki hiyuki Aug 28, 2025

Choose a reason for hiding this comment

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

all是不是也可以支持,去style当中扫一下在支持范围内的属性进行动画

Copy link
Collaborator

Choose a reason for hiding this comment

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

不过成本高的话先不支持也行,后续还是建议直接基于Reanimated新版提供的能力来实现,那里面直接支持all

? useAnimationAPIHooks({
animation,
style: originalStyle,
transitionend: withTimingCallback
Copy link
Collaborator

Choose a reason for hiding this comment

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

用户没注册transitionend就别传呗,减少一次runOnJS

'worklet'
// 动画结束后设置下一次transformOrigin
if (finished && transitionend) {
runOnJS(transitionend)(finished, current, duration)
Copy link
Collaborator

@hiyuki hiyuki Aug 28, 2025

Choose a reason for hiding this comment

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

runOnJS防内存泄漏改造

// 根据 animation action 创建&驱动动画
function createAnimation (animatedKeys: string[] = []) {
// duration 不同需要再次执行回调,这里记录一下上次propName动画的duration
let lastDuration = -1
Copy link
Collaborator

Choose a reason for hiding this comment

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

逻辑漏洞,比如width:200ms, height:400ms, opacity:200ms,transitionend应该只需要执行两次,应该用map来存储出现过的duration

: SupportedProperty[key]
// 获取到的toVal为百分比且初始值为0时,需更新初始值为0%
if (PercentExp.test(toVal) && shareValMap[key].value === 0) {
shareValMap[key].value = '0%'
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个逻辑对于animationAPI来说也需要把?

left: 0,
transformOrigin: ['50%', '50%', 0]
}, TransformInitial)
export const SupportedProperty = Object.assign({
Copy link
Collaborator

@hiyuki hiyuki Aug 28, 2025

Choose a reason for hiding this comment

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

变量都统一小写开头吧

const { style: originalStyle = {}, transitionend } = props
// ** 从 style 中获取动画数据
const transitionMap = useMemo(() => {
return parseTransitionStyle(originalStyle)
Copy link
Collaborator

Choose a reason for hiding this comment

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

transition不支持变更吗

// translateZ: 0,
}
// 动画默认初始值
export const InitialValue: ExtendedViewStyle = Object.assign({
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个和SupportedProperty为啥要分开定义?

Copy link
Collaborator

Choose a reason for hiding this comment

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

一个是AnimationAPI的初始值?一个是transition的初始值?变量名写明确一些吧

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