diff --git a/src/AddIns/Uno.UI.Lottie/LottieVisualSource.iOSmacOS.cs b/src/AddIns/Uno.UI.Lottie/LottieVisualSource.iOSmacOS.cs deleted file mode 100644 index 8fe4d64287c3..000000000000 --- a/src/AddIns/Uno.UI.Lottie/LottieVisualSource.iOSmacOS.cs +++ /dev/null @@ -1,225 +0,0 @@ -#if !NET6_0_OR_GREATER -using System; -using System.Threading; -using Windows.Foundation; -using Microsoft.UI.Xaml.Controls; -using Airbnb.Lottie; -using Foundation; -using System.Threading.Tasks; -using Uno.Disposables; -#if __IOS__ -using _ViewContentMode = UIKit.UIViewContentMode; -#else -using _ViewContentMode = Airbnb.Lottie.LOTViewContentMode; -#endif - -#if HAS_UNO_WINUI -namespace CommunityToolkit.WinUI.Lottie -#else -namespace Microsoft.Toolkit.Uwp.UI.Lottie -#endif -{ - partial class LottieVisualSourceBase - { - private LOTAnimationView? _animation; - - private Uri? _lastSource; - private (double fromProgress, double toProgress, bool looped)? _playState; - - private readonly SerialDisposable _animationDataSubscription = new SerialDisposable(); - - async Task InnerUpdate(CancellationToken ct) - { - var player = _player; - - if (player == null) - { - return; - } - - await SetProperties(); - - async Task SetProperties() - { - var sourceUri = UriSource; - if (_lastSource == null || !_lastSource.Equals(sourceUri)) - { - _lastSource = sourceUri; - if ((await TryLoadDownloadJson(sourceUri, ct)) is { } jsonStream) - { - var tcs = new TaskCompletionSource(); - - var cacheKey = sourceUri.OriginalString; - _animationDataSubscription.Disposable = null; - _animationDataSubscription.Disposable = - LoadAndObserveAnimationData(jsonStream, cacheKey, OnJsonChanged); - - void OnJsonChanged(string updatedJson, string updatedCacheKey) - { - var jsonData = NSJsonSerialization.Deserialize(NSData.FromString(updatedJson), default, out var _) as NSDictionary; - var animation = LOTAnimationView.AnimationFromJSON(jsonData); - SetAnimation(animation); - - tcs.TrySetResult(true); - } - - await tcs.Task; - } - else - { - var path = sourceUri?.PathAndQuery ?? ""; - if (path.StartsWith("/", StringComparison.Ordinal)) - { - path = path.Substring(1); - } - - if (_animation == null) - { - var animation = new LOTAnimationView(); - _animation = SetAnimation(animation); - } - - _animation.SetAnimationNamed(path); - } - - // Force layout to recalculate - player.InvalidateMeasure(); - player.InvalidateArrange(); - - if (_playState != null) - { - var (fromProgress, toProgress, looped) = _playState.Value; - Play(fromProgress, toProgress, looped); - } - else if (player.AutoPlay) - { - Play(0, 1, true); - } - } - - if (_animation == null) - { - return; - } - - switch (player.Stretch) - { - case Microsoft.UI.Xaml.Media.Stretch.None: - _animation.ContentMode = _ViewContentMode.Center; - break; - case Microsoft.UI.Xaml.Media.Stretch.Uniform: - _animation.ContentMode = _ViewContentMode.ScaleAspectFit; - break; - case Microsoft.UI.Xaml.Media.Stretch.Fill: - _animation.ContentMode = _ViewContentMode.ScaleToFill; - break; - case Microsoft.UI.Xaml.Media.Stretch.UniformToFill: - _animation.ContentMode = _ViewContentMode.ScaleAspectFill; - break; - } - - var duration = TimeSpan.FromSeconds(_animation.AnimationDuration); - player.SetValue(AnimatedVisualPlayer.DurationProperty, duration); - - var isLoaded = duration > TimeSpan.Zero; - player.SetValue(AnimatedVisualPlayer.IsAnimatedVisualLoadedProperty, isLoaded); - - _animation.CompletionBlock = isCompleted => - { - SetIsPlaying(_animation.IsAnimationPlaying); - }; - - _animation.AnimationSpeed = (nfloat)player.PlaybackRate; - } - } - - private LOTAnimationView SetAnimation(LOTAnimationView animation) - { - if (!ReferenceEquals(_animation, animation)) - { - _animation?.RemoveFromSuperview(); - } -#if __IOS__ - _player?.Add(animation); -#else - _player?.AddSubview(animation); -#endif - _animation = animation; - return animation; - } - - public void Play(double fromProgress, double toProgress, bool looped) - { - _playState = (fromProgress, toProgress, looped); - if (_animation != null) - { - if (_animation.IsAnimationPlaying) - { - _animation.Stop(); - } - - _animation.LoopAnimation = looped; - - void Start() - { - _animation.PlayFromProgress((nfloat)fromProgress, (nfloat)toProgress, isFinished => - { - if (looped && isFinished) - { - Start(); - } - }); - } - - Start(); - SetIsPlaying(true); - } - } - - public void Stop() - { - _playState = null; - SetIsPlaying(false); - _animation?.Stop(); - } - - public void Pause() - { - SetIsPlaying(false); - _animation?.Pause(); - } - - public void Resume() - { - _animation?.Play(); - SetIsPlaying(true); - } - - public void SetProgress(double progress) - { - if (_animation != null) - { - _animation.AnimationProgress = (nfloat)progress; - } - } - - public void Load() - { - if (_player?.IsPlaying ?? false) - { - _animation?.Play(); - } - } - - public void Unload() - { - if (_player?.IsPlaying ?? false) - { - _animation?.Pause(); - } - } - - private Size CompositionSize => _animation?.IntrinsicContentSize ?? default; - } -} -#endif diff --git a/src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.Android.cs b/src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.Android.cs deleted file mode 100644 index 2b136857b7e5..000000000000 --- a/src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.Android.cs +++ /dev/null @@ -1,265 +0,0 @@ -#if !NET6_0_OR_GREATER -using System; -using System.Threading; -using Android.Animation; -using Android.Widget; -using Windows.Foundation; -using Microsoft.UI.Xaml.Controls; -using Android.Views; -using Uno.Disposables; -using Uno.UI; -using ViewHelper = Uno.UI.ViewHelper; -using System.Threading.Tasks; - -using Com.Airbnb.Lottie; - -#if HAS_UNO_WINUI -namespace CommunityToolkit.WinUI.Lottie -#else -namespace Microsoft.Toolkit.Uwp.UI.Lottie -#endif -{ - partial class LottieVisualSourceBase - { - private LottieAnimationView? _animation; - - private LottieListener? _listener; - - private class LottieListener : AnimatorListenerAdapter - { - private readonly LottieVisualSourceBase _lottieVisualSource; - - public LottieListener(LottieVisualSourceBase lottieVisualSource) - { - _lottieVisualSource = lottieVisualSource; - } - - public override void OnAnimationCancel(Animator? animation) => _lottieVisualSource.SetIsPlaying(false); - - public override void OnAnimationEnd(Animator? animation) => _lottieVisualSource.SetIsPlaying(false); - - public override void OnAnimationPause(Animator? animation) => _lottieVisualSource.SetIsPlaying(false); - - public override void OnAnimationResume(Animator? animation) => _lottieVisualSource.SetIsPlaying(true); - - public override void OnAnimationStart(Animator? animation) => _lottieVisualSource.SetIsPlaying(true); - } - - private Uri? _lastSource; - private (double fromProgress, double toProgress, bool looped)? _playState; - - private readonly SerialDisposable _animationDataSubscription = new SerialDisposable(); - - async Task InnerUpdate(CancellationToken ct) - { - if (!(_player is { } player)) - { - return; - } - - if (_animation == null) - { - _listener = new LottieListener(this); - - _animation = new LottieAnimationView(Android.App.Application.Context); - _animation.EnableMergePathsForKitKatAndAbove(true); - - _animation.AddAnimatorListener(_listener); - - await SetProperties(); - - // Add the player after - player.AddView(_animation); - } - else - { - await SetProperties(); - } - - async Task SetProperties() - { - var sourceUri = UriSource; - if (_lastSource == null || !_lastSource.Equals(sourceUri)) - { - _lastSource = sourceUri; - - if ((await TryLoadDownloadJson(sourceUri, ct)) is { } jsonStream) - { - var first = true; - - var cacheKey = sourceUri.OriginalString; - _animationDataSubscription.Disposable = null; - _animationDataSubscription.Disposable = - LoadAndObserveAnimationData(jsonStream, cacheKey, OnJsonChanged); - - void OnJsonChanged(string updatedJson, string updatedCacheKey) - { - _animation.SetAnimationFromJson(updatedJson, updatedCacheKey); - - if (_playState != null) - { - var (fromProgress, toProgress, looped) = _playState.Value; - Play(fromProgress, toProgress, looped); - } - else if (player.AutoPlay && first) - { - Play(0, 1, true); - } - - first = false; - SetDuration(); - } - } - else - { - var path = sourceUri?.PathAndQuery ?? ""; - if (path.StartsWith("/", StringComparison.Ordinal)) - { - path = path.Substring(1); - } - - _animation.SetAnimation(path); - - if (_playState != null) - { - var (fromProgress, toProgress, looped) = _playState.Value; - Play(fromProgress, toProgress, looped); - } - else if (player.AutoPlay) - { - Play(0, 1, true); - } - - SetDuration(); - } - } - - switch (player.Stretch) - { - case Microsoft.UI.Xaml.Media.Stretch.None: - _animation.SetScaleType(ImageView.ScaleType.Center); - break; - case Microsoft.UI.Xaml.Media.Stretch.Uniform: - _animation.SetScaleType(ImageView.ScaleType.CenterInside); - break; - case Microsoft.UI.Xaml.Media.Stretch.Fill: - _animation.SetScaleType(ImageView.ScaleType.FitCenter); - break; - case Microsoft.UI.Xaml.Media.Stretch.UniformToFill: - _animation.SetScaleType(ImageView.ScaleType.CenterCrop); - break; - } - - _animation.Speed = (float)player.PlaybackRate; - } - } - - partial void InnerMeasure(Size size) - { - var physicalSize = size.LogicalToPhysicalPixels(); - - _animation?.Measure( - ViewHelper.MakeMeasureSpec((int)physicalSize.Width, MeasureSpecMode.AtMost), - ViewHelper.MakeMeasureSpec((int)physicalSize.Height, MeasureSpecMode.AtMost) - ); - } - - private void SetDuration() - { - if (_animation is { } animation) - { - var duration = TimeSpan.FromMilliseconds(animation.Duration); - _player?.SetValue(AnimatedVisualPlayer.DurationProperty, duration); - _player?.SetValue(AnimatedVisualPlayer.IsAnimatedVisualLoadedProperty, duration > TimeSpan.Zero); - } - } - - public void Play(double fromProgress, double toProgress, bool looped) - { - _playState = (fromProgress, toProgress, looped); - if (_player == null) - { - return; - } - SetIsPlaying(true); - if (_animation is { } animation) - { - animation.RepeatCount = - looped ? ValueAnimator.Infinite : 0; // Repeat count doesn't include first time. - animation.SetMinProgress((float)fromProgress); - animation.SetMaxProgress((float)toProgress); - animation.PlayAnimation(); - } - } - - public void Stop() - { - _playState = null; - if (_player == null) - { - return; - } - _playState = null; - _animation?.CancelAnimation(); - } - - public void Pause() - { - _animation?.PauseAnimation(); - } - - public void Resume() - { - _animation?.ResumeAnimation(); - } - - public void SetProgress(double progress) - { - if (_animation == null) - { - return; - } - - //If setting Progress directly, we should have the full range to choose from - //Will be overridden in the Play method - _animation.SetMinAndMaxProgress(0f, 1f); - _animation.Progress = (float)progress; - Stop(); - } - - public void Load() - { - if (_player?.IsPlaying ?? false) - { - _animation?.ResumeAnimation(); - } - } - - public void Unload() - { - if (_player?.IsPlaying ?? false) - { - _animation?.PauseAnimation(); - } - } - - private Size CompositionSize - { - get - { - var composition = _animation?.Composition; - if (composition != null) - { - SetDuration(); - - var bounds = composition.Bounds; - - return new Size(bounds.Width(), bounds.Height()); - } - - return default; - } - } - } -} -#endif diff --git a/src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.cs b/src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.cs index 1f70d9d983ef..09ecf9167d05 100644 --- a/src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.cs +++ b/src/AddIns/Uno.UI.Lottie/LottieVisualSourceBase.cs @@ -32,7 +32,7 @@ public abstract partial class LottieVisualSourceBase : DependencyObject, IAnimat { public delegate void UpdatedAnimation(string animationJson, string cacheKey); -#if ((__ANDROID__ || __IOS__ || __MACOS__) && !NET6_0_OR_GREATER) || HAS_SKOTTIE || __WASM__ +#if HAS_SKOTTIE || __WASM__ private static HttpClient? _httpClient; #endif @@ -97,7 +97,7 @@ public Task SetSourceAsync(Uri sourceUri) } -#if !(__WASM__ || (__ANDROID__ && !NET6_0_OR_GREATER) || (__IOS__ && !NET6_0_OR_GREATER) || (__MACOS__ && !NET6_0_OR_GREATER) || HAS_SKOTTIE) +#if !(__WASM__ || HAS_SKOTTIE) public void Play(double fromProgress, double toProgress, bool looped) => ThrowNotImplementedOnNonTestPlatforms(); @@ -196,7 +196,7 @@ async Task Load(CancellationToken ct) }); } -#if ((__ANDROID__ || __IOS__ || __MACOS__) && !NET6_0_OR_GREATER) || HAS_SKOTTIE +#if HAS_SKOTTIE private void SetIsPlaying(bool isPlaying) => _player?.SetValue(AnimatedVisualPlayer.IsPlayingProperty, isPlaying); #endif @@ -247,7 +247,7 @@ Size IAnimatedVisualSource.Measure(Size availableSize) partial void InnerMeasure(Size size); -#if ((__ANDROID__ || __IOS__ || __MACOS__) && !NET6_0_OR_GREATER) || HAS_SKOTTIE || __WASM__ +#if HAS_SKOTTIE || __WASM__ private async Task TryLoadDownloadJson(Uri uri, CancellationToken ct) { if (TryLoadEmbeddedJson(uri, ct) is { } json) diff --git a/src/AddIns/Uno.UI.MSAL/AcquireTokenInteractiveParameterBuilderExtensions.cs b/src/AddIns/Uno.UI.MSAL/AcquireTokenInteractiveParameterBuilderExtensions.cs index 48e280dcbb8b..c4a74111666e 100644 --- a/src/AddIns/Uno.UI.MSAL/AcquireTokenInteractiveParameterBuilderExtensions.cs +++ b/src/AddIns/Uno.UI.MSAL/AcquireTokenInteractiveParameterBuilderExtensions.cs @@ -15,12 +15,8 @@ public static AcquireTokenInteractiveParameterBuilder WithUnoHelpers(this Acquir #if __WASM__ builder.WithCustomWebUi(WasmWebUi.Instance); #elif __MACOS__ -#if NET6_0_OR_GREATER // WithUnoHelpers is not yet supported for macOS on .NET 6 // builder.WithParentActivityOrWindow(Microsoft.UI.Xaml.Window.Current.Content.Window); -#else - builder.WithParentActivityOrWindow(Microsoft.UI.Xaml.Window.Current.Content.Window); -#endif #endif return builder; } diff --git a/src/SourceGenerators/SourceGeneratorHelpers/Helpers/Nullable.cs b/src/SourceGenerators/SourceGeneratorHelpers/Helpers/Nullable.cs index 1e9802b501b3..06862e666355 100644 --- a/src/SourceGenerators/SourceGeneratorHelpers/Helpers/Nullable.cs +++ b/src/SourceGenerators/SourceGeneratorHelpers/Helpers/Nullable.cs @@ -137,7 +137,7 @@ sealed class DoesNotReturnIfAttribute : Attribute } #endif -#if NETSTANDARD2_0 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 || NET45 || NET451 || NET452 || NET46 || IS_UNIT_TESTS || NET462 || NET47 || NET471 || NET472 || NET48 || (!NET6_0_OR_GREATER && (__IOS__ || __ANDROID__ || __MACOS__)) +#if NETSTANDARD2_0 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NETCOREAPP3_0 || NETCOREAPP3_1 || NET45 || NET451 || NET452 || NET46 || IS_UNIT_TESTS || NET462 || NET47 || NET471 || NET472 || NET48 /// Specifies that the method or property will ensure that the listed field and property members have not-null values. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] #if SYSTEM_PRIVATE_CORELIB diff --git a/src/Uno.UI.Toolkit/CommandBarExtensions.cs b/src/Uno.UI.Toolkit/CommandBarExtensions.cs index 8981d36f0d59..fc558cae17a0 100644 --- a/src/Uno.UI.Toolkit/CommandBarExtensions.cs +++ b/src/Uno.UI.Toolkit/CommandBarExtensions.cs @@ -7,13 +7,6 @@ namespace Uno.UI.Toolkit { -#if !NET6_0_OR_GREATER // Moved to the linker definition file -#if __IOS__ - [global::Foundation.PreserveAttribute(AllMembers = true)] -#elif __ANDROID__ - [Android.Runtime.PreserveAttribute(AllMembers = true)] -#endif -#endif public static class CommandBarExtensions { #region Subtitle diff --git a/src/Uno.UI.Toolkit/MenuFlyoutExtensions.cs b/src/Uno.UI.Toolkit/MenuFlyoutExtensions.cs index 83cda8c02a09..702a77766a2c 100644 --- a/src/Uno.UI.Toolkit/MenuFlyoutExtensions.cs +++ b/src/Uno.UI.Toolkit/MenuFlyoutExtensions.cs @@ -6,13 +6,6 @@ namespace Uno.UI.Toolkit { -#if !NET6_0_OR_GREATER // Moved to the linker definition file -#if __IOS__ - [global::Foundation.PreserveAttribute(AllMembers = true)] -#elif __ANDROID__ - [Android.Runtime.PreserveAttribute(AllMembers = true)] -#endif -#endif public class MenuFlyoutExtensions { #region Property: CancelTextIosOverride diff --git a/src/Uno.UI.Toolkit/MenuFlyoutItemExtensions.cs b/src/Uno.UI.Toolkit/MenuFlyoutItemExtensions.cs index 2e270a11ddea..454bd05291a6 100644 --- a/src/Uno.UI.Toolkit/MenuFlyoutItemExtensions.cs +++ b/src/Uno.UI.Toolkit/MenuFlyoutItemExtensions.cs @@ -8,13 +8,6 @@ namespace Uno.UI.Toolkit { -#if !NET6_0_OR_GREATER // Moved to the linker definition file -#if __IOS__ - [global::Foundation.PreserveAttribute(AllMembers = true)] -#elif __ANDROID__ - [Android.Runtime.PreserveAttribute(AllMembers = true)] -#endif -#endif public static class MenuFlyoutItemExtensions { #region IsDestructive diff --git a/src/Uno.UI.Toolkit/SplitViewExtensions.cs b/src/Uno.UI.Toolkit/SplitViewExtensions.cs index 39a20527bdb9..79347cf48bf5 100644 --- a/src/Uno.UI.Toolkit/SplitViewExtensions.cs +++ b/src/Uno.UI.Toolkit/SplitViewExtensions.cs @@ -8,13 +8,6 @@ namespace Uno.UI.Toolkit { -#if !NET6_0_OR_GREATER // Moved to the linker definition file -#if __IOS__ - [global::Foundation.PreserveAttribute(AllMembers = true)] -#elif __ANDROID__ - [Android.Runtime.PreserveAttribute(AllMembers = true)] -#endif -#endif public static class SplitViewExtensions { #region IsPaneEnabled diff --git a/src/Uno.UI.Toolkit/UIElementExtensions.cs b/src/Uno.UI.Toolkit/UIElementExtensions.cs index c3280de68eeb..bbb5b0f0298e 100644 --- a/src/Uno.UI.Toolkit/UIElementExtensions.cs +++ b/src/Uno.UI.Toolkit/UIElementExtensions.cs @@ -33,13 +33,6 @@ namespace Uno.UI.Toolkit { -#if !NET6_0_OR_GREATER // Moved to the linker definition file -#if __IOS__ - [global::Foundation.PreserveAttribute(AllMembers = true)] -#elif __ANDROID__ - [Android.Runtime.PreserveAttribute(AllMembers = true)] -#endif -#endif public static class UIElementExtensions { #region Elevation diff --git a/src/Uno.UWP/Helpers/Theming/SystemThemeObserver.macOS.cs b/src/Uno.UWP/Helpers/Theming/SystemThemeObserver.macOS.cs index 0351b086d77a..adeeeb5b7a4a 100644 --- a/src/Uno.UWP/Helpers/Theming/SystemThemeObserver.macOS.cs +++ b/src/Uno.UWP/Helpers/Theming/SystemThemeObserver.macOS.cs @@ -12,11 +12,7 @@ public class SystemThemeObserver : NSObject internal void ObserveSystemThemeChanges() { NSDistributedNotificationCenter -#if NET6_0_OR_GREATER .DefaultCenter -#else - .GetDefaultCenter() -#endif .AddObserver( this, _modeSelector, diff --git a/src/Uno.UWP/UI/Color.iOS.cs b/src/Uno.UWP/UI/Color.iOS.cs index 04e589460973..b2a8251bc3a0 100644 --- a/src/Uno.UWP/UI/Color.iOS.cs +++ b/src/Uno.UWP/UI/Color.iOS.cs @@ -1,9 +1,6 @@ using System; using CoreGraphics; - -#if NET6_0_OR_GREATER using ObjCRuntime; -#endif namespace Windows.UI { diff --git a/src/Uno.UWP/UI/Color.macOS.cs b/src/Uno.UWP/UI/Color.macOS.cs index 753614a139fd..0a714a0de9cf 100644 --- a/src/Uno.UWP/UI/Color.macOS.cs +++ b/src/Uno.UWP/UI/Color.macOS.cs @@ -1,21 +1,12 @@ using System; using CoreGraphics; - -#if NET6_0_OR_GREATER using ObjCRuntime; -#endif namespace Windows.UI { public partial struct Color : IFormattable { -#if NET6_0_OR_GREATER private static bool legacy = OperatingSystem.IsMacOSVersionAtLeast(10, 15); -#else -#pragma warning disable CS0618 // Type or member is obsolete - private static bool legacy = !ObjCRuntime.PlatformHelper.CheckSystemVersion(10, 15); -#pragma warning restore CS0618 // Type or member is obsolete -#endif public static implicit operator AppKit.NSColor(Color color) => AppKit.NSColor.FromRgba(color.R, color.G, color.B, color.A); public static implicit operator CGColor(Color color) diff --git a/src/Uno.UWP/UI/ViewManagement/UISettings.cs b/src/Uno.UWP/UI/ViewManagement/UISettings.cs index b46a5d830da2..cabc1b11b38e 100644 --- a/src/Uno.UWP/UI/ViewManagement/UISettings.cs +++ b/src/Uno.UWP/UI/ViewManagement/UISettings.cs @@ -28,7 +28,7 @@ public UISettings() _instances.TryAdd(_weakReference, null); -#if __MACOS__ && NET6_0_OR_GREATER +#if __MACOS__ NSColor.Notifications.ObserveSystemColorsChanged((sender, eventArgs) => { OnColorValuesChanged(); @@ -66,7 +66,7 @@ public Color GetColorValue(UIColorType desiredColor) return desiredColor switch { -#if __MACOS__ && NET6_0_OR_GREATER +#if __MACOS__ UIColorType.Background => NSColor.ControlBackground, UIColorType.Foreground => NSColor.ControlText, UIColorType.Accent => NSColor.ControlAccent,