Skip to content
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

🐛 Mobile | Fix iOS border animation #1106

Merged
merged 3 commits into from
Oct 22, 2024
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
1 change: 1 addition & 0 deletions src/MobileUI/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static MauiApp CreateMauiApp()
.ConfigureMauiHandlers((handlers) =>
{
handlers.AddHandler(typeof(TableView), typeof(CustomTableViewRenderer));
handlers.AddHandler<Border, NotAnimatedBorderHandler>();
});

AppCenter.Start($"android={Constants.AppCenterAndroidId};" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.Maui.Handlers;

namespace SSW.Rewards.Mobile.Renderers;

public class NotAnimatedBorderHandler : BorderHandler
{

}
38 changes: 38 additions & 0 deletions src/MobileUI/Platforms/iOS/Renderers/NotAnimatedBorderHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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
// 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
{
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 };
}
}
Loading