-
Notifications
You must be signed in to change notification settings - Fork 0
MvxCachingFragmentCompatActivity GetLastFragmentInfo() does not return the last added fragment. #275
Comments
Do you have any suggestions how to fix this? If we can't trust in the ArrayList's index, what do we do instead? |
I'm looking for a way to fix this now. SupportFragmentManager.Fragments is readonly so I can't reinitialize the ArrayList with other indexes. One solution that I'm working on right now is saving the fragment |
…return the last added fragment. - Removed unnused usings - Removed double casting - Used .ToFragment() extension method. - Created _lastFragmentTag - Filling _lastFragmentTag within ShowFragment if Fragment is cacheable
Good start, and I think using a Queue to store the last tags is the only option. To get the lastFragment in all scenario's right we need the following: PS: I made a quick work-around that works most of the time..... BUT sometimes it won't because the base. counts on SupportFragmentManager.Fragments and that collection isn't ordened like you would expect, so don't count on the order like done in the original GetLastFragmentInfo().
|
I created a version that works with back navigation as well |
I'm not sure if this is a bug or a misinterpretation, this is something that got me struggling for a while now.
Expected behavior
GetLastFragmentInfo() returning the last fragment that was added to it's
ArrayList
.Actual behavior
FragmentManager.Fragments
is anArrayList
and the indexes of thisArrayList
change when a new fragment is added. However when a fragment is removed thisArrayList
keeps it's indexes.When a new fragment is added through the method
ShowViewModel()
the fragment is added where the index of theArrayList
is equal to null.This means that the following line in
GetLastFragmentInfo()
does not return the last fragment add but the last fragment in theArrayList
:var lastFragment = currentCacheableFragments.Last();
Configuration
Version: 4.2.0
The text was updated successfully, but these errors were encountered: