-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear happens after onViewCreated #116
Comments
I'm having the same problem. Took me hours already and I haven't even been able to solve it. upd: in case you want to know how I fixed it. The presentation logic was very poorly written (we had to publish the application ASAP) which is why in some cases there was a fragment opening and instantly closing without displaying anything. I changed the logic so that the fragment wouldn't be needlessly created and the whole problem was gone. This sort of implies that this issue won't really need a fix. |
Hi. It's interesting case. Need to add additional check of Fragment View state. Will be investigated |
I had the same problem when I used //MainFragment
private val binding by viewBinding(FragmentMainBinding::bind, onViewDestroyed = {
printer.debug("onViewDestroyed;binding:${it.idPrint()}")
})
fun onViewCreated() {
printer.info("onViewCreated")
// set background is red,then background is white when happen bug。
binding.root.setBackgroundColor(Color.RED)
binding.root.setOnClickListener {
printer.debug("navigate to BFragment")
findNavController().navigate(R.id.bFragment, null, animOptions)
}
}
fun onDestroyView() {
printer.debug("onDestroyView")
} Then I quickly switch MainFragment and BFragment, which is easier to reproduce .
It can be found that after using I read several previous issues and learned that you have fixed similar problems. My testing came to the following conclusions:
val animOptions = navOptions {
anim {
enter = androidx.navigation.ui.R.anim.nav_default_enter_anim
exit = androidx.navigation.ui.R.anim.nav_default_exit_anim
popEnter = androidx.navigation.ui.R.anim.nav_default_pop_enter_anim
popExit = androidx.navigation.ui.R.anim.nav_default_pop_exit_anim
}
} I believe the problem lies with Fragment's transition animation, but I have no idea how to solve this problem on ViewBindingPropertyDelegate. |
Same (( Decided to use pure ViewBinding as a temporary solution |
Will be fixed in 2.0.0 |
Description:
If you quickly add and remove a fragment from the back stack, then there is a situation where onViewDestroyed is called after onViewCreated. This causes onViewCreated to use the old view. The problem is floating and reproduces over time.
I think the problem is that
postClear
ofonDestroy
fromviewLifecycle
doesn't guarantee thatclear
will be called beforeonViewCreated
.Source code:
Logs:
It can be seen that the
FragmentA onViewCreated binding = FragmentABinding@10bb7ab
was called twiceThe text was updated successfully, but these errors were encountered: