Skip to content

Commit

Permalink
Remove PlatformVersion and use OperatingSystem APIs directly
Browse files Browse the repository at this point in the history
  • Loading branch information
akoeplinger committed Apr 28, 2022
1 parent 59c06ab commit 2a97e3f
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 123 deletions.
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ indent_size = 2
[*.cs]
indent_style = tab

# TODO: Disable platform compatibility analyzer until all CA1416 violations are fixed
# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1416
dotnet_diagnostic.CA1416.severity = error

# TODO: Remove this to reenable the COMAnalyzer once https://github.com/dotnet/linker/issues/2686 is fixed
Expand Down
4 changes: 3 additions & 1 deletion src/Compatibility/Core/src/Windows/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ internal Platform(Microsoft.UI.Xaml.Window page)

InitializeStatusBar();

if(!PlatformVersion.IsDesktop)
// https://docs.microsoft.com/en-us/windows/winui/api/microsoft.ui.xaml.window.current?view=winui-3.0
// The currently activated window for UWP apps. Null for Desktop apps.
if (Microsoft.UI.Xaml.Window.Current != null)
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

// TODO WINUI: This event is only available on UWP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ void AlignEmptyView()

bool isRtl;

if (PlatformVersion.IsAtLeast(10))
if (OperatingSystem.IsIOSVersionAtLeast(10) || OperatingSystem.IsTvOSVersionAtLeast(10))
isRtl = CollectionView.EffectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.RightToLeft;
else
isRtl = CollectionView.SemanticContentAttribute == UISemanticContentAttribute.ForceRightToLeft;
Expand Down
11 changes: 0 additions & 11 deletions src/Compatibility/Core/src/iOS/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public static class Forms
static bool? s_isiOS13OrNewer;
static bool? s_isiOS14OrNewer;
static bool? s_isiOS15OrNewer;
static bool? s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden;

[SupportedOSPlatformGuard("ios11.0")]
//[SupportedOSPlatformGuard("tvos11.0")] TODO: the block guarded by this property calling API unsupported on TvOS or version not supported
Expand Down Expand Up @@ -118,16 +117,6 @@ internal static void RenderersRegistered()
IsInitializedRenderers = true;
}

[SupportedOSPlatformGuard("ios11.0")] // TODO: it is not explicitly guard iOS version 11.0, but always used before calling something supported from version 11.0
internal static bool RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden
{
get
{
if (!s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden.HasValue)
s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden = new UIViewController().RespondsToSelector(new ObjCRuntime.Selector("setNeedsUpdateOfHomeIndicatorAutoHidden"));
return s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden.Value;
}
}
#else

static bool? s_isMojaveOrNewer;
Expand Down
2 changes: 1 addition & 1 deletion src/Compatibility/Core/src/iOS/PlatformRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override void ViewDidLoad()
{
base.ViewDidLoad();
SetNeedsStatusBarAppearanceUpdate();
if (Forms.RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden)
if (OperatingSystem.IsIOSVersionAtLeast(11))
SetNeedsUpdateOfHomeIndicatorAutoHidden();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public override void ViewDidLoad()
UpdateHideNavigationBarSeparator();
UpdateUseLargeTitles();

if (Forms.RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden)
if (OperatingSystem.IsIOSVersionAtLeast(11))
SetNeedsUpdateOfHomeIndicatorAutoHidden();

// If there is already stuff on the stack we need to push it
Expand Down
4 changes: 2 additions & 2 deletions src/Compatibility/Core/src/iOS/Renderers/PageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public override void ViewDidAppear(bool animated)

_appeared = true;
UpdateStatusBarPrefersHidden();
if (Forms.RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden)
if (OperatingSystem.IsIOSVersionAtLeast(11))
SetNeedsUpdateOfHomeIndicatorAutoHidden();

if (Element.Parent is CarouselPage)
Expand Down Expand Up @@ -504,7 +504,7 @@ IEnumerable<UIView> ViewAndSuperviewsOfView(UIView view)

void UpdateHomeIndicatorAutoHidden()
{
if (Element == null || !Forms.RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden)
if (Element == null || !OperatingSystem.IsIOSVersionAtLeast(11))
return;

SetNeedsUpdateOfHomeIndicatorAutoHidden();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void UpdateFlyoutPageContainers()
_detailController.AddChildViewController(detailRenderer.ViewController);

SetNeedsStatusBarAppearanceUpdate();
if (Forms.RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden)
if (OperatingSystem.IsIOSVersionAtLeast(11))
SetNeedsUpdateOfHomeIndicatorAutoHidden();

if (detailRenderer.ViewController.View.Superview != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class CellRenderer : ElementHandler<Cell, UITableViewCell>, IRegisterable

EventHandler? _onForceUpdateSizeRequested;
PropertyChangedEventHandler? _onPropertyChangedEventHandler;
readonly UIColor _defaultCellBgColor = PlatformVersion.IsAtLeast(13) ? UIColor.Clear : UIColor.White;
readonly UIColor _defaultCellBgColor = (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13)) ? UIColor.Clear : UIColor.White;

public static PropertyMapper<Cell, CellRenderer> Mapper =
new PropertyMapper<Cell, CellRenderer>(ElementHandler.ElementMapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e)
{
Control.Layer.RemoveAllAnimations();
//iOS11 hack
if (PlatformVersion.IsAtLeast(11))
if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11))
this.BeginInvokeOnMainThread(() =>
{
if (Control != null /*&& !_disposed*/)
Expand Down Expand Up @@ -860,7 +860,7 @@ protected override void UpdateEstimatedRowHeight(UITableView tableView)
var estimatedRowHeight = GetEstimatedRowHeight(tableView);
//if we are providing 0 we are disabling EstimatedRowHeight,
//this works fine on newer versions, but iOS10 it will cause a crash so we leave the default value
if (estimatedRowHeight > 0 || (estimatedRowHeight == 0 && PlatformVersion.IsAtLeast(11)))
if (estimatedRowHeight > 0 || (estimatedRowHeight == 0 && (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11))))
tableView.EstimatedRowHeight = estimatedRowHeight;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ internal void UpdateTitleArea(Page page)

// on iOS 10 if the user hasn't set the back button text
// we set it to an empty string so it's consistent with iOS 11
if (!PlatformVersion.IsAtLeast(11) && !isBackButtonTextSet)
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)) && !isBackButtonTextSet)
backButtonText = "";

// First page and we have a flyout detail to contend with
Expand Down Expand Up @@ -1391,7 +1391,7 @@ void UpdateHasBackButton()
if (!_navigation.TryGetTarget(out n))
return;

if (!PlatformVersion.IsAtLeast(11) || n._parentFlyoutPage != null)
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)) || n._parentFlyoutPage != null)
UpdateTitleArea(Child);
}

Expand Down Expand Up @@ -1614,7 +1614,7 @@ protected internal MauiControlsNavigationBar(NativeHandle handle) : base(handle)

public override void LayoutSubviews()
{
if (!PlatformVersion.IsAtLeast(11))
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)))
{
for (int i = 0; i < this.Subviews.Length; i++)
{
Expand Down Expand Up @@ -1654,7 +1654,7 @@ class Container : UIView

public Container(View view, UINavigationBar bar) : base(bar.Bounds)
{
if (PlatformVersion.IsAtLeast(11))
if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11))
{
TranslatesAutoresizingMaskIntoConstraints = false;
}
Expand Down Expand Up @@ -1701,7 +1701,7 @@ public override CGRect Frame
{
if (Superview != null)
{
if (!PlatformVersion.IsAtLeast(11))
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)))
{
value.Y = Superview.Bounds.Y;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public bool Reset()
if (_lastInset == 0 && _tabThickness == 0)
return false;

if (!PlatformVersion.IsAtLeast(11))
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)))
{
UpdateContentInset(_lastInset, _tabThickness);
return true;
Expand Down Expand Up @@ -155,7 +155,7 @@ void UpdateVerticalBounce()
// If we can't bounce in that case you may not be able to expose the handler.
// Also the hiding behavior only depends on scroll on iOS 11. In 10 and below
// the search goes in the TitleView so there is nothing to collapse/expand.
if (!PlatformVersion.IsAtLeast(11) ||
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)) ||
(_renderer.VirtualView is ScrollView scrollView && scrollView.Orientation == ScrollOrientation.Horizontal))
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal CGSize GetReferenceSizeForheaderOrFooter(UICollectionView collectionVie
return CGSize.Empty;
}

if (!PlatformVersion.IsAtLeast(11))
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)))
{
// iOS 10 crashes if we try to dequeue a cell for measurement
// so we'll use an alternate method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ void AlignEmptyView()

bool isRtl;

if (PlatformVersion.IsAtLeast(10))
if (OperatingSystem.IsIOSVersionAtLeast(10) || OperatingSystem.IsTvOSVersionAtLeast(10))
isRtl = CollectionView.EffectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.RightToLeft;
else
isRtl = CollectionView.SemanticContentAttribute == UISemanticContentAttribute.ForceRightToLeft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public override UICollectionViewLayoutInvalidationContext GetInvalidationContext
if (preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Header
&& preferredAttributes.RepresentedElementKind != UICollectionElementKindSectionKey.Footer)
{
if (PlatformVersion.IsAtLeast(12))
if (OperatingSystem.IsIOSVersionAtLeast(12) || OperatingSystem.IsTvOSVersionAtLeast(12))
{
return base.GetInvalidationContext(preferredAttributes, originalAttributes);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controls/src/Core/Platform/iOS/ModalWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal ModalWrapper(IPlatformViewHandler modal)
{
var result = style.ToPlatformModalPresentationStyle();

if (!PlatformVersion.IsAtLeast(13) && result == UIKit.UIModalPresentationStyle.Automatic)
if (!(OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13)) && result == UIKit.UIModalPresentationStyle.Automatic)
{
result = UIKit.UIModalPresentationStyle.FullScreen;
}
Expand All @@ -47,7 +47,7 @@ internal ModalWrapper(IPlatformViewHandler modal)

modal.ViewController.DidMoveToParentViewController(this);

if (PlatformVersion.IsAtLeast(13))
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
PresentationController.Delegate = this;

((Page)modal.VirtualView).PropertyChanged += OnModalPagePropertyChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal void SendPopping(Task popTask)
//// var navController = handler._controlsNavigationController;
//// var NavigationBar = navController.NavigationBar;

//// if (PlatformVersion.IsAtLeast(13))
//// if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
//// {
//// var navigationBarAppearance = NavigationBar.StandardAppearance;

Expand Down Expand Up @@ -146,7 +146,7 @@ internal void SendPopping(Task popTask)

//// // Determine new large title text attributes via global static data
//// var largeTitleTextAttributes = titleTextAttributes;
//// if (PlatformVersion.IsAtLeast(11))
//// if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11))
//// {
//// var globalLargeTitleTextAttributes = UINavigationBar.Appearance.LargeTitleTextAttributes;

Expand All @@ -157,7 +157,7 @@ internal void SendPopping(Task popTask)
//// };
//// }

//// if (PlatformVersion.IsAtLeast(13))
//// if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsTvOSVersionAtLeast(13))
//// {
//// if (NavigationBar.CompactAppearance != null)
//// {
Expand All @@ -178,7 +178,7 @@ internal void SendPopping(Task popTask)
//// {
//// NavigationBar.TitleTextAttributes = titleTextAttributes;

//// if (PlatformVersion.IsAtLeast(11))
//// if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11))
//// NavigationBar.LargeTitleTextAttributes = largeTitleTextAttributes;
//// }

Expand Down
6 changes: 3 additions & 3 deletions src/Core/src/Handlers/WebView/WebViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ internal async Task FirstLoadUrlAsync(string url)
var safeRelativeUri = new Uri($"{uri.PathAndQuery}{uri.Fragment}", UriKind.Relative);
NSUrlRequest request = new NSUrlRequest(new Uri(safeHostUri, safeRelativeUri));

if (HasCookiesToLoad(url) && !PlatformVersion.IsAtLeast(11))
if (HasCookiesToLoad(url) && !(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)))
return;

await SyncPlatformCookiesAsync(url);
Expand Down Expand Up @@ -293,7 +293,7 @@ async Task SyncPlatformCookiesAsync(string url)
// So on iOS10 if the user wants to remove any cookies we just delete
// the cookie for the entire domain inside of DeleteCookies and then rewrite
// all the cookies
if (PlatformVersion.IsAtLeast(11) || deleteCookies.Count == 0)
if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11) || deleteCookies.Count == 0)
{
foreach (var nsCookie in retrieveCurrentWebCookies)
{
Expand Down Expand Up @@ -332,7 +332,7 @@ async Task InitialCookiePreloadIfNecessary(string url)
return;

// Pre ios 11 we sync cookies after navigated
if (!PlatformVersion.IsAtLeast(11))
if (!(OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)))
return;

var cookies = myCookieJar.GetCookies(uri);
Expand Down
21 changes: 0 additions & 21 deletions src/Core/src/Platform/Android/PlatformVersion.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/Core/src/Platform/Windows/PlatformVersion.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Core/src/Platform/iOS/MauiPageControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void UpdateIndicatorCount()

void UpdateSquareShape()
{
if (!PlatformVersion.IsAtLeast(14))
if (!(OperatingSystem.IsIOSVersionAtLeast(14) || OperatingSystem.IsTvOSVersionAtLeast(14)))
{
UpdateCornerRadius();
return;
Expand Down Expand Up @@ -140,7 +140,7 @@ void MauiPageControlValueChanged(object? sender, System.EventArgs e)
_indicatorView.Position = (int)CurrentPage;
//if we are iOS13 or lower and we are using a Square shape
//we need to update the CornerRadius of the new shape.
if (IsSquare && !PlatformVersion.IsAtLeast(14))
if (IsSquare && !(OperatingSystem.IsIOSVersionAtLeast(14) || OperatingSystem.IsTvOSVersionAtLeast(14)))
LayoutSubviews();

}
Expand Down
43 changes: 0 additions & 43 deletions src/Core/src/Platform/iOS/PlatformVersion.cs

This file was deleted.

Loading

0 comments on commit 2a97e3f

Please sign in to comment.