-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Show fragments correctly in bottom navigation #11838
Show fragments correctly in bottom navigation #11838
Conversation
You can trigger optional UI/connected tests for these changes by visiting CircleCI here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @planarvoid! I'm curious what you think about using the fragmentmanager instead of caching the fragments locally - see my comment. I haven't tested the app yet.
@@ -281,31 +288,45 @@ class WPMainNavigationView @JvmOverloads constructor( | |||
} | |||
|
|||
private inner class NavAdapter { | |||
private val mFragments = SparseArray<Fragment>(numPages()) | |||
private val mFragments = mutableMapOf<PageType, Fragment>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to manually keep references to the fragments? I'm not sure it's safe - what if we unintentionally re-use a destroyed fragment. It won't go though it's regular restoration process and we might end up in an undefined state. I'd personally rather rely on the FragmentManager implementation for the fragment caching, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I've removed the map and simplified the adapter. I think now it's much better.
WordPress/src/main/java/org/wordpress/android/ui/main/WPMainNavigationView.kt
Show resolved
Hide resolved
You can test the changes on this Pull Request by downloading the APK here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Looks and works as expected;). The issue with the ViewPager2 disappeared 🥳
Fixes #11830
Previously we were using
FragmentManager.replace
to replace fragments on bottom navigation change. This call sets the Fragment as not active. However, we were still keeping and using the fragments in the sparse array. Overall this approach works but it causes some unnecessary fragment recreation and it's buggy with child fragments. If the parent is not active, the child fragments are also not active (even if the parent is actually visible). I'm replacing this functionality withshow/hide
calls instead. The fragments get initialized the first time you open the app and when you switch the tabs (or rotate the device), the fragments are retrieved from the fragment manager and shown/hidden.To test:
PR submission checklist:
RELEASE-NOTES.txt
if necessary.