Repository navigation
Conversation
Emulator evidenceTest layout: the export const theme: AndroidWidgetTheme = {
day: { primary: '#E65100', surface: '#FFF3E0' },
night: { primary: '#FFB74D', surface: '#3E2723' },
dynamicColors: false,
}The widget background uses Every clip runs day → night → day on the home screen. In every clip Build: a debug APK of the example app from this branch @ Devices: Android 7.0 emulator, API 24 (AVD
|
|
If I want to use different colors for day and night, in both light and dark modes, that’s possible. So, we would have four variants: |
A Dynamic Widget can export a theme with day and night colors for any AndroidDynamicColors role, and its role tokens then resolve to those colors. dynamicColors: false lets the theme win over Material You on Android 12+.
Covers the theme export, its precedence over dynamic colors, and how malformed themes are handled.
15f4874 to
a8c97e9
Compare
What is this?
An Android Dynamic Widget can now export a
themenext to its render function. The theme givesdayandnightcolors for anyAndroidDynamicColorsrole, and the widget's role tokens then resolve to those colors.Until now, role tokens always meant Glance's own palette: Material You on Android 12+, and Glance's fixed purple baseline below that. An app had no way to map the roles to its brand colors, so on older devices every widget looked like a stock Material demo.
This is the theme half of #319. Color pairs come in #356.
How does it work?
themeas JSON. The native side reads it each time the bundle is evaluated, so editing or removing the theme takes effect on the next Metro reload.GlanceThemebuilt from the theme. Each role defined on both sides becomes a day/night color, and roles the theme leaves out keep the palette they have today. Native modifiers such asbackground(AndroidDynamicColors.surface)follow the theme too.dynamicColors: falsemakes the theme win everywhere.{ day, night }pairs are always used as written. Payload-driven widgets and the prerendered placeholder don't see the theme.Differences from #319:
dayandnight, matching the pair keys from feat(android): day/night color pairs on Android Dynamic Widgets #356.DynamicThemeColorProvidersdirectly, because that API is restricted.render, so this addsgetThemeJSONon the JS side andnativeThemeJSONon the native side.Why is this useful?
Apps can give their widgets a brand palette that works on every Android version, without replacing role tokens with literal colors. On Android 11 and older, widgets no longer fall back to Glance's purple baseline. With
dynamicColors: false, the brand palette also replaces Material You on newer devices.Refs #319