Status Update
Comments
ng...@gmail.com <ng...@gmail.com> #2
jg...@google.com <jg...@google.com> #3
Could you modify it to trigger the bug (reflect your configuration) or alternatively provide us with a minimal sample that triggers the issue?
Note we've released a Stable version of ViewPager2, so please try with that.
je...@google.com <je...@google.com> #4
In particular, I would like to know:
- The API of the device
- The locale of the device
- If you use FragmentStateAdapter or if you have your own view adapter
- The view hierarchy in which the ViewPager2 resides
- The view hierarchy of ViewPager2's children
- A screen recording of the bug
- When you say "auto drag", do you mean that you use the fakeDrag API to automatically drag the ViewPager2?
And, as Jakub stated:
- A simple application with reproduction steps, so we can reproduce locally
jg...@google.com <jg...@google.com> #5
to...@gmail.com <to...@gmail.com> #6
Open app -> click 'ViewPager2 with Nested RecyclerViews' -> rotate device
je...@google.com <je...@google.com> #7
Thanks for supplying us with the reproducible sample, I have verified that it is indeed a bug that needs fixing.
je...@google.com <je...@google.com>
ap...@google.com <ap...@google.com> #8
Branch: androidx-master-dev
commit 559a69b8575085214f055ea2b6b2de2a8673e6d2
Author: Jelle Fresen <jellefresen@google.com>
Date: Thu Jan 30 11:39:12 2020
Fix boundary check in findReferenceChild
Bug: 143989556
Bug: 148453703
Test: ./gradlew recyclerview:recyclerview:cC \
-Pandroid.testInstrumentationRunnerArguments.class=\
androidx.recyclerview.widget.LinearLayoutManagerFindReferenceChildTest
Change-Id: I8c5f16163f5092acbea91992496d6343d2bc9fd1
M recyclerview/recyclerview/src/androidTest/java/androidx/recyclerview/widget/BaseLinearLayoutManagerTest.java
A recyclerview/recyclerview/src/androidTest/java/androidx/recyclerview/widget/LinearLayoutManagerFindReferenceChildTest.kt
M recyclerview/recyclerview/src/main/java/androidx/recyclerview/widget/LinearLayoutManager.java
je...@google.com <je...@google.com> #9
We are working on a fix in RecyclerView and in ViewPager2. In the mean time, you can try the following workaround:
Override onConfigurationChanged
in your Activity, and record the currentItem of ViewPager2, and add a OnLayoutChangeListener to ViewPager2 that consumes this variable by making sure RecyclerView is scrolled to the right location. Here is an outline of a workaround:
viewPager.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
val horizontal = viewPager.orientation == ViewPager2.ORIENTATION_HORIZONTAL
val rtl = ViewCompat.getLayoutDirection(viewPager) == ViewCompat.LAYOUT_DIRECTION_RTL
if (currentItemBeforeConfigChange != RecyclerView.NO_POSITION) {
val currentItem = currentItemBeforeConfigChange
currentItemBeforeConfigChange = RecyclerView.NO_POSITION
val rv = viewPager.getChildAt(0) as RecyclerView
val child = rv.getChildAt(0)
val childPosition = rv.getChildLayoutPosition(child)
val pxPerItem = if (horizontal) {
if (rtl) -child.width else child.width
} else {
child.height
}
val expectedChildLocation = pxPerItem * (childPosition - currentItem)
val actualChildLocation = if (horizontal) child.left else child.top
val scrollDistance = actualChildLocation - expectedChildLocation
rv.scrollBy(
if (horizontal) scrollDistance else 0,
if (!horizontal) scrollDistance else 0
)
}
}
Please make sure to tweak this to your application's needs
je...@google.com <je...@google.com> #10
je...@google.com <je...@google.com>
je...@google.com <je...@google.com> #11
Note: while no new version of viewpager2 is released, one can unblock oneself by adding an explicit dependency to the latest alpha version of recyclerview (androidx.recyclerview:recyclerview:1.2.0-alpha03
at the time of writing).
Description
I use ViewPager2 version: 1.0.0-rc01
With configure change ="keyboardHidden|orientation|screenSize"
And setOffscreenPageLimit = 2.
But when rotation screen -> current item auto drag 1/2 to next item -> in screen exists 1/2 current item + 1/2 next item.
I try not setOffscreenPageLimit -> issue not occur.
Please help me check in case setOffscreenPageLimit.
Thanks so much!