← 输入框|github.com|刷新
Skip to content

fix(core): appearance APIs before app start, replaceable Android handlers, explicit systemAppearanceChanged() - #11537

Merged
triniwiz merged 4 commits into
mainfrom
fix/appearance-apis
Oct 24, 2026
Merged

triniwiz merged 4 commits into
mainfrom
fix/appearance-apis

Conversation

@triniwiz

@triniwiz triniwiz commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

  • On Android, Application.systemAppearance(), orientation() and layoutDirection() throw until Application.run() has initialized the module, because they read the configuration from Application.android.context. A theme module imported by the app's entry cannot read the appearance.
  • Utils.android.setDarkModeHandler() keeps the first handler it is given and ignores later ones. setStatusBarColor() and setNavigationBarColor() never change a color: they assign with ??= onto settings that always start with default colors. All three store the settings under the current activity rather than the one passed in, so refreshEdgeToEdge() on that activity loses them.
  • Application.systemAppearanceChanged(rootView, appearance) does nothing while setAutoSystemAppearanceChanged(false) is in effect, so an app that turned automatic changes off to choose its own appearance has to turn them back on around each call.

What is the new behavior?

  • The Android trait getters read the configuration from the native application when the context is not set yet. The app's code runs from the native application's onCreate, so it exists by then.
  • The setters replace the handler and the colors they are given, keep the colors they are not given, and store the settings under the activity passed in.
  • autoSystemAppearanceChanged gates only the automatic path, where the system's appearance changes. The event still fires there. An explicit systemAppearanceChanged() call applies the classes.

Tests: application/system-appearance.spec.ts (4) and utils/edge-to-edge.android.spec.ts (3).

Verified with all of these core PRs merged together (#11527–#11537): apps/automated passes on the iOS 26.4 simulator (1830 OK, 0 failed) and on an Android API 36 emulator (1692 OK; the one failure is the network-dependent IMAGE-CACHE.test_ImageCache_ValidUrl timeout, which also passes on reruns).

Application.systemAppearance(), orientation() and layoutDirection() threw
on Android until Application.run() had initialized the module, because
they read the configuration from Application.android.context, which is
only set then. Code that reads the appearance while it loads, such as a
theme module imported by the app's entry, could not use them.

They now read the configuration from the native application when the
context is not set yet. The app's code runs from the native application's
onCreate, so it exists by then.
…lues

Utils.android.setDarkModeHandler() kept the first handler it was given
and ignored later ones, and setStatusBarColor() and
setNavigationBarColor() never changed a color at all: they assigned with
`??=` onto settings that always start with default colors. All three also
stored the settings under the current activity rather than the one passed
in, so refreshEdgeToEdge() on that activity lost them.

The setters now replace the handler and the colors they are given, keep
the colors they are not, and store the settings under the activity they
were given.
@nx-cloud

nx-cloud Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 4316bbf

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 39s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-15 20:42:35 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11537
npm i https://pkg.pr.new/@nativescript/vite@11537
npm i https://pkg.pr.new/@nativescript/webpack@11537

commit: 4316bbf

…e off

Application.systemAppearanceChanged(rootView, appearance) did nothing
while setAutoSystemAppearanceChanged(false) was in effect, so an app that
turned off automatic changes to choose its own appearance had to turn
them back on around each call.

The flag now gates only the automatic path, where the system's appearance
changes; the event still fires there. An explicit call to
systemAppearanceChanged() applies the classes.
@triniwiz
triniwiz force-pushed the fix/appearance-apis branch from ea689c9 to 447ce6c Compare October 15, 2026 13:27
@triniwiz
triniwiz merged commit 26f5032 into main Oct 24, 2026
9 of 10 checks passed
@triniwiz
triniwiz deleted the fix/appearance-apis branch October 24, 2026 01:05
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