Fixed
Status Update
Comments
jg...@google.com <jg...@google.com> #2
Over to Ralston to take a look. I imagine with the new relocation logic it should be fixed?
jg...@google.com <jg...@google.com> #3
What is happening here is that the TextField does not know that it is in a scrollable container, and since the keyboard is going to hide the currently focused text, the text field calls View.requestRectangleOnScreen which causes the entire app to pan up, and that clips the top bar.
The Relocation APIs are experimental right now. It is not used in TextField as we are past the alpha stage and can only use stable APIs in TextField. So this bug can only be fixed post 1.0
sa...@gmail.com <sa...@gmail.com> #4
This should be fixed by
I verified that this sample code now works when soft input mode is AdjustResize.
jg...@google.com <jg...@google.com> #5
Re #4 it's difficult to say without seeing your code, but you'd have to pass that information there, e.g. by exposing a field that Fragments have access to, or passing a callback to Fragments so they can query some object that keeps track of what's visible (e.g. something that relies on OnPageChangeCallback and keeps state).
jg...@google.com <jg...@google.com> #6
This was raised on GitHub as well: https://github.com/googlesamples/android-viewpager2/issues/3#issue-434618886
Copying the content here as closing GitHub issue tracker (want to have one place to track things).
AndyGu commented 5 hours ago
The scenes I met is that when I store fragments in viewpager2, then I switch them using ”setCurrentItem(position, false)“, there is no certain method called in Fragment's lifecycle, sometimes it calls onAttach() onCreate() and so on, sometimes no method is called(it is related to the memory management I guess). I know I can call registerOnPageChangeCallback of viewpager2, but what I faced is I may fail when I do something to the fragment that I setCurrentItem to, because the fragment will init again when the lifecycle methods called after the callback of onPageSelected.
So am I do the code wrong way or is there some certain method can be called in fragment when switching the fragments, or I can call some method to manage the memory of viewpager2?
Copying the content here as closing GitHub issue tracker (want to have one place to track things).
AndyGu commented 5 hours ago
The scenes I met is that when I store fragments in viewpager2, then I switch them using ”setCurrentItem(position, false)“, there is no certain method called in Fragment's lifecycle, sometimes it calls onAttach() onCreate() and so on, sometimes no method is called(it is related to the memory management I guess). I know I can call registerOnPageChangeCallback of viewpager2, but what I faced is I may fail when I do something to the fragment that I setCurrentItem to, because the fragment will init again when the lifecycle methods called after the callback of onPageSelected.
So am I do the code wrong way or is there some certain method can be called in fragment when switching the fragments, or I can call some method to manage the memory of viewpager2?
jg...@google.com <jg...@google.com> #8
It's definitely on our radar - we'll be looking into it soon.
Description
Instead, I propose using existing fragment lifecycle methods. Off-screen fragments would be paused while the current page's fragment would be resumed. This would allow you to implement logic in the same way for fragments in a ViewPager as anywhere else in the application.