-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Platform-specific APIs. #11384
Comments
Yes
This is a really good idea. It's perfectly clear this is platform specific and also doesn't exist on the shared type. The syntax is really nice too!
I've often thought Avalonia should have an Avalonia.Platforms parent directory. Then all platform implementations go in there. Avalonia.Android, Avalonia.X11, etc. That would really clean up the main src directory IMO. Then these types of attached properties should probably go inside a PlatformIntegration directory or something within the specific platform. Then you can have files for Window.cs, etc and inside there put whatever platform specific code. Alternatively, the idea started with Xamarin is to have Window.cs and Window.macOS.cs, etc. Platform specific code is in a partial class file next to the shared code. The file suffix states the platform. Not a huge fan of this for Avalonia though as it's extremely rare to need platform specific code so far. It makes more sense to be with the platform implementations. |
Note that an app using some platform features in XAML should not be forced to reference a platform backend when running on a different platform. Especially since one can't reference wasm, mobile and desktop at the same time. |
@kekekeks That's true. But I think the code should still exist with other platform-specific code. You can move it to a shared Avalonia.Platforms.Integration namespace or something. That would complicate the build though if you left it in with other platform-specific code but is still doable. |
The support code can live where it wants to live, but the API should still be accessible when targeting |
I think you could implement in |
And it will nice to support platform suffix .cs compilation. |
@workgroupengineering it won't work if XAML project uses generic .netstandard of .net6.0 target (not a platform specific one). It's not a problem in MAUI, where you have a new target for each platform. And every third party library can target all platforms at once to get this XAML compilation-time trimming. That's why we want a different way in our implementation of OnPlatform extension. Where we rely on postproccessing linker trimming depending on runtime identifier of the actual application (i.e., libraries contain all the branches of OnPlatform as they are platform agnostic). |
Unrelated to this issue. And you already have it in the SDK - ExcludeFromCurrentConfiguration. It can be done with simple msbuild condition. Note, "linux" and "browser" branches will not work...because there are no targets for these platforms. Yet? For XAML support you would need to exclude AvaloniaXaml entries as well, I suppose. While it would be nice to have built in, we just can't because how .NET SDK works and what target frameworks we have on our hands. |
We now have MacOSProperties, Win32Properties and soon will get X11Properties. |
There are various APIs which are specific to a platform (i.e. have no corresponding APIs on other platforms) but would still be useful to be accessed from Avalonia.
One example of this which recently came up is
NSWindowLevel
on macOS: other platforms don't have an equivalent so it doesn't make sense as a general API, but still it's really useful in certain situations to be able to set this for a window.One way of providing these APIs might be as attached properties, for example one could set:
Such a property would only have effect when running on macOS.
The main question with regards to such APIs, is in which assembly should they live?
So, a few questions to start the ball rolling:
The text was updated successfully, but these errors were encountered: