Fixed
Status Update
Comments
er...@gmail.com <er...@gmail.com> #2
I was going to open another issue but I came across this as it is same issue I am seeing. In my use case, I used "offscreenPageLimit = 3" which causes the menu items of "FragmentA" and "FragmentB" to be seen together.
I have attached a small project that replicates the issue.
I have attached a small project that replicates the issue.
er...@gmail.com <er...@gmail.com> #3
jg...@google.com <jg...@google.com> #4
Thank you for reporting and providing a great sample / analysis. I can confirm I can reproduce both issues. We will look into it and provide an update here.
jg...@google.com <jg...@google.com> #5
Btw, as a temporary workaround before a fix is released you can probably copy-paste the FragmentStateAdapter [1] class and patch it locally?
[1]https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/viewpager2/src/main/java/androidx/viewpager2/adapter/FragmentStateAdapter.java
[1]
ch...@beyls.net <ch...@beyls.net> #6
In my case the simplest workaround was to add fragment.setMenuItemVisible(false) directly in the createFragment(position) method of my adapters, right before returning the fragment.
jg...@google.com <jg...@google.com>
je...@google.com <je...@google.com>
ap...@google.com <ap...@google.com> #7
Project: platform/frameworks/support
Branch: androidx-master-dev
commit dca177316c5d2771759641d01f956b0f49892ca7
Author: Jelle Fresen <jellefresen@google.com>
Date: Fri Jan 17 17:32:28 2020
Fix for Fragment menu visibility issue in FSA
The fragment's menu visibility is directly related to the fragment's max
lifecycle. When the max lifecycle is STARTED, the menu should not be
visible. When the max lifecycle is RESUMED, the menu should be visible.
This CL fixes the bug where a fragment that is added to the fragment
manager by FragmentStateAdapter did set the max lifecycle to STARTED,
but did not set the menu visibility to false.
Relnote: "Fixed `FragmentStateAdapter` issue with initial fragment menu
visibility when adding a fragment to the `FragmentManager`."
Bug: 144442240
Test: ./gradlew viewpager2:viewpager2:cC \
-Pandroid.testInstrumentationRunnerArguments.class=\
androidx.viewpager2.widget.FragmentLifecycleTest
Change-Id: I9d2ffa0efcb03b63eeca25f2d4e74c81446a5774
M viewpager2/viewpager2/src/androidTest/java/androidx/viewpager2/widget/FragmentLifecycleTest.kt
M viewpager2/viewpager2/src/main/java/androidx/viewpager2/adapter/FragmentStateAdapter.java
https://android-review.googlesource.com/1211984
Branch: androidx-master-dev
commit dca177316c5d2771759641d01f956b0f49892ca7
Author: Jelle Fresen <jellefresen@google.com>
Date: Fri Jan 17 17:32:28 2020
Fix for Fragment menu visibility issue in FSA
The fragment's menu visibility is directly related to the fragment's max
lifecycle. When the max lifecycle is STARTED, the menu should not be
visible. When the max lifecycle is RESUMED, the menu should be visible.
This CL fixes the bug where a fragment that is added to the fragment
manager by FragmentStateAdapter did set the max lifecycle to STARTED,
but did not set the menu visibility to false.
Relnote: "Fixed `FragmentStateAdapter` issue with initial fragment menu
visibility when adding a fragment to the `FragmentManager`."
Bug: 144442240
Test: ./gradlew viewpager2:viewpager2:cC \
-Pandroid.testInstrumentationRunnerArguments.class=\
androidx.viewpager2.widget.FragmentLifecycleTest
Change-Id: I9d2ffa0efcb03b63eeca25f2d4e74c81446a5774
M viewpager2/viewpager2/src/androidTest/java/androidx/viewpager2/widget/FragmentLifecycleTest.kt
M viewpager2/viewpager2/src/main/java/androidx/viewpager2/adapter/FragmentStateAdapter.java
je...@google.com <je...@google.com>
v....@gmail.com <v....@gmail.com> #8
I think this issue relates to https://issuetracker.google.com/issues/147550812 as well and that other issue can be marked as fixed too.
Checked on 1.1.0-alpha01 and can confirm the fix.
Checked on 1.1.0-alpha01 and can confirm the fix.
ni...@gmail.com <ni...@gmail.com> #9
Comment has been deleted.
14...@gmail.com <14...@gmail.com> #10
Still having issue in alpha, when you slide very fast, icon will disappear for a while!
je...@google.com <je...@google.com> #11
Can you file a new bug for that? It sounds like that is a separate issue where for a brief period of time there none of the fragments is in RESUMED state. We'd need to figure out if that is a bug or working as intended.
Description
As a result, between the time the fragment is added and the time it becomes the new primary fragment of the ViewPager2, its menu is briefly shown at the same time as the menu of the current primary fragment, creating a visual glitch of duplicate menu items.
Fix: update the code of FragmentStateAdapter to call newFragment.setMenuItemVisible(false) right after creating the fragment using createFragment(position)