Add overridable attachContent() to allow non-RIB roots in RibActivity#662
Merged
Merged
Conversation
Extracts the root-attach block from onCreate into a new `protected open attachContent(rootViewGroup, savedInstanceState)` method with the current behavior as its default. Subclasses can override it to host an alternative root (e.g. a Compose host) while still receiving RibActivity's lifecycle publishing and saved-state wrapping. Also drops the elvis-throw in onSaveInstanceState so a null router - now a valid state when attachContent is overridden to skip attach - no longer crashes the delegation. onDestroy and onBackPressed were already null-safe. Adds RibActivityTest cases exercising an override that skips attach: router stays null (interactor access throws), lifecycle CREATE still fires, onBackPressed falls through to super, and onSaveInstanceState no longer crashes.
|
|
sanchezz93
approved these changes
Jul 14, 2026
jbarr21
approved these changes
Jul 14, 2026
jbarr21
requested review from
jbarr21
and removed request for
Copilot and
jbarr21
July 14, 2026 19:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Currently there isn't a way to test RIB vs non-RIB architecture without creating two different activities to bypass RIB creation code in RibActivity. Two activities introduce additional latency on startup path. This PR decouples the RIB creation block from onCreate() so it can be no-oped in one of the branches for a test.
Change
onCreateinto a newprotected open fun attachContent(rootViewGroup, savedInstanceState). The default implementation reproduces the current inline logic, so behavior for existing subclasses is unchanged.?: throw NullPointerException("Router should not be null")inonSaveInstanceState. Becauserouteris already declared nullable, the elvis-safe delegation is semantically identical whenrouter != null(the common case); the null case now no-ops cleanly instead of NPE-ing when a subclass overridesattachContentto skip attach.onDestroyandonBackPressedwere already null-safe; no change.Backward compatibility
attachContentis a newprotected openmethod with a default that reproduces the current inline logic.attachContent.onSaveInstanceState: identical behavior whenrouter != null; the previously-guaranteed-then-thrown null path becomes a no-op.Tests
Added
RibActivityTestcases exercising a subclass that overridesattachContentto skip attach:onCreate_whenAttachContentOverriddenToSkip_shouldLeaveRouterNull—attachContentruns,createRouteris not invoked, andinteractoraccess throwsIllegalStateException.onCreate_whenAttachContentOverriddenToSkip_shouldStillPublishLifecycle—lifecycle()still emitsCREATE.onBackPressed_whenRouterIsNull_shouldFallThroughToSuper—onUnhandledBackPressed()runs and the activity finishes.onSaveInstanceState_whenRouterIsNull_shouldNotCrash— no NPE.Full
:libraries:rib-android:testsuite passes locally (17/17 inRibActivityTest).