Skip to content

Set the view tree OnBackPressedDispatcherOwner in CoreAppCompatActivity - #666

Merged
gpolak merged 1 commit into
uber:mainfrom
gpolak:view_tree_back_dispatcher_owner
Oct 22, 2026
Merged

gpolak merged 1 commit into
uber:mainfrom
gpolak:view_tree_back_dispatcher_owner

Conversation

@gpolak

@gpolak gpolak commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

RibActivity attaches its root view to android.R.id.content without calling setContentView, so ComponentActivity.initializeViewTreeOwners() never runs. initViewTreeOwners() fills in the lifecycle, ViewModel store and saved-state owners, but not the OnBackPressedDispatcherOwner. findViewTreeOnBackPressed- DispatcherOwner() therefore returns null for every view in a RIB activity.

View-based components that register back callbacks through the view tree (for example a bottom sheet that dismisses on back) silently skip registration. Under predictive back the key-event fallback never fires, so back reaches RibActivity's callback and the router navigates away instead of the component handling it.

Add an explicit androidx.activity dependency to rib-android-core. That pulls in a newer lifecycle, where the ViewTreeLifecycleOwner and ViewTreeViewModelStoreOwner classes are no longer callable from Kotlin, so switch to the equivalent extension functions; the compiled calls are the same.

RibActivity attaches its root view to android.R.id.content without calling
setContentView, so ComponentActivity.initializeViewTreeOwners() never runs.
initViewTreeOwners() fills in the lifecycle, ViewModel store and saved-state
owners, but not the OnBackPressedDispatcherOwner. findViewTreeOnBackPressed-
DispatcherOwner() therefore returns null for every view in a RIB activity.

View-based components that register back callbacks through the view tree
(for example a bottom sheet that dismisses on back) silently skip
registration. Under predictive back the key-event fallback never fires, so
back reaches RibActivity's callback and the router navigates away instead
of the component handling it.

Add an explicit androidx.activity dependency to rib-android-core. That
pulls in a newer lifecycle, where the ViewTreeLifecycleOwner and
ViewTreeViewModelStoreOwner classes are no longer callable from Kotlin, so
switch to the equivalent extension functions; the compiled calls are the
same.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
window.decorView.setViewTreeLifecycleOwner(this)
window.decorView.setViewTreeViewModelStoreOwner(this)
window.decorView.setViewTreeSavedStateRegistryOwner(this)
window.decorView.setViewTreeOnBackPressedDispatcherOwner(this)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the change - also register OnBackPressDispatcherOwner

@gpolak
gpolak merged commit d1da827 into uber:main Oct 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants