我想在启动画面+ React native中播放抽奖动画

时间:2019-08-06 06:19:55

标签: reactjs react-native-android screen native splash-screen

在React native中,在应用启动之前,我们可以看到白屏。我想在应用程序图标点击时立即加载启动屏幕。我想避免白色背景。

我们可以使用react-native-splash-screen来做到这一点,但它仅支持png,不支持抽奖动画。有什么解决办法吗?

2 个答案:

答案 0 :(得分:1)

我不知道找到解决方法。我会写我的。

  1. 在您的项目中,转到android / app / build.gradle
final lottieVersion = "2.8.0"

在之后声明最终的抽奖版本

import com.android.build.OutputFile
  1. 在同一位置,您必须将此行添加到
dependencies {

这里会有一些

implementation [ ... ] 

我们将添加implementation 'com.airbnb.android:lottie:$lottieVersion'

  1. 完成此步骤后,我们会将这些行添加到launch_screen.xml

我们需要一个用于Lottie JSON的原始目录。在res目录下创建一个名为raw的目录,然后将您的Lottie动画放入raw文件夹中。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_splash">

 <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/animation_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:lottie_rawRes='@raw/loading_chat'
        app:lottie_loop="true"
        app:lottie_autoPlay="true"
    />

</LinearLayout>

此反应本机指南> = 60,谢谢

答案 1 :(得分:0)

如果您在react native中寻找动画启动屏幕,我建议您调查一下此软件包。 (npm中的搜索关键字是“ react-native-lottie-splash-screen”)

react-native-lottie-splash-screen

此程序包派生“ react-native-lottie-screen”存储库,并添加了抽奖启动画面的功能。

它使用airbnb Lottie文件实现动画启动屏幕。另外,我将其应用于多个react本机项目,并且效果很好。祝你有美好的一天!