-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Remove all usage of Device throughout the repo #4982
Conversation
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.
The Blazor changes look fine to me.
if (Device.RuntimePlatform == Device.iOS) | ||
if (DeviceInfo.Platform == DevicePlatform.iOS) |
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.
Should checks like these use the OperatingSystem
class?
https://docs.microsoft.com/dotnet/api/system.operatingsystem.isios?view=net-6.0
Do we even need DeviceInfo.Platform
?
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.
I agree, OperatingSystem
is the recommended API going forward.
It also makes it easier for the linker to trim out code since e.g. OperatingSystem.IsIOS()
is hardcoded to true
in the BCL on these platforms (though one thing to keep in mind is that IsIOS()
also returns true on Catalyst, so you need to check !IsMacCatalyst()
if you really only mean iOS).
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.
I guess one issue is that DevicePlatform has entries for UWP/Tizen which OperatingSystem
does not, though it should still be worthwhile to switch the other cases.
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.
Is it possible for the BCL API to have a more generic API? Instead of IsXxx and have a string based one? Or even mark some api as a "this method returns true on platform X"? So we can add our own platforms and then inform the linker?
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.
I suppose IsOSPlatform("Tizen")
exists and is linker-friendly? Maybe we can use that? If Samsung implemented it...
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.
yeah OperatingSystem.IsOSPlatform("Tizen")
should work (assuming they implement it), but it won't be linker friendly since the linker can't tell it from the string I think.
Looking around in dotnet/runtime it seems that they instead opted to be regarded as a Linux distribution like Ubuntu, Debian, etc. and just return true for .IsLinux()
.
_webviewManager = new AndroidWebKitWebViewManager( | ||
PlatformView, | ||
Services!, | ||
new MauiDispatcher(Services!.GetRequiredService<IDispatcher>()), |
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.
Instead of using the Device.Invoke we can just capture the dispatcher at the time of adding the view to the UI. This changes for all platforms.
Device.StartTimer(TimeSpan.FromMilliseconds(10), () => | ||
{ | ||
UpdateToolbar(); | ||
return false; | ||
}); | ||
PostDelayed(() => UpdateToolbar(), 10); |
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.
In some cases I just used the native "run on UI thread" stuff as that means we don't need to care about passing a dispatcher or the maui control in.
public static IItemsViewSource Create(IEnumerable itemsSource, ICollectionChangedNotifier notifier) | ||
public static IItemsViewSource Create(IEnumerable itemsSource, BindableObject container, ICollectionChangedNotifier notifier) |
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.
@PureWeen I saw this was done for ObservableItemTemplateCollection for Windows, so I copied that. Mainly just for the dispatcher, but if we pass the view in, then we never have to worry about reaching out into the Application. or Device. worlds.
Not sure if this is going to do terrible things with lifetime and/or memory. If so, we can change and find another way.
var source = ItemsSourceFactory.Create(_groupSource[n] as IEnumerable, this); | ||
var source = ItemsSourceFactory.Create(_groupSource[n] as IEnumerable, _groupableItemsView, this); |
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.
Here is an example of apssing in the groupable view itself into the items source collection thing above.
[Obsolete] | ||
public static void Init(IActivationState activationState, InitializationOptions? options = null) => | ||
Init(activationState.Context, options); |
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.
I marked all of the Init things in the Forms type obsolete so that everyone knows not to use it. It is still used internally for now, but this is basically a non-public thing with all the work for the hosting and registration.
#pragma warning disable CS0612 // Type or member is obsolete | ||
Forms.Init(state, new InitializationOptions { Flags = InitializationFlags.SkipRenderers }); | ||
#pragma warning restore CS0612 // Type or member is obsolete |
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.
In order for us to still use the Forms.Init in the builder, we can just do this. Eventually, all this goes away and it is pretty slim right now anyway.
var ois = ItemsSourceFactory.Create(source, new MockCollectionChangedNotifier()); | ||
var ois = ItemsSourceFactory.Create(source, Application.Current, new MockCollectionChangedNotifier()); |
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.
This is weird, but this is exactly what Device.InvokeOnMainThread did. And in the case of a test, the "container" is the app. So... yeah?
@@ -10,30 +10,41 @@ | |||
namespace Microsoft.Maui.Controls | |||
{ | |||
/// <include file="../../docs/Microsoft.Maui.Controls/Device.xml" path="Type[@FullName='Microsoft.Maui.Controls.Device']/Docs" /> | |||
//[Obsolete] |
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.
Can't go 100% removed because of Device.GetNamedSize
and potentially Device.Styles
[Obsolete] | ||
public static void RegisterAll(Type[] attrTypes, IFontRegistrar fontRegistrar = null) |
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.
Made the RegisterAll methods obsolete as these are probably not the droids users are looking for.
if (Device.RuntimePlatform == Device.GTK && GTK != s_notset) | ||
if (DeviceInfo.Platform == DevicePlatform.Create("GTK") && GTK != s_notset) |
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.
This is probably not worth the code and will be removed in #4491 but it is here for now and does not break anything.
* Implement IBorder on Windows (#5008) * Implement IBorder on Windows * Fix rectangles Co-authored-by: redth <jondick@gmail.com> * Remove all usage of Device throughout the repo (#4982) Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com> Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
* Implement IBorder on Windows (#5008) * Implement IBorder on Windows * Fix rectangles Co-authored-by: redth <jondick@gmail.com> * Remove all usage of Device throughout the repo (#4982) * Remove unsupported targets in Device class (#4491) * Remove unsupported targets in Device class * Fixed broken tests * Deprecate UWP target * Allow to use UWP target on XAML * Fix build errors * comments * UWP == WinUI * Fix Build errors * Added more tests * fix * vbnm * More fixes * things Co-authored-by: Matthew Leibowitz <mattleibow@live.com> Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com> Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
* Implement IBorder on Windows (#5008) * Implement IBorder on Windows * Fix rectangles Co-authored-by: redth <jondick@gmail.com> * Remove all usage of Device throughout the repo (#4982) * Remove unsupported targets in Device class (#4491) * Remove unsupported targets in Device class * Fixed broken tests * Deprecate UWP target * Allow to use UWP target on XAML * Fix build errors * comments * UWP == WinUI * Fix Build errors * Added more tests * fix * vbnm * More fixes * things Co-authored-by: Matthew Leibowitz <mattleibow@live.com> * [ci] Remove image override (#5053) * [ci] Remove image override * [ci] Don't provisioning windows Co-authored-by: Javier Suárez <javiersuarezruiz@hotmail.com> Co-authored-by: Matthew Leibowitz <mattleibow@live.com> Co-authored-by: Rui Marinho <me@ruimarinho.net>
Description of Change
The
Device
class now no longer holds any new or useful functionality that cannot be found in a better and more coherent place after #1965 .This PR now goes and marks Device as obsolete and then replaces all usages with the new and improved APIs. Device now just exists as an obsolete compatibility API.
Issues Fixed
Fixes #4549