简体   繁体   English

在React Native中启动动画视图

[英]Bouncing Animated View in react native

I'm trying to implement a view similar to something like: https://bouncingdvdlogo.com/ but for a piece of text. 我正在尝试实现类似于以下内容的视图: https : //bouncingdvdlogo.com/,只是一段文字。

My first thought was that I could just create an animated loop for both the X and Y axis and just set the top and left styles on an Animated.Text . 我的第一个想法是,我可以为X和Y轴都创建一个动画循环,并在Animated.Text上设置topleft样式。 The catch here is that I don't know what size the text will be exactly until runtime. 这里的问题是,直到运行时,我才知道文本的确切大小。

I first attempted to use measure to get the values then start the animation but measure isn't a function available on Animated.Text . 我首先尝试使用measure来获取值,然后开始动画,但是measure不是Animated.Text可用的函数。 Is there a simpler approach to solve this animation problem? 有没有更简单的方法来解决此动画问题?

I ended up trying a different approach that has worked pretty well. 我最终尝试了另一种效果很好的方法。 I hope anyone else who comes across this finds it useful. 我希望遇到此问题的其他人会发现它有用。

Basically rather than trying to measure the div and calculate its position I animated the flex property of some wrapping divs to achieve the same affect. 基本上,不是尝试测量div并计算其位置,而是设置一些包装div的flex属性的动画效果以实现相同的效果。

Here's a demo that shows how this works: https://snack.expo.io/rkNs_CR2G 这是一个演示其工作原理的演示: https : //snack.expo.io/rkNs_CR2G

I've added colors to the animated flex divs to visualize what's going on. 我已将颜色添加到动画flex div中以可视化发生的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM