Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/XCT.Sample.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected override void OnCreate(Bundle savedInstanceState)
ToolbarResource = Resource.Layout.Toolbar;

base.OnCreate(savedInstanceState);

Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using AndroidX.Core.View.Accessibility;
using Xamarin.CommunityToolkit.Effects;
using Xamarin.CommunityToolkit.Effects.Semantic;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.Forms;
using Effects = Xamarin.CommunityToolkit.Android.Effects;

Expand Down Expand Up @@ -118,7 +119,7 @@ public override void OnInitializeAccessibilityNodeInfo(global::Android.Views.Vie
if (!string.IsNullOrEmpty(hint))
{
// info HintText won't read anything back when using TalkBack pre API 26
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
if (XCT.SdkInt >= (int)BuildVersionCodes.O)
{
info.HintText = hint;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Android.Views;
using Xamarin.CommunityToolkit.Android.Effects;
using Xamarin.CommunityToolkit.Effects;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AButton = Android.Widget.Button;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)

void Update()
{
if (View == null || Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
if (View == null || XCT.SdkInt < (int)BuildVersionCodes.Lollipop)
return;

var radius = (float)ShadowEffect.GetRadius(Element);
Expand Down Expand Up @@ -98,7 +99,7 @@ void Update()
group.SetClipToPadding(false);

#pragma warning disable
if (Build.VERSION.SdkInt < BuildVersionCodes.P)
if (XCT.SdkInt < (int)BuildVersionCodes.P)
return;

View.SetOutlineAmbientShadowColor(androidColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Android.App;
using Android.OS;
using Android.Views;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.Forms.Internals;

namespace Xamarin.CommunityToolkit.Effects
Expand All @@ -10,9 +11,9 @@ static class BarStyle
{
internal static bool IsSupported()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.M)
if (XCT.SdkInt < (int)(int)BuildVersionCodes.M)
{
Log.Warning(string.Empty, $"This functionality is not available. Minimum supported API is {BuildVersionCodes.M}");
Log.Warning(string.Empty, $"This functionality is not available. Minimum supported API is {(int)BuildVersionCodes.M}");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Xamarin.CommunityToolkit.Android.Effects;
using Xamarin.CommunityToolkit.Effects;
using Xamarin.CommunityToolkit.Extensions;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using AView = Android.Views.View;
Expand Down Expand Up @@ -76,7 +77,7 @@ protected override void OnAttached()
accessibilityManager.AddTouchExplorationStateChangeListener(accessibilityListener);
}

if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop || !effect.NativeAnimation)
if (XCT.SdkInt < (int)BuildVersionCodes.Lollipop || !effect.NativeAnimation)
return;

View.Clickable = true;
Expand All @@ -85,7 +86,7 @@ protected override void OnAttached()

if (Group == null)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
if (XCT.SdkInt >= (int)BuildVersionCodes.M)
View.Foreground = ripple;

return;
Expand Down Expand Up @@ -126,7 +127,7 @@ protected override void OnDetached()
View.Touch -= OnTouch;
View.Click -= OnClick;

if (Build.VERSION.SdkInt >= BuildVersionCodes.M && View.Foreground == ripple)
if (XCT.SdkInt >= (int)BuildVersionCodes.M && View.Foreground == ripple)
View.Foreground = null;
}

Expand Down Expand Up @@ -354,7 +355,7 @@ void EndRipple()

void CreateRipple()
{
var drawable = Build.VERSION.SdkInt >= BuildVersionCodes.M && Group == null
var drawable = XCT.SdkInt >= (int)BuildVersionCodes.M && Group == null
? View?.Foreground
: View?.Background;

Expand All @@ -379,7 +380,7 @@ void UpdateRipple()
rippleColor = effect.NativeAnimationColor;
rippleRadius = effect.NativeAnimationRadius;
ripple?.SetColor(GetColorStateList());
if (Build.VERSION.SdkInt >= BuildVersionCodes.M && ripple != null)
if (XCT.SdkInt >= (int)BuildVersionCodes.M && ripple != null)
ripple.Radius = (int)(View.Context?.Resources?.DisplayMetrics?.Density * effect?.NativeAnimationRadius ?? throw new NullReferenceException());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.CommunityToolkit.UI.Views;
using Xamarin.Forms.Platform.Android;

Expand All @@ -7,7 +8,7 @@ namespace Xamarin.CommunityToolkit.Extensions
public static partial class NavigationExtensions
{
static void PlatformShowPopup(BasePopup popup) =>
Platform.CreateRendererWithContext(popup, ToolkitPlatform.Context);
Platform.CreateRendererWithContext(popup, XCT.Context);

static Task<T?> PlatformShowPopupAsync<T>(Popup<T> popup)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Android.OS;
using Xamarin.CommunityToolkit.Helpers;
using AView = Android.Views.View;

namespace Xamarin.CommunityToolkit.Extensions.Internals
Expand All @@ -8,7 +9,7 @@ public static class ViewExtensions
internal static void MaybeRequestLayout(this AView view)
{
var isInLayout = false;
if ((int)Build.VERSION.SdkInt >= 18)
if (XCT.SdkInt >= 18)
isInLayout = view.IsInLayout;

if (!isInLayout && !view.IsLayoutRequested)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System;
using Android.Content;
using Android.OS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

namespace Xamarin.CommunityToolkit
namespace Xamarin.CommunityToolkit.Helpers
{
/// <summary>
/// Platform extension methods.
/// </summary>
static class ToolkitPlatform
static class XCT
{
static Context? context;
static int? sdkInt;
Expand All @@ -33,4 +30,4 @@ internal static Context Context

internal static int SdkInt => sdkInt ??= (int)Build.VERSION.SdkInt;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Xamarin.CommunityToolkit.Helpers
{
static class XCT
{
internal static bool IsiOS13OrNewer => UIDevice.CurrentDevice.CheckSystemVersion(13, 0);
static bool? isiOS13OrNewer;

internal static bool IsiOS13OrNewer => isiOS13OrNewer ??= UIDevice.CurrentDevice.CheckSystemVersion(13, 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Android.OS;
using Xamarin.CommunityToolkit.Helpers;

// Inspired by Xamarin.Essentials.MainThread https://github.com/xamarin/Essentials/tree/main/Xamarin.Essentials/MainThread
namespace Xamarin.CommunityToolkit.ObjectModel.Internals
Expand All @@ -12,7 +13,7 @@ static bool IsMainThread
{
get
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
if (XCT.SdkInt >= (int)BuildVersionCodes.M)
return Looper.MainLooper?.IsCurrentThread ?? false;

return Looper.MyLooper() == Looper.MainLooper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.CommunityToolkit.Helpers;

#if MONOANDROID
using Xamarin.Forms.Platform.Android;
Expand Down Expand Up @@ -40,7 +41,7 @@ public async Task<bool> IsImageSourceValidAsync(ImageSource? source)
#if TIZEN
return await handler.LoadImageAsync(new NImage(XForms.NativeParent), source).ConfigureAwait(false);
#elif MONOANDROID
var imageSource = await handler.LoadImageAsync(source, ToolkitPlatform.Context).ConfigureAwait(false);
var imageSource = await handler.LoadImageAsync(source, XCT.Context).ConfigureAwait(false);
return imageSource != null;
#else
var imageSource = await handler.LoadImageAsync(source).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.Forms;

namespace Xamarin.CommunityToolkit.UI.Views
Expand All @@ -10,7 +11,7 @@ public ThumbFrame()
#region Required work-around to prevent linker from removing the platform-specific implementation
#if __ANDROID__
if (System.DateTime.Now.Ticks < 0)
_ = new ThumbFrameRenderer(ToolkitPlatform.Context ?? throw new NullReferenceException());
_ = new ThumbFrameRenderer(XCT.Context ?? throw new NullReferenceException());
#endif
#endregion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.CommunityToolkit.Helpers;
using Xamarin.CommunityToolkit.UI.Views.Internals;
using Xamarin.Forms;
using static System.Math;
Expand Down Expand Up @@ -94,7 +95,7 @@ public SideMenuView()
#region Required work-around to prevent linker from removing the platform-specific implementation
#if __ANDROID__
if (System.DateTime.Now.Ticks < 0)
_ = new Xamarin.CommunityToolkit.Android.UI.Views.SideMenuViewRenderer(ToolkitPlatform.Context ?? throw new NullReferenceException());
_ = new Xamarin.CommunityToolkit.Android.UI.Views.SideMenuViewRenderer(XCT.Context ?? throw new NullReferenceException());
#elif __IOS__
if (System.DateTime.Now.Ticks < 0)
_ = new Xamarin.CommunityToolkit.iOS.UI.Views.SideMenuViewRenderer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ void UpdateCharacterSpacing()
if (Element == null)
return;

if (ToolkitPlatform.SdkInt >= 21)
if (XCT.SdkInt >= 21)
{
// 0.0624 - Coefficient for converting Pt to Em
var characterSpacing = (float)(Element.CharacterSpacing * 0.0624);
Expand Down Expand Up @@ -483,7 +483,7 @@ void UpdateText()
switch (Element.TextType)
{
case TextType.Html:
if (ToolkitPlatform.SdkInt >= 24)
if (XCT.SdkInt >= 24)
{
nextView.SetText(Html.FromHtml(Element.Text ?? string.Empty, FromHtmlOptions.ModeCompact), BufferType.Spannable);
ShowNext();
Expand Down