Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ThemeDictionaries #283

Merged
merged 49 commits into from
Feb 4, 2023
Merged

Migrate to ThemeDictionaries #283

merged 49 commits into from
Feb 4, 2023

Conversation

amwx
Copy link
Owner

@amwx amwx commented Feb 3, 2023

This is part of preview5, but because this has breaking changes related to FluentAvaloniaTheme and how to use the themes for this library, I'm pulling it out for visibility.

ThemeDictionaries are now here, along with a built in mechanism to resolve some system settings (IPlatformSettings). Starting with preview5, the following changes are being made:

NOTE
HighContrast theme is broken right now and requires a fix upstream.

  • FluentAvaloniaTheme's RequestedTheme property is now obsolete, and you should change the requested theme using the RequestedThemeVariant property on Application (or anywhere else). The property has not been removed yet, but will before the final v2 release. Along the same lines, the RequestedThemeChanged event is obsolete as well. I'm marking obsolete now for migration purposes. Preview5 has A LOT of changes, let's make some things easier.
  • InvalidateThemingFromSystemThemeChanged() is also being marked obsolete. With the new changes, there not really any need for this anymore

HIGH CONTRAST THEME
A ThemeVariant is stored in FluentAvaloniaTheme for the HighContrast theme:

public static readonly ThemeVariant HighContrastTheme = new ThemeVariant(HighContrastModeString, ThemeVariant.Light);

To use:

Application.Current.RequestedThemeVariant = FluentAvaloniaTheme.HighContrastTheme

In xaml, if you're building a resource dictionary for a custom control

xmlns:sty="using:FluentAvalonia.Styling"

<ResourceDictionary x:Key="{x:Static sty:FluentAvaloniaTheme.HighContrastTheme}" />

RESOLVING SYSTEM RESOURCES

PreferSystemTheme and PreferUserAccentColor still work. On startup what will happen now is FATheme will redirect the call to Application.Current.RequestedThemeVariant with Light, Dark, or HighContrast theme.

For the most part, I'm now deferring to IPlatformSettings for the lookup of theme & accent colors. On windows, this will have no effect. On MacOS, theme lookup should now work (if it didn't before) as the Avalonia implementation falls into ObjC territory. On linux, I'm preserving the existing lookup added previous before attempting the lookup with IPlatformSettings which is very limited. IPlatformSettings also means this theme & accent color will work on WASM & mobile now too (at least where it supported).

REFRESHING SYSTEM VALUES
FATheme will subscribe to IPlatformSettings.ColorValuesChanged, so if the Avalonia implementation supports listening for changes in system theme or accent color, FATheme will automatically take care of switching for you. This does require PreferSystemTheme and/or PreferUserAccentColor to be true. If you want to manage this yourself, you should disable those properties.

For more on the Avalonia APIs:
IPlatformSettings & related: AvaloniaUI/Avalonia#9913
ThemeDictionaries/ThemeVariants: AvaloniaUI/Avalonia#8166

@amwx amwx merged commit d936eb5 into master Feb 4, 2023
@amwx amwx mentioned this pull request Feb 6, 2023
4 tasks
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.

2 participants