英文:
Animate a Reanimated Animated.View from zero width to flex fill smoothly
问题
我有一个 react-native-reanimated
视图,当 flex: 0
时宽度为零,当 flex: 1
时填充可用宽度。
我想要平滑地动画过渡,使视图从零宽度动态增长到填充可用宽度,同时也要动画化任何元素随着其增长而动画化:
[#1 第一个元素] -- [#2 我想要增长的元素] -- [#3 应该被推动动画化的元素,因为 #2 增长了动画]
在我的初始视图中,因为 #2 宽度为零,看起来像 [#1] -- [#3]
。我想要将 #2 的 flex
从 0
动画到 1
,但它立即动画到全宽度而不是平滑动画化。我可以想象为什么会发生这种情况(因为 flex 是相对的,在只有一个填充 flex 的元素时,非零值之间没有区别),但不知道如何解决它。
考虑到:
- 我的动画元素的全宽度是动态的
- 动画元素后面的元素也需要在布局中 动画 推动
如何使 Reanimated 视图动画地增长并动画地推动其后的任何元素在布局中?
我正在使用 Reanimated 3.4.1。
英文:
I have a react-native-reanimated
View that is zero width when flex: 0
and fills available width when flex: 1
.
I want to animate the transition smoothly, making the view animate from 0 width to fill availabla width dynamically, while also animating any elements as it grows:
[#1 first elem] -- [#2 elem i want to grow] -- [#3 elem that should be pushed animated because #2 grows animated]
In my initial view, as #2 has zero width, it looks like [#1] -- [#3]
. I want to animate flex
of #2 from 0
to 1
, but it animates immediately to full width instead of smoothly animating. I can imagine why this happens (as flex is relative, there is no difference between non-zero values as long as it's the only flex-filling element) but don't know how to solve it.
Given that:
- The full width of my animating element is dynamic
- The elements after the animating element also need to be pushed animated in the layout
How can I animate a Reanimated View to grow in size and animatedly push any elements after it in the layout?
I'm using Reanimated 3.4.1.
答案1
得分: 0
我已测量容器视图、第一个元素(在动画/增长之前的元素)、最后一个元素(在动画/增长之后的元素)的布局,计算可用空间(容器 - 第一个元素的宽度 - 最后一个元素的宽度 - 任何填充等),并将元素的宽度动画到该值。
英文:
I've ended up measuring container view, first element (the one before the animated/growing), last element (the one after the animated/growing) on layout, calculated available space (container - first element's width - last element's width - any paddings etc) and animated the width of the element to that value.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论