Browse Source

Add iOS tint/accent color support

pull/9913/head
Max Katz 4 years ago
parent
commit
124c87b2cf
  1. 8
      src/iOS/Avalonia.iOS/AvaloniaView.cs
  2. 32
      src/iOS/Avalonia.iOS/PlatformSettings.cs

8
src/iOS/Avalonia.iOS/AvaloniaView.cs

@ -60,6 +60,14 @@ namespace Avalonia.iOS
settings?.TraitCollectionDidChange();
}
public override void TintColorDidChange()
{
base.TintColorDidChange();
var settings = AvaloniaLocator.Current.GetRequiredService<IPlatformSettings>() as PlatformSettings;
settings?.TraitCollectionDidChange();
}
internal class TopLevelImpl : ITopLevelImplWithTextInputMethod, ITopLevelImplWithNativeControlHost,
ITopLevelImplWithStorageProvider
{

32
src/iOS/Avalonia.iOS/PlatformSettings.cs

@ -22,12 +22,34 @@ internal class PlatformSettings : DefaultPlatformSettings
var contrastPreference = UITraitCollection.CurrentTraitCollection.AccessibilityContrast == UIAccessibilityContrast.High ?
ColorContrastPreference.High :
ColorContrastPreference.NoPreference;
return _lastColorValues = new PlatformColorValues
UIColor? tintColor = null;
if (OperatingSystem.IsIOSVersionAtLeast(14))
{
tintColor = UIConfigurationColorTransformer.PreferredTint(UIColor.Clear);
}
if (tintColor is not null)
{
ThemeVariant = themeVariant,
ContrastPreference = contrastPreference
};
tintColor.GetRGBA(out var red, out var green, out var blue, out var alpha);
return _lastColorValues = new PlatformColorValues
{
ThemeVariant = themeVariant,
ContrastPreference = contrastPreference,
AccentColor1 = new Color(
(byte)(alpha * 255),
(byte)(red * 255),
(byte)(green * 255),
(byte)(blue * 255))
};
}
else
{
return _lastColorValues = new PlatformColorValues
{
ThemeVariant = themeVariant, ContrastPreference = contrastPreference
};
}
}
public void TraitCollectionDidChange()

Loading…
Cancel
Save