Skip to content

Inherit the environment locale in presentations - #502

Open
vincentborko wants to merge 1 commit into
skiptools:mainfrom
vincentborko:pr/sheet-locale
Open

Inherit the environment locale in presentations#502
vincentborko wants to merge 1 commit into
skiptools:mainfrom
vincentborko:pr/sheet-locale

Conversation

@vincentborko

Copy link
Copy Markdown
Contributor

Fixes #501.

.environment(\.locale, …) set on an ancestor did not reach the content of a .sheet or .fullScreenCover: the presented content resolved Text catalog keys, and reported @Environment(\.locale), in the device locale.

locale is the only environment value not held in one of our own composition locals — it reads and writes Compose's LocalConfiguration. Presented content composes in a separate Android window, and ProvideAndroidCompositionLocals re-provides LocalConfiguration there from the platform, discarding the ancestor's override. Everything stored in our own composition locals — including custom EnvironmentKeys, layoutDirection, and timeZone — crosses the boundary correctly; #501 has the measurements.

The setter now records the override in our own composition local as well, and the getter prefers it over LocalConfiguration. LocalConfiguration is still written, so Android resource resolution keeps following the locale within the same window.

Design note

The alternative is to re-provide the presenter's LocalConfiguration inside each presentation window, which would additionally fix Compose-native resource lookups (stringResource, Material date pickers) inside sheets. I did not take it: it has to be repeated at every window-creating call site — sheets, covers, alerts, confirmation dialogs, menus, popups — and overriding the whole Configuration risks clobbering the dialog window's own metrics, which SheetPresentation reads for detent insets. Happy to switch if you would rather close that gap in one place.

Testing

testSheetInheritsLocaleFromPresenter asserts that a Text catalog key inside a .sheet resolves against the presenter's locale. Verified it fails without the source change (Failed to assert the following: (Text + EditableText = [Terminé])) and passes with it.

swift test passes: 94 tests, 0 failures, native and transpiled.

Also verified on an Android emulator with a Skip Lite app whose device language is en-US and which sets .environment(\.locale, Locale(identifier: "fr")) once at the root. .sheet and .fullScreenCover content reported en_US and rendered the base-language string before the change; both report fr and render the French string after it.

Skip Fuse UI needs no companion change: \.locale is bridged through EnvironmentValues.builtinBridged/setBuiltinBridged, which read and write this same property.

Skip Pull Request Checklist:

  • REQUIRED: I have signed the Contributor Agreement
  • REQUIRED: I have tested my change locally with swift test
  • OPTIONAL: I have tested my change on an iOS simulator or device
  • OPTIONAL: I have tested my change on an Android emulator or device
  • REQUIRED: I have checked whether this change requires a corresponding update in the Skip Fuse UI repository (link related PR if applicable)
  • OPTIONAL: I have added an example of any UI changes to the Showcase sample app

  • AI was used to generate or assist with generating this PR. Claude Code was used to isolate the cause and write the change and the test. Verification was done by measurement rather than review: the environment values were probed side by side across inline, pushed, sheet and cover contexts on a running emulator to establish that only locale was lost; ProvideAndroidCompositionLocals was confirmed to provide LocalConfiguration by disassembling ui-android; and the new test was confirmed to fail without the source change before the PR was opened.

@cla-bot cla-bot Bot added the cla-signed label Jul 31, 2026
vincentborko added a commit to vincentborko/skip-ui that referenced this pull request Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Environment locale does not propagate into .sheet / .fullScreenCover content

1 participant