Status Update
Comments
jg...@google.com <jg...@google.com> #2
Branch: androidx-main
commit c2365dcfeb9064814282304f30f3eb86be71fdc7
Author: Dan Nizri <dniz@google.com>
Date: Wed Dec 20 16:33:08 2023
Fix Popup back handling on Android T/13+ when android:enableOnBackInvokedCallback="true"
Bug: 313702338
Bug: 318537200
Test: tested with android:enableOnBackInvokedCallback="true"
Change-Id: I7c7cef686ed9fbfd2d144c90040b13528f1675ed
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/window/AndroidPopup.android.kt
sa...@gmail.com <sa...@gmail.com> #3
Is there remaining work for this feature request. Support for predictive back in Dialogs would allow Material3 to remove some Dialog forks and would be very helpful!
sa...@gmail.com <sa...@gmail.com> #4
Yeah, we probably want to investigate new API shapes here to take advantage of predictive back. No work ongoing yet though, needs prioritization
jg...@google.com <jg...@google.com> #5
jg...@google.com <jg...@google.com> #6
(recapping my chat with Ian)
The tricky part is that the onDismissRequest
is really the final signal and a chance for the app to just say 'nope, I don't want the dialog to dismiss' (since they own the state of 'should the dialog be shown or not' simply by either adding the Dialog to composition or leaving out of composition) - that's the just-in-time problem that the comment talks about. It would be very odd to have any kind of progress animation that doesn't actually lead to the dialog being dismissed when it is committed"
so really it needs to be a more holistic look at how to do dialogs and swap from a binary state (shown/not shown) to something that actually has something in between for cases like predictive back
sa...@gmail.com <sa...@gmail.com> #7
Did and in the sample.
And here I want to introduce new bug.
Steps:
1) Run app and see "Page 2"
2) Press button to open second screen
3) Press back button
4) See "Page 1" instead of "Page2|
In this case I have dinamic pages ( images preview for example ).
And I want to start from concrete page.
In this example it is "Page 2".
So here when you will come back first screen and call viewPager.setCurrentItem(1, false) viewPager.mCurrentItem is already == 1
and on statment
if (item == mCurrentItem && mScrollEventAdapter.isIdle())
it will return from method and don't change page
Also you can call viewPager.setCurrentItem(1, TRUE) and get exception:
java.lang.IllegalArgumentException: No view found for id 0x3 (unknown) for fragment PageFragment{fa928b5 (ca5083d2-7993-4315-a650-8c4f1a0a0225) id=0x3}
So I updated sample project.
sa...@gmail.com <sa...@gmail.com> #8
Steps:
1) Run app
2) Block phone screen
3) Unlock
4) See white screen
jg...@google.com <jg...@google.com> #9
Failing that, could you file separate bugs for other issues? This one is for Navigation.
[1]
[2]
sa...@gmail.com <sa...@gmail.com> #10
Tried grab FragmentStateAdaper from your link.
Comment 8 fixed.
Comment 7 still actual.
Description
I tried to use new ViewPager2 with FragmentStateAdapter. I found bug and created sample project to show it.
First screen is fragment with ViewPager with 2 fragment pages and button to open second screen.
Second screen is just empty fragment.
Steps:
1) Run app
2) Press button to open second screen
3) Press back button
4) Crash: java.lang.IllegalStateException: Observer androidx.viewpager2.adapter.FragmentStateAdapter$1@f8b5102 is already registered.
I did a little search and that's what I found:
This happens because the adapter did not called unregisterAdapterDataObserver(mDataObserver) which call only when recyclerView call FragmentStateAdapter.onDetachedFromRecyclerView.
This call happens only if we change adapter for new or set null for recyclerView ( for viewPager in this case ).
To fix it I tried set null adapter for viewPager in onDestroyView.
Then another exception occurs: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
RecyclerView calls FragmentStateAdapter.onViewRecycled and FragmentStateAdapter tries to removeFragment but fails, because "Can not perform this action after onSaveInstanceState".
Is it bug or I missed something?
This behavior is not listed in the API changes.
Also if you try to change ViewPager2 to old ViewPager this sample will work fine.
Here is sample project to reproduce bug:
Thanks in advance for the answer and help.