反应本地动画将一个单词淡入另一个单词

发布于 2025-02-04 19:58:52 字数 1455 浏览 3 评论 0原文

当使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文