0

I'm using Lottie and Epoxy in my Android project with DataBinding. I would like to start animation with LottieImageView when RecyclerView is snapped, but LottieImageView does not start animation, while it is set to autoPlay=true.

The Epoxy controller is below:

class MainController : EpoxyController() {

    var currentSnappedPosition = 0
        set(value) {
            field = value
            requestModelBuild()
        }

    override fun buildModels() {
        repeat(10) {
            ItemBindingModel_()
                .id(modelCountBuiltSoFar)
                .isSnapped(currentSnappedPosition == modelCountBuiltSoFar)
                .addTo(this)
        }
    }
}

currentSnappedPosition is updated when RecyclerView item is snapped, and then rquestModelBuild() is called.

The layout file is below:

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>

        <import
            type="android.view.View" />

        <variable
            name="isSnapped"
            type="boolean" />

    </data>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.airbnb.lottie.LottieAnimationView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="@{isSnapped ? View.VISIBLE : View.GONE }"
            app:lottie_autoPlay="true"
            app:lottie_loop="true"
            app:lottie_rawRes="@raw/lunar_new_year"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:text="not snapped..."
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="@{isSnapped ? View.GONE : View.VISIBLE }"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </FrameLayout>

</layout>

LottieAnimationView is set visible when the item is snapped.

The whole project is on GitHub:

Does anyone know how to auto start when LottieAnimationView set visible?

TylerH
  • 20,799
  • 66
  • 75
  • 101
MikakoTabe
  • 105
  • 1
  • 7

0 Answers0