Closed Hafizzle closed 1 year ago
I accidentally also fixed this before I saw your PR. The issue I see is that with this solution we run into the same issue that we already had before. Where sometimes the app crashes because the viewModel property of the chat fragment is not initialised.
The root of the issue is that if the ChatFragment is inside the PartyFragment, there is no provider for GroupViewModel
. Because the PartyFragment uses the subclass of that PartyViewModel
. I fixed this by making the viewModel property open and making a PartyChatFragment subclass.
I accidentally also fixed this before I saw your PR. The issue I see is that with this solution we run into the same issue that we already had before. Where sometimes the app crashes because the viewModel property of the chat fragment is not initialised.
The root of the issue is that if the ChatFragment is inside the PartyFragment, there is no provider for
GroupViewModel
. Because the PartyFragment uses the subclass of thatPartyViewModel
. I fixed this by making the viewModel property open and making a PartyChatFragment subclass.
@phillipthelen Ahh! That makes sense, thank you!!
I believe when creating a new fragment instance using FragmentStateAdapter, the parentFragment is not PartyFragment due to how FragmentStateAdapter manages it's fragments internally.
In instances where ChatFragment is created from FragmentStateAdapter, use a passed viewmodel reference.Else, use the Parent fragment as the ownerProducer.