From fde090040993bbb2fd92f625dec936d25cf79394 Mon Sep 17 00:00:00 2001 From: Zachary Keeping Date: Fri, 18 Oct 2024 14:42:10 +1100 Subject: [PATCH 1/3] Disable animations on borders on iOS --- src/MobileUI/MauiProgram.cs | 7 ++++++- .../NoneAnimatedBorderContentView.cs | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs diff --git a/src/MobileUI/MauiProgram.cs b/src/MobileUI/MauiProgram.cs index 5b72a4943..49ced7d11 100644 --- a/src/MobileUI/MauiProgram.cs +++ b/src/MobileUI/MauiProgram.cs @@ -5,8 +5,8 @@ using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; using Microsoft.Extensions.Logging; +using Microsoft.Maui.Handlers; using Microsoft.Maui.LifecycleEvents; -using Microsoft.Maui.Platform; using Mopups.Hosting; using SkiaSharp.Views.Maui.Controls.Hosting; using SSW.Rewards.Mobile.Renderers; @@ -87,6 +87,11 @@ public static MauiApp CreateMauiApp() { handler.PlatformView.TintColor = UIKit.UIColor.FromRGB(204,65,65); }); + + // Workaround for an issue with border animation on iOS + // See: https://github.com/dotnet/maui/issues/18204 + BorderHandler.PlatformViewFactory = (h) => new NoneAnimatedBorderContentView() { CrossPlatformLayout = h.VirtualView }; + #endif return builder.Build(); diff --git a/src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs b/src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs new file mode 100644 index 000000000..10b9730ba --- /dev/null +++ b/src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs @@ -0,0 +1,21 @@ +namespace SSW.Rewards.Mobile.Renderers; + +// Workaround for an issue with border animation on iOS +// See: https://github.com/dotnet/maui/issues/18204 +class NoneAnimatedBorderContentView : Microsoft.Maui.Platform.ContentView +{ + public override void LayoutSubviews() + { + Layer.RemoveAllAnimations(); + + if (Layer.Sublayers != null) + { + foreach (var subLayer in Layer.Sublayers) + { + subLayer.RemoveAllAnimations(); + } + } + + base.LayoutSubviews(); + } +} \ No newline at end of file From f39c2575ad0e64a381a832766aad7b9829f6c33b Mon Sep 17 00:00:00 2001 From: Zachary Keeping Date: Fri, 18 Oct 2024 14:52:12 +1100 Subject: [PATCH 2/3] Cleanup --- src/MobileUI/MauiProgram.cs | 5 +-- .../Renderers/NotAnimatedBorderHandler.cs | 8 ++++ .../NoneAnimatedBorderContentView.cs | 21 ----------- .../iOS/Renderers/NotAnimatedBorderHandler.cs | 37 +++++++++++++++++++ 4 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 src/MobileUI/Platforms/Android/Renderers/NotAnimatedBorderHandler.cs delete mode 100644 src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs create mode 100644 src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs diff --git a/src/MobileUI/MauiProgram.cs b/src/MobileUI/MauiProgram.cs index 49ced7d11..271d29b60 100644 --- a/src/MobileUI/MauiProgram.cs +++ b/src/MobileUI/MauiProgram.cs @@ -44,6 +44,7 @@ public static MauiApp CreateMauiApp() .ConfigureMauiHandlers((handlers) => { handlers.AddHandler(typeof(TableView), typeof(CustomTableViewRenderer)); + handlers.AddHandler(); }); AppCenter.Start($"android={Constants.AppCenterAndroidId};" + @@ -87,10 +88,6 @@ public static MauiApp CreateMauiApp() { handler.PlatformView.TintColor = UIKit.UIColor.FromRGB(204,65,65); }); - - // Workaround for an issue with border animation on iOS - // See: https://github.com/dotnet/maui/issues/18204 - BorderHandler.PlatformViewFactory = (h) => new NoneAnimatedBorderContentView() { CrossPlatformLayout = h.VirtualView }; #endif diff --git a/src/MobileUI/Platforms/Android/Renderers/NotAnimatedBorderHandler.cs b/src/MobileUI/Platforms/Android/Renderers/NotAnimatedBorderHandler.cs new file mode 100644 index 000000000..5cb0bdf7f --- /dev/null +++ b/src/MobileUI/Platforms/Android/Renderers/NotAnimatedBorderHandler.cs @@ -0,0 +1,8 @@ +using Microsoft.Maui.Handlers; + +namespace SSW.Rewards.Mobile.Renderers; + +public class NotAnimatedBorderHandler : BorderHandler +{ + +} \ No newline at end of file diff --git a/src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs b/src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs deleted file mode 100644 index 10b9730ba..000000000 --- a/src/MobileUI/Platforms/iOS/Renderers/NoneAnimatedBorderContentView.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace SSW.Rewards.Mobile.Renderers; - -// Workaround for an issue with border animation on iOS -// See: https://github.com/dotnet/maui/issues/18204 -class NoneAnimatedBorderContentView : Microsoft.Maui.Platform.ContentView -{ - public override void LayoutSubviews() - { - Layer.RemoveAllAnimations(); - - if (Layer.Sublayers != null) - { - foreach (var subLayer in Layer.Sublayers) - { - subLayer.RemoveAllAnimations(); - } - } - - base.LayoutSubviews(); - } -} \ No newline at end of file diff --git a/src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs b/src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs new file mode 100644 index 000000000..9c450f4dd --- /dev/null +++ b/src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs @@ -0,0 +1,37 @@ +using CoreAnimation; +using Microsoft.Maui.Handlers; +using ContentView = Microsoft.Maui.Platform.ContentView; + +namespace SSW.Rewards.Mobile.Renderers; + +// Workaround for an issue with border animation on iOS +// See: https://github.com/dotnet/maui/issues/18204 +public class NotAnimatedBorderHandler : BorderHandler +{ + private class BorderContentView : ContentView + { + public override void LayoutSubviews() + { + Layer.RemoveAllAnimations(); + + if (Layer.Sublayers != null) + { + foreach (var sublayer in Layer.Sublayers) + { + sublayer.RemoveAllAnimations(); + } + } + + base.LayoutSubviews(); + } + } + + protected override ContentView CreatePlatformView() + { + _ = VirtualView ?? + throw new InvalidOperationException($"{nameof(VirtualView)} must be set to create a {nameof(ContentView)}"); + _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} cannot be null"); + + return new BorderContentView { CrossPlatformLayout = VirtualView }; + } +} \ No newline at end of file From e2e90669b9505e74edfcad6b2bcd37d26b4deedf Mon Sep 17 00:00:00 2001 From: Zachary Keeping Date: Fri, 18 Oct 2024 15:06:50 +1100 Subject: [PATCH 3/3] Cleanup --- src/MobileUI/MauiProgram.cs | 3 +-- .../Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MobileUI/MauiProgram.cs b/src/MobileUI/MauiProgram.cs index 271d29b60..aa75a3be8 100644 --- a/src/MobileUI/MauiProgram.cs +++ b/src/MobileUI/MauiProgram.cs @@ -5,8 +5,8 @@ using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; using Microsoft.Extensions.Logging; -using Microsoft.Maui.Handlers; using Microsoft.Maui.LifecycleEvents; +using Microsoft.Maui.Platform; using Mopups.Hosting; using SkiaSharp.Views.Maui.Controls.Hosting; using SSW.Rewards.Mobile.Renderers; @@ -88,7 +88,6 @@ public static MauiApp CreateMauiApp() { handler.PlatformView.TintColor = UIKit.UIColor.FromRGB(204,65,65); }); - #endif return builder.Build(); diff --git a/src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs b/src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs index 9c450f4dd..d884c7d46 100644 --- a/src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs +++ b/src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs @@ -6,6 +6,7 @@ namespace SSW.Rewards.Mobile.Renderers; // Workaround for an issue with border animation on iOS // See: https://github.com/dotnet/maui/issues/18204 +// TODO: Remove this workaround when the issue is fixed in MAUI (should be version 9.0.0) public class NotAnimatedBorderHandler : BorderHandler { private class BorderContentView : ContentView