team-supercharge / ShimmerLayout

DEPRECATED - Memory efficient shimmering effect for Android applications by Supercharge.
Apache License 2.0
2.51k stars 282 forks source link

ShimmerLayout animation logic ignores parent visibility and detached from window state #77

Open alexandrvj opened 5 years ago

alexandrvj commented 5 years ago

There are at least two problem cases with ShimmerLayout animation logic.

  1. If the ShimmerLayout has parent view/container and you hide parent view, animation logic inside ShimmerLayout doesn't stop. For example, we have some xml

<androidx.cardview.widget.CardView android:id="@+id/cardView" android:layout_width="match_parent" android:layout_height="48dp" android:layout_margin="8dp" android:visibility="gone">

<io.supercharge.shimmerlayout.ShimmerLayout
    android:id="@+id/shimmer"
    app:shimmer_auto_start="true"
    style="@style/ShimmerLayout">

    <View
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_gravity="center_vertical|start"
        android:layout_marginLeft="16dp"
        android:background="@color/n7"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="16dp"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="64dp"
        android:layout_marginRight="32dp"
        android:background="@color/n7"/>
</io.supercharge.shimmerlayout.ShimmerLayout>

</androidx.cardview.widget.CardView>

then our ShimmerLayout will run recursivelly in startShimmerAnimation method, although we have not even shown it to the user.

  1. More than that it leads to memory leak when using Activity#recreate method: a) ShimmerLayout#startShimmerAnimation subscribes to ViewTreeObserver#onPreDraw to detect own width; b) ShimmerLayout don't stop animation logic when parent view becomes hidden or the ShimmerLayout is detached from the window.;
alexandrvj commented 5 years ago

Up!

veghtomi commented 5 years ago

@alexandrvj

  1. issue: I believe the answer to this is very obvious. If you animate a View with built-in classes like ObjectAnimator and the animated View becomes hidden, then the animation will continue regardless. With this library, it is the same.

  2. issue: good finding. I could reproduce the memory leak, a fix will come.

matheuspontoporto commented 1 year ago

@veghtomi any updates on this fix for the leak, to stop the previous animations ?