-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for UISettings.GetColorValue
- Loading branch information
1 parent
8e467c4
commit bdc1420
Showing
14 changed files
with
149 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Uno.Helpers.Theming | ||
{ | ||
internal static partial class SystemThemeHelper | ||
{ | ||
private static SystemTheme GetSystemTheme() | ||
{ | ||
if ((int)Build.VERSION.SdkInt >= 28) | ||
{ | ||
var uiModeFlags = Android.App.Application.Context.Resources.Configuration.UiMode & UiMode.NightMask; | ||
if (uiModeFlags == UiMode.NightYes) | ||
{ | ||
return ApplicationTheme.Dark; | ||
} | ||
} | ||
return ApplicationTheme.Light; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.Helpers.Theming | ||
{ | ||
internal static partial class SystemThemeHelper | ||
{ | ||
private ApplicationTheme GetDefaultSystemTheme() | ||
{ | ||
//Ensure the current device is running 12.0 or higher, because `TraitCollection.UserInterfaceStyle` was introduced in iOS 12.0 | ||
if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0)) | ||
{ | ||
if (UIScreen.MainScreen.TraitCollection.UserInterfaceStyle == UIUserInterfaceStyle.Dark) | ||
{ | ||
return ApplicationTheme.Dark; | ||
} | ||
} | ||
return ApplicationTheme.Light; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.Helpers.Theming | ||
{ | ||
internal static partial class SystemThemeHelper | ||
{ | ||
/// <summary> | ||
/// Based on <see cref="https://forums.developer.apple.com/thread/118974" /> | ||
/// </summary> | ||
/// <returns>System theme</returns> | ||
private ApplicationTheme GetDefaultSystemTheme() | ||
{ | ||
var version = DeviceHelper.OperatingSystemVersion; | ||
if (version >= new Version(10, 14)) | ||
{ | ||
var app = NSAppearance.CurrentAppearance?.FindBestMatch(new string[] | ||
{ | ||
NSAppearance.NameAqua, | ||
NSAppearance.NameDarkAqua | ||
}); | ||
|
||
if (app == NSAppearance.NameDarkAqua) | ||
{ | ||
return ApplicationTheme.Dark; | ||
} | ||
} | ||
return ApplicationTheme.Light; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.Helpers.Theming | ||
{ | ||
internal static partial class SystemThemeHelper | ||
{ | ||
|
||
} | ||
|
||
internal interface ISystemThemeHelperExtension | ||
{ | ||
SystemTheme GetDefaultSystemTheme(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using Uno.Extensions; | ||
using Uno.Foundation; | ||
using Uno.Logging; | ||
|
||
namespace Uno.Helpers.Theming | ||
{ | ||
internal static partial class SystemThemeHelper | ||
{ | ||
private static SystemTheme GetSystemTheme() | ||
{ | ||
var serializedTheme = WebAssemblyRuntime.InvokeJS("Windows.UI.Xaml.Application.getDefaultSystemTheme()"); | ||
|
||
if (serializedTheme != null) | ||
{ | ||
if (Enum.TryParse(serializedTheme, out SystemTheme theme)) | ||
{ | ||
if (typeof(SystemThemeHelper).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) | ||
{ | ||
typeof(SystemThemeHelper).Log().Info("Setting OS preferred theme: " + theme); | ||
} | ||
return theme; | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException($"{serializedTheme} theme is not a supported OS theme"); | ||
} | ||
} | ||
//OS has no preference or API not implemented, use light as default | ||
if (typeof(SystemThemeHelper).Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information)) | ||
{ | ||
typeof(SystemThemeHelper).Log().Info("No preferred theme, using Light instead"); | ||
} | ||
return SystemTheme.Light; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters