简体   繁体   English

如何在 React Native 中实现涟漪效果

[英]How to achieve the ripple effect in React Native

在此处输入图像描述

In some applications, I see when a user is speaking the background of the user profile has these circles increasing and decreasing in radius.在某些应用程序中,我看到当用户说话时,用户个人资料的背景中这些圆圈的半径会增加和减少。

How do I achieve this using React Native and Reanimated-v2?如何使用 React Native 和 Reanimated-v2 实现这一点?

You can achieve it using react-native-lottie easily您可以使用 react-native-lottie 轻松实现它

Working example: https://codesandbox.io/s/loving-leakey-0e5j5n工作示例: https ://codesandbox.io/s/loving-leakey-0e5j5n

  1. Find the free ripple effect that you want on https://lottiefiles.com/search?q=ripple&category=animations&type=free for example https://lottiefiles.com/16138-ripple but you can search for specific keywords and use the one that looks like with audio syncing like this one https://lottiefiles.com/31698-audio-powerhttps://lottiefiles.com/search?q=ripple&category=animations&type=free上找到您想要的免费涟漪效果,例如https://lottiefiles.com/16138-ripple但您可以搜索特定关键字并使用看起来像这样的音频同步https://lottiefiles.com/31698-audio-power

  2. Download lottie json file (You will need an account for it) and you can change also layers color before download.下载 lottie json 文件(您需要一个帐户),您还可以在下载前更改图层颜色。 This这个

  3. Integrate it using https://github.com/lottie-react-native/lottie-react-native into your react-native app.使用https://github.com/lottie-react-native/lottie-react-native将其集成到您的 react-native 应用程序中。

I have created working example here for you https://codesandbox.io/s/loving-leakey-0e5j5n styles won't be perfect in example but you can update it as per your need.我在这里为您创建了工作示例https://codesandbox.io/s/loving-leakey-0e5j5n样式在示例中并不完美,但您可以根据需要对其进行更新。

import React from "react";
import { StyleSheet, Text, View } from "react-native";
import LottieView from 'lottie-react-native';

function App() {
  return (
    <View style={styles.app}>
      <View style={styles.content}>
        <Text style={styles.title}>React Native Lottie</Text>
        <View style={styles.lottieContainer}>
          <LottieView source={require("./assets/ripple.json")} autoPlay loop />
        </View>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  app: {
    flex: 1
  },
  content: {
    alignItem: "center",
    padding: 20,
    position: "relative",
    flex: 1,
    justifyContent: "center"
  },
  title: {
    fontWeight: "bold",
    fontSize: "1.5rem",
    marginVertical: "1em",
    textAlign: "center",
    zIndex: 1
  },
  lottieContainer: {
    backgroundColor: "#5295d1",
    position: "absolute",
    justifyContent: "center",
    top: 0,
    bottom: 0,
    left: 0,
    right: 0,
    zIndex: 0
  }
});

export default App;

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

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