[bug]: Translating values starting from 0 requires unit symbol

未关闭
#2,303 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
react, typescript
领域
frontend

调研方向

从链接的 CodeSandbox 中的 @react-spring/web 复现开始,跟踪当一个端点为 translateY(0),而另一个端点包含百分比时 transform 值是如何被解释的。验证 @react-spring/web 和 @react-spring/three 的行为,然后添加一个回归测试,表明切换菜单时可以平滑地进行动画,而不要求在 zero 上指定单位。

由索引模型根据 Issue 内容生成。

描述

area: core kind: bug
Which react-spring target are you using?
  • @react-spring/web
  • @react-spring/three
  • @react-spring/native
  • @react-spring/konva
  • @react-spring/zdog
What version of react-spring are you using?

9.7.3

What's Wrong?

I have a really simple toggled animation of a menu that initially is set to transform: translateY(-100%), when the state is change it slides into view at transform: translateY(0), when the state is then changed again the animation is skipped and the menu just disappears. I found this was due to not having a % unit symbol on the end, others have also found this same issue

To Reproduce
import React from "react";
import { useSpring, animated } from '@react-spring/web';

export default function Menu({ isMenuActive, data }) {
    const springs = useSpring({
        transform: isMenuActive ? `translateY(0%)` : `translateY(-100%)`,
    });

    return (
        <>
            <animated.div style={springs} className="menu-container">
               <p>Menu Items</p>
               <p>Menu Items</p>
               <p>Menu Items</p>
            </animated.div>
        </>
    );
}

Use this basic react hook to animate in the menu component.

Expected Behaviour

When the animation value start at 0 it should infer either the pixel or percentage value so it translates smoothly as it does in normal CSS.

Link to repo

https://codesandbox.io/s/kind-black-sgr767?file=/src/App.js

主要语言
TypeScript
星标
29.3k
派生
1.2k
平均合并
3 天 15 小时
30 天内合并 PR
17

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pmndrs/react-spring 的其他 Issue

查看 pmndrs/react-spring 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。