Skip to content

Isolate saved state for Android views hosted in Compose - #1560

Merged
steve-the-edwards merged 1 commit into
mainfrom
sedwards/CLF-61/compose-android-view-saved-state
Aug 24, 2026
Merged

Isolate saved state for Android views hosted in Compose#1560
steve-the-edwards merged 1 commit into
mainfrom
sedwards/CLF-61/compose-android-view-saved-state

Conversation

@steve-the-edwards

@steve-the-edwards steve-the-edwards commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Why

ScreenViewFactory.asComposableFactory() bridges a Workflow Android View into Compose. Unlike view-based Workflow containers, the bridge currently gives every hosted View the same parent SavedStateRegistryOwner.

Saved-state provider keys must be unique within one registry. Compose may keep outgoing and incoming incompatible AndroidViews attached simultaneously during replacement, and separate Compose call sites may host sibling Views with the same nested provider keys. Sharing the parent owner therefore allows otherwise independent View trees to collide and crash.

What changed

  • Give each Android View-backed rendering its own saved-state namespace under the parent registry, keyed by rendering compatibility and Compose call site.
  • Install the child owner synchronously before AndroidView attaches and unregister it when the composition is abandoned or forgotten.
  • Preserve the parent registry owner for pure Compose renderings.

Adoption

This is the source-of-truth replacement for consumer-local wrappers that create child SavedStateRegistryOwners around Android View-backed Workflow renderings in Compose. After adopting a release with this fix, consumers should delete those wrappers and retain their product-level regression tests as downstream verification.

Testing

Android instrumentation tests prove that incompatible overlapping Views and sibling Views receive distinct owners, pure Compose retains its parent owner, and Android View state survives Activity recreation.

@steve-the-edwards steve-the-edwards changed the title CLF-61: Isolate saved state for Android views hosted in Compose Isolate saved state for Android views hosted in Compose Aug 18, 2026
@steve-the-edwards
steve-the-edwards marked this pull request as ready for review August 18, 2026 18:56
@steve-the-edwards
steve-the-edwards requested review from a team as code owners August 18, 2026 18:56
Amp-Thread-ID: https://ampcode.com/threads/T-019fd390-8848-7140-9346-1fa5aa52c4a6
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Codex <noreply@openai.com>
Ai-assisted: true
@steve-the-edwards
steve-the-edwards force-pushed the sedwards/CLF-61/compose-android-view-saved-state branch from 539aed3 to 72012c2 Compare August 24, 2026 15:21
@steve-the-edwards
steve-the-edwards merged commit d918586 into main Aug 24, 2026
74 checks passed
@steve-the-edwards
steve-the-edwards deleted the sedwards/CLF-61/compose-android-view-saved-state branch August 24, 2026 20:40
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