haroldadmin / Vector

Kotlin Coroutines based MVI architecture library for Android
https://haroldadmin.github.io/Vector/
Apache License 2.0
193 stars 9 forks source link

VectorFragment should be scoped to Fragment's View lifecycle #21

Closed alan-rodriguez closed 4 years ago

alan-rodriguez commented 4 years ago

Describe the bug The fragment's view is destroyed before fragmentScope is cancelled in onDestroy(), which can cause crashes if the renderer directly references any views. The usage of data binding in the sample fragments prevents this from happening, but consumers of the library may not be using data binding.

Expected behavior Use viewLifecycleOwner.lifecycleScope from lifecycle-runtime-ktx or manually manage fragmentScope according to the Fragment's View lifecycle.

haroldadmin commented 4 years ago

Thank you for bringing this up. I agree that the renderer method should be bound to the view lifecycle instead of the fragment lifecycle. However, changing fragmentScope would be a potentially breaking change.

As alternative, i can introduce a viewScope Coroutine scope to VectorFragment and bind the renderer method to it. Would this be an acceptable solution to you?

Under the hood viewScope can simply act as an alias for viewLifecycleOwner.lifecycleScope.