Fixed
Status Update
Comments
er...@gmail.com <er...@gmail.com> #2
Could be related to the changes you've made in FixedFragmentStateAdapter. Could you share the code, I can have a quick look.
er...@gmail.com <er...@gmail.com> #3
> Could be related to the changes you've made in FixedFragmentStateAdapter. Could you share the code, I can have a quick look.
Sorry, but I believe that is not a culprit. I just added a single line of code to avoid BadParcelableException.
https://issuetracker.google.com/issues/132840199
```
@Override
public final void restoreState(@NonNull Parcelable savedState) {
if (!mSavedStates.isEmpty() || !mFragments.isEmpty()) {
throw new IllegalStateException(
"Expected the adapter to be 'fresh' while restoring state.");
}
Bundle bundle = (Bundle) savedState;
bundle.setClassLoader(getClass().getClassLoader()); // <-- ADDED THIS LINE
for (String key : bundle.keySet()) {
...
}
```
Sorry, but I believe that is not a culprit. I just added a single line of code to avoid BadParcelableException.
```
@Override
public final void restoreState(@NonNull Parcelable savedState) {
if (!mSavedStates.isEmpty() || !mFragments.isEmpty()) {
throw new IllegalStateException(
"Expected the adapter to be 'fresh' while restoring state.");
}
Bundle bundle = (Bundle) savedState;
bundle.setClassLoader(getClass().getClassLoader()); // <-- ADDED THIS LINE
for (String key : bundle.keySet()) {
...
}
```
jg...@google.com <jg...@google.com> #4
I investigated the issue and turned out the part of the scenario which causes the problem;
1. RecyclerView.recycleViewHolderInternal()
2. hodler.doesTransientStatePreventRecycling() retuns true
3. FragmentStateAdapter.onFailedToRecycleView() -> onViewRecycled() -> removeFragment()
4. onFailedToRecycleView() retuns false, it means the ViewHolder is not recycled yet.
5. Soon after, FragmentStateAdapter.onViewAttachedToWindow() -> placeFragmentInViewHolder() -> IllegalStateException("Design assumption violated.")
1. RecyclerView.recycleViewHolderInternal()
2. hodler.doesTransientStatePreventRecycling() retuns true
3. FragmentStateAdapter.onFailedToRecycleView() -> onViewRecycled() -> removeFragment()
4. onFailedToRecycleView() retuns false, it means the ViewHolder is not recycled yet.
5. Soon after, FragmentStateAdapter.onViewAttachedToWindow() -> placeFragmentInViewHolder() -> IllegalStateException("Design assumption violated.")
jg...@google.com <jg...@google.com> #5
Hi! I have successfully created a demo project which can reproduce this issue. Please check the following repo and I hope it helps to resolve the issue.
https://github.com/h6ah4i/FragmentStateAdapterOnFailedToRecyclerViewFailure
ch...@beyls.net <ch...@beyls.net> #6
[UPDATE]
This issue still exists on ViewPager2 v1.0.0-alpha06 with RecyclerView v1.1.0-beta01.
This issue still exists on ViewPager2 v1.0.0-alpha06 with RecyclerView v1.1.0-beta01.
jg...@google.com <jg...@google.com>
je...@google.com <je...@google.com>
ap...@google.com <ap...@google.com> #7
I can confirm I can repro this and will try to provide a workaround / fix soon.
Big thanks for the sample app, repro steps and research info. Super appreciated!
Big thanks for the sample app, repro steps and research info. Super appreciated!
je...@google.com <je...@google.com>
v....@gmail.com <v....@gmail.com> #8
The easiest workaround would involve copying FragmentStateAdapter and FragmentViewHolder into your project, and in FragmentStateAdapter adding ensureFragment(holder.getAdapterPosition()) as the first line of placeFragmentInViewHolder method. Attached as a patch to your sample app.
We'll work on a proper fix. Might unblock you in the meantime though. Thanks again for reporting and a sample app.
We'll work on a proper fix. Might unblock you in the meantime though. Thanks again for reporting and a sample app.
ni...@gmail.com <ni...@gmail.com> #9
Comment has been deleted.
14...@gmail.com <14...@gmail.com> #10
Project: platform/frameworks/support
Branch: androidx-master-dev
commit a35a5180df0b98c4af4a4e119388f7d70d27ade4
Author: Jakub Gielzak <jgielzak@google.com>
Date: Tue Jul 30 17:27:14 2019
FragmentStateAdapter transient state fix follow-up
Follow-up to Ieb166c6fb48907cbb7aa46ab87a3ae4cc29591a6:
* Disabled tests on API < 16
* Updated a comment
Bug: 134246546
Test: TransientStateFragmentTest
Test: ./gradlew viewpager2:connectedCheck
Change-Id: Id27c1267d4fc75c41849291322952fc1ea0e8d0d
M viewpager2/src/androidTest/java/androidx/viewpager2/widget/TransientStateFragmentTest.kt
M viewpager2/src/main/java/androidx/viewpager2/adapter/FragmentStateAdapter.java
https://android-review.googlesource.com/1093437
https://goto.google.com/android-sha1/a35a5180df0b98c4af4a4e119388f7d70d27ade4
Branch: androidx-master-dev
commit a35a5180df0b98c4af4a4e119388f7d70d27ade4
Author: Jakub Gielzak <jgielzak@google.com>
Date: Tue Jul 30 17:27:14 2019
FragmentStateAdapter transient state fix follow-up
Follow-up to Ieb166c6fb48907cbb7aa46ab87a3ae4cc29591a6:
* Disabled tests on API < 16
* Updated a comment
Bug: 134246546
Test: TransientStateFragmentTest
Test: ./gradlew viewpager2:connectedCheck
Change-Id: Id27c1267d4fc75c41849291322952fc1ea0e8d0d
M viewpager2/src/androidTest/java/androidx/viewpager2/widget/TransientStateFragmentTest.kt
M viewpager2/src/main/java/androidx/viewpager2/adapter/FragmentStateAdapter.java
je...@google.com <je...@google.com> #11
The fix is now in place and should come out in the next release.
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)