-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Following a leak report, `RiveAnimationView` will now initialize the lifecycle observer with a controller parameter to allow for it release upon destruction. This still allows us to behave right when a RecyclerView allocates new `RiveAnimationView`s that never get attached to the window (and they can subsequently be released when the surrounding `Activity` is closed) but also to timely release resources when `RiveAnimationView` lives within a Fragment, so it doesn't have to wait until the whole Activity is closed. More specifically, it wasn't just the native objects that were leaking but the entire View due to the `inner RiveViewLifecycleObserver`. With the class now living outside `RiveAnimationView` we get rid of that leak. In any case, to avoid contention between `LifecycleOwner`s, when `onAttachedToWindow()` is called, the `View` will now validate the current `lifecycleOwner` and swap it out if necessary. It also add an example Activity that was reproducing the issue mentioned above. Diffs= fee8fbb01 Add fix for lifecycle observe leak (#5564) Co-authored-by: Umberto Sonnino <[email protected]>
- Loading branch information
1 parent
d96ae5c
commit 9e2beb8
Showing
9 changed files
with
183 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
094afae0b4f55e121a36981b9846ccbc9912c347 | ||
fee8fbb01b8df639d11244f6ac00bd651a324fa0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/app/rive/runtime/example/FrameActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package app.rive.runtime.example | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.commit | ||
import app.rive.runtime.kotlin.RiveAnimationView | ||
|
||
class FrameActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_frame) | ||
|
||
// Don't do anything if restoring a previous state. | ||
if (savedInstanceState != null) { | ||
return | ||
} | ||
|
||
supportFragmentManager.commit { | ||
setReorderingAllowed(true) | ||
add(R.id.frame_fragment_container, TextFragment()) | ||
} | ||
|
||
findViewById<Button>(R.id.swap_fragment).setOnClickListener { | ||
val currentFragment = | ||
supportFragmentManager.findFragmentById(R.id.frame_fragment_container) | ||
supportFragmentManager.commit { | ||
replace( | ||
R.id.frame_fragment_container, | ||
if (currentFragment is TextFragment) RiveSimpleFragment() else TextFragment() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
class TextFragment : Fragment() { | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
return inflater.inflate(R.layout.fragment_text, container, false) | ||
} | ||
} | ||
|
||
open class RiveSimpleFragment : Fragment() { | ||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
val riveFragmentContainerView = | ||
inflater.inflate(R.layout.fragment_rive, container, false) | ||
val riveView = | ||
riveFragmentContainerView.findViewById<RiveAnimationView>(R.id.rive_view_fragment) | ||
riveView.layoutParams.apply { | ||
width = 300 | ||
height = 300 | ||
} | ||
riveView.setRiveResource(R.raw.basketball) | ||
|
||
return riveFragmentContainerView | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/frame_fragment_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="16dp"> | ||
|
||
<Button | ||
android:id="@+id/swap_fragment" | ||
style="@style/Widget.Material3.Button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|center" | ||
android:text="Swap Fragment" | ||
android:textColor="@color/textColorPrimary" /> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:background="@color/colorPrimary" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/textview" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Lorem Ipsum" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters