简体   繁体   English

Lottie Animation 作为我的 react-native 应用程序的原生启动画面

[英]Lottie Animation as a native splash screen for my react-native App

I'm using a lottie Animation as a splash screen for my react native app.我正在使用 lottie Animation 作为我的本机反应应用程序的初始屏幕。 the current implementation is that I've just put the lottie animation as the initial page in my navigation stack but, there is a latency until the JavaScript takes control.当前的实现是我刚刚将 lottie animation 作为我的导航堆栈中的初始页面,但是,在 JavaScript 控制之前存在延迟。 this isn't an issue on IOS but very noticeable on Android. I want to figure out if there's any way to cut out that latency.这在 IOS 上不是问题,但在 Android 上非常明显。我想弄清楚是否有任何方法可以消除这种延迟。 Basically, How to make Android draw something from the very beginning (not just white screen)?基本上,如何让 Android 从一开始就画一些东西(不仅仅是白屏)?

I have tried keeping the first frame of the animation as a native splash screen until the animation kicks in but the transition still looks very abrupt.我曾尝试将 animation 的第一帧保留为本机启动画面,直到 animation 启动,但过渡看起来仍然非常突然。

for android you have to use react-native-splash-screen and there you can show Lottie Animations.对于 android 你必须使用 react-native-splash-screen 并且你可以在那里显示 Lottie Animations。 Here is a simple example这是一个简单的例子

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash_back">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/icon"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.43"
        tools:ignore="MissingConstraints" />


    <TextView
        android:id="@+id/text_one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="@string/phone_number_tracker"
        android:textColor="#fff"
        android:textSize="20sp"
        android:textStyle="bold"
        app:fontFamily="Poppins-Medium"
        app:layout_constraintBottom_toTopOf="@+id/animationView"
        app:layout_constraintEnd_toEndOf="@+id/imageView"
        app:layout_constraintHorizontal_bias="0.516"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toBottomOf="@+id/imageView"
        app:layout_constraintVertical_bias="0.133" />

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/animationView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.18"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_bias="0.63"
        app:layout_constraintWidth_percent="0.6"
        app:lottie_autoPlay="true"
        app:lottie_loop="true"
        app:lottie_rawRes="@raw/loading" />

</androidx.constraintlayout.widget.ConstraintLayout>

for more information please visit react-native-splash-screen有关更多信息,请访问react-native-splash-screen

There is another similar question about this here.这里还有另一个类似的问题。

Lottie Splash Screen with Expo - animated splash screen with Expo Lottie Splash Screen with Expo - 带有 Expo 的动画启动画面

They recommended using react-native-animated-screen and they have an example in expo as well.他们推荐使用react-native-animated-screen并且他们在 expo 中也有一个例子。 Expo example Expo 例子

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

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