Feature Request P4
Status Update
Comments
ga...@wahoofitness.com <ga...@wahoofitness.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 85c1de7395f07e3256a50706d4f619e654624250
Author: Ian Lake <ilake@google.com>
Date: Fri Apr 19 13:54:21 2019
Ensure Fragment OnBackPressedCallbacks take priority
As FragmentController is not yet driven by a
LifecycleObserver ( b/127528777 ), LifecycleObservers on
Fragments are not necessarily nested within
LifecycleObservers registered at the Activity level.
This can lead to cases where a Fragment is started
before the Activity's Lifecycle is started.
In the case of FragmentManager's usage of Lifecycle to
add OnBackPressedCallbacks, that nesting is critical
to ensure the ordering of callbacks. By creating a
host level Lifecycle that is exactly nested outside
the callbacks to FragmentController, we can ensure
the proper nesting in callbacks.
Test: added test passes
Change-Id: I958d2389c90dcd9d157c6c3d30dffb689ed40c62
M fragment/src/androidTest/AndroidManifest.xml
M fragment/src/androidTest/java/androidx/fragment/app/OnBackPressedCallbackTest.kt
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
https://android-review.googlesource.com/948209
https://goto.google.com/android-sha1/85c1de7395f07e3256a50706d4f619e654624250
Branch: androidx-master-dev
commit 85c1de7395f07e3256a50706d4f619e654624250
Author: Ian Lake <ilake@google.com>
Date: Fri Apr 19 13:54:21 2019
Ensure Fragment OnBackPressedCallbacks take priority
As FragmentController is not yet driven by a
LifecycleObserver (
Fragments are not necessarily nested within
LifecycleObservers registered at the Activity level.
This can lead to cases where a Fragment is started
before the Activity's Lifecycle is started.
In the case of FragmentManager's usage of Lifecycle to
add OnBackPressedCallbacks, that nesting is critical
to ensure the ordering of callbacks. By creating a
host level Lifecycle that is exactly nested outside
the callbacks to FragmentController, we can ensure
the proper nesting in callbacks.
Test: added test passes
Change-Id: I958d2389c90dcd9d157c6c3d30dffb689ed40c62
M fragment/src/androidTest/AndroidManifest.xml
M fragment/src/androidTest/java/androidx/fragment/app/OnBackPressedCallbackTest.kt
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
Description
Component used: Navigation Version used: 2.7.4
This request is related to this feature request
Our application also has this issue. Below is our navigation architecture:
Because each tab is composed, we have to track the 'active' tab as to enable/disable the tab's respective
BackHandler
. However, if I am on tab 2 which is an Ionic Portal (web micro-front-end), when using theBackHandler
to handle navigation events, theNavHost
on tab 5 receives the events if thecurrentBackStack.size > 1
. We cannot move theBackHandler
to be after theNavHost
as it will make theBackHandler
's within each destination route not consumable.In addition to this, if we move Tab 5 to a higher order position in the
HorizontalPager
(say position 1 or 2), this issue does not occur. It's only happening when it's the 'last' tab in the pager. We cannot re-order our tab positions as this is a requirement from our Product Manager.Furthermore, it would be helpful if the
BackHandler/PredictiveBackHandler
would check theNavController
'senableOnBackPressedCallback
. Seems like the simplest approach.