androidbroadcast / ViewBindingPropertyDelegate

Make work with Android View Binding simpler
https://proandroiddev.com/make-android-view-binding-great-with-kotlin-b71dd9c87719
Apache License 2.0
1.42k stars 102 forks source link

Navigation Component Pop Behavior Problem #90

Closed enciyo closed 2 years ago

enciyo commented 2 years ago

Hi, I'm using the library with navigation component. I noticed a problem. This issue occurs when pop behavior is defined.

 <fragment
        android:id="@+id/profileFragment"
        android:name="by.kirich1409.viewbindingdelegate.sample.fragment.noreflection.ProfileFragment"
        android:label="ProfileFragment" >
        <action
            android:id="@+id/action_profileFragment_to_profileDialogFragment1"
            app:destination="@id/profileDialogFragment1"
            app:popUpTo="@id/profileFragment"
            app:popUpToInclusive="true" />
    </fragment>
 <fragment
        android:id="@+id/profileDialogFragment1"
        android:name="by.kirich1409.viewbindingdelegate.sample.dialog.noreflection.ProfileDialogFragment1"
        android:label="ProfileDialogFragment1" />   

OnView Destroyed is called as soon as the ProfileDialogFragment1 is opened. I guess this problem is caused by registering to lifecycle of fragment parent manager.

    private fun registerFragmentLifecycleCallbacksIfNeeded(fragment: Fragment) {
        if (fragmentLifecycleCallbacks != null) {
            return
        }

        val fragmentManager = fragment.parentFragmentManager.also { fm ->
            this.fragmentManager = fm
        }
        fragmentLifecycleCallbacks = ClearOnDestroy().also { callbacks ->
            fragmentManager.registerFragmentLifecycleCallbacks(callbacks, false)
        }
    }

You can find sample code here. issue.zip

kirich1409 commented 2 years ago

Which version of View Binding Delegate did you used?

enciyo commented 2 years ago

Which version of View Binding Delegate did you used?

1.5.2

kirich1409 commented 2 years ago

Try to use v 1.5.3

enciyo commented 2 years ago

This is working. Thank you for solution.