Skip to content

Environment propagation for font, color, and disabled#38

Merged
colemancda merged 3 commits into
masterfrom
feature/style-inheritance
Jul 23, 2026
Merged

Environment propagation for font, color, and disabled#38
colemancda merged 3 commits into
masterfrom
feature/style-inheritance

Conversation

@colemancda

Copy link
Copy Markdown
Member

Style modifiers set on a container now apply to its whole subtree — SwiftUI's environment semantics for .font, .foregroundColor, and .disabled. Previously these only had an effect when attached directly to a Text or Button; on a VStack they were silently ignored.

How it works

Pure interpreter change (the modifiers already emit on any view from earlier tiers). Modeled the same way Compose models its own text environment — CompositionLocals:

  • LocalInheritedFontSize / LocalInheritedFontWeight / LocalInheritedColor / LocalInheritedDisabled
  • Render(node) folds the node's own font/foregroundColor/disabled modifiers into these before rendering its subtree (right alongside the existing animation-spec provider).
  • RenderText starts from the inherited values; its own modifiers override them. Button is disabled when either its own or an inherited .disabled(true) is in scope.

Explicit-wins is automatic: a child's own .font overrides the inherited one.

Verification

  • Desktop Kotlin compiles; emulator (new Styling screen): three Texts inheriting a container .font(.title); two inheriting .foregroundColor(.blue); a child .font(.caption) overriding an inherited title; combined headline+purple; and a .disabled(true) container whose buttons are dimmed and non-interactive (tap count stays 0)

Deferred

Inherited .disabled fully disables Button and visually dims the subtree (container alpha), but does not yet set enabled = false on Toggle/Slider/TextField. .italic/.lineLimit/.multilineTextAlignment remain Text-local (not propagated).

@colemancda
colemancda merged commit f0ca64f into master Jul 23, 2026
6 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.

1 participant