-
Notifications
You must be signed in to change notification settings - Fork 735
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
feat: Platform runtime helper #18758
base: master
Are you sure you want to change the base?
Changes from 7 commits
c0aef67
1c3106f
4da5a6b
0349cc8
231b43f
2cee6c0
9c801db
c30a070
a0cdd81
59dffec
ca9e0c2
2bbd9d4
4e6a320
545651d
7fbe6d4
b5035d9
6475085
4767456
46a9f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
using Uno.UI.Helpers; | ||
|
||
namespace Uno.UI.Toolkit; | ||
|
||
public static class PlatformRuntimeHelper | ||
{ | ||
public static UnoRuntimePlatform Current => | ||
#if !HAS_UNO | ||
Uno.UI.Toolkit.UnoRuntimePlatform.Windows; | ||
#else | ||
(Uno.UI.Toolkit.UnoRuntimePlatform)PlatformRuntimeHelper.Current; | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Uno.UI.Toolkit; | ||
|
||
public enum UnoRuntimePlatform | ||
{ | ||
Android, | ||
iOS, | ||
MacCatalyst, | ||
MacOSX, | ||
WebAssembly, | ||
Windows, | ||
Skia, | ||
SkiaGtk, | ||
SkiaWpf, | ||
SkiaX11, | ||
SkiaFrameBuffer, | ||
SkiaMacOS, | ||
Unknown | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.UI.Helpers; | ||
|
||
public static class PlatformRuntimeHelper | ||
{ | ||
internal static UnoRuntimePlatform SkiaPlatform { get; set; } = UnoRuntimePlatform.Skia; | ||
|
||
public static UnoRuntimePlatform Current => GetPlatform(); | ||
|
||
private static UnoRuntimePlatform GetPlatform() => | ||
#if __ANDROID__ | ||
UnoRuntimePlatform.Android; | ||
#elif __IOS__ | ||
UnoRuntimePlatform.iOS; | ||
#elif __MACCATALYST__ | ||
UnoRuntimePlatform.MacCatalyst; | ||
#elif __MACOS__ | ||
UnoRuntimePlatform.MacOSX; | ||
#elif __WASM__ | ||
UnoRuntimePlatform.WebAssembly; | ||
#elif __SKIA__ | ||
SkiaPlatform; | ||
#else | ||
UnoRuntimePlatform.Unknown; | ||
#endif | ||
|
||
} |
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.UI.Helpers; | ||
|
||
public enum UnoRuntimePlatform | ||
{ | ||
Android, | ||
iOS, | ||
MacCatalyst, | ||
MacOSX, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this entry is not necessary, as it is actually only temporary anyway, as we will be dropping the legacy macOS implementation |
||
WebAssembly, | ||
Windows, | ||
Skia, | ||
SkiaGtk, | ||
SkiaWpf, | ||
SkiaX11, | ||
SkiaFrameBuffer, | ||
SkiaMacOS, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SkiaIslands? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In such case I would go with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When\where\how would There's no code to allow to set it (from the host) since it's returned from a method. An internal Also if You might want to add an extension method, on the enum, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds good, in some cases you want to make some code skia specific (maybe because of native rendering limitations), in other cases it is the "native platform" that matters only; so a combination of |
||
Unknown | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace Uno.UI.Helpers; | ||
|
||
internal static class UnoRuntimePlatformExtensions | ||
{ | ||
public static bool IsSkia(UnoRuntimePlatform platform) | ||
{ | ||
return platform == UnoRuntimePlatform.SkiaFrameBuffer | ||
|| platform == UnoRuntimePlatform.SkiaGtk | ||
|| platform == UnoRuntimePlatform.SkiaMacOS | ||
|| platform == UnoRuntimePlatform.SkiaWpf | ||
|| platform == UnoRuntimePlatform.SkiaX11; | ||
} | ||
|
||
public static bool IsAndroid(this UnoRuntimePlatform platform) | ||
{ | ||
return platform == UnoRuntimePlatform.Android; | ||
} | ||
|
||
public static bool IsiOS(this UnoRuntimePlatform platform) | ||
{ | ||
return platform == UnoRuntimePlatform.iOS; | ||
} | ||
|
||
public static bool IsMacCatalyst(this UnoRuntimePlatform platform) | ||
{ | ||
return platform == UnoRuntimePlatform.MacCatalyst; | ||
} | ||
|
||
public static bool IsMacOS(this UnoRuntimePlatform platform) | ||
{ | ||
return platform == UnoRuntimePlatform.MacOSX; | ||
} | ||
|
||
public static bool IsWebAssembly(this UnoRuntimePlatform platform) | ||
{ | ||
return platform == UnoRuntimePlatform.WebAssembly; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a runtime test that gets the value from
GetPlatform()
at runtime and checks that the result is notUnknown
- this will future proof us against potential new platforms being added and us forgetting to update this code path