反应本地动画将一个单词淡入另一个单词
当使用React Native Animation点击按钮时,我正在尝试找到一种方法将“ Word1”淡入“ Word2”。
我现在接近它的方式是在同一位置使用绝对定位Word1和Word2,以及通过动画减少/增加每个单词的不透明度。我增加了Word1的不透明度,而模拟降低了Word2的不透明度,反之亦然。
这在iOS上效果很好,但是在Android上存在问题 - 似乎Pressable
在使用“绝对定位”时在Android中实际上无效: https://github.com/facebook/react-native/issues/27232
const englishTextAnim = useRef(
new Animated.Value(deviceLanguage === "en" ? 1 : 0)
).current;
const spanishTextAnim = useRef(
new Animated.Value(deviceLanguage == "es" ? 1 : 0)
).current;
...
<Pressable
onPress={() => {
}}
style={styles.nextButton}
>
<Animated.Text
style={[styles.nextButtonText, { opacity: englishTextAnim }]}
>
Next
</Animated.Text>
<Animated.Text
style={[styles.nextButtonText, { opacity: spanishTextAnim }]}
>
Siguiente
</Animated.Text>
</Pressable>
...
nextButton: {
alignSelf: "center",
flex: 1,
justifyContent: "center",
},
nextButtonText: {
textAlign: "center",
position: "absolute",
alignSelf: "center",
},
是否还有其他任何获得相同效果的方法(淡出一个单击按钮时向另一个单词)?
I'm trying to find a way to fade "word1" into "word2" when a button is clicked using react native animation.
The way I'm approaching it now is by using absolute positioning word1 and word2 in the same location, and via an animation reducing/increasing opacity of each word. I increase opacity of word1 while simulataneously decrease opacity of word2, and vice versa.
This works great on IOS, but theres an issue on Android - it seems like Pressable
don't really work in android when using absolute positioning: https://github.com/facebook/react-native/issues/27232
const englishTextAnim = useRef(
new Animated.Value(deviceLanguage === "en" ? 1 : 0)
).current;
const spanishTextAnim = useRef(
new Animated.Value(deviceLanguage == "es" ? 1 : 0)
).current;
...
<Pressable
onPress={() => {
}}
style={styles.nextButton}
>
<Animated.Text
style={[styles.nextButtonText, { opacity: englishTextAnim }]}
>
Next
</Animated.Text>
<Animated.Text
style={[styles.nextButtonText, { opacity: spanishTextAnim }]}
>
Siguiente
</Animated.Text>
</Pressable>
...
nextButton: {
alignSelf: "center",
flex: 1,
justifyContent: "center",
},
nextButtonText: {
textAlign: "center",
position: "absolute",
alignSelf: "center",
},
Are there any other ways of getting the same effect (fading one word into another when a button is clicked)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论