Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,34 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup? container

_navigationRootManager = modalContext.GetNavigationRootManager();
_navigationRootManager.Connect(_modal, modalContext);

UpdateBackgroundColor();

return _navigationRootManager?.RootView ??
var rootView = _navigationRootManager?.RootView ??
throw new InvalidOperationException("Root view not initialized");

if (IsAnimated)
{
_ = new GenericGlobalLayoutListener((listener,view) =>
{
listener.Invalidate();
if(view is not null)
{
var animation = AnimationUtils.LoadAnimation(view.Context, Resource.Animation.nav_modal_default_enter_anim)!;
view.StartAnimation(animation);
animation.AnimationEnd += OnAnimationEnded;
}
},_navigationRootManager.RootView);
}
return rootView;
}
void OnAnimationEnded(object? sender, AAnimation.AnimationEndEventArgs e)
{
if (sender is not AAnimation animation)
return;

animation.AnimationEnd -= OnAnimationEnded;
FireAnimationEnded();
}

public override void OnCreate(Bundle? savedInstanceState)
Expand All @@ -329,26 +352,7 @@ public override void OnStart()

int width = ViewGroup.LayoutParams.MatchParent;
int height = ViewGroup.LayoutParams.MatchParent;
dialog.Window.SetLayout(width, height);

if (IsAnimated)
{
var animation = AnimationUtils.LoadAnimation(_mauiWindowContext.Context, Resource.Animation.nav_modal_default_enter_anim)!;
View.StartAnimation(animation);

animation.AnimationEnd += OnAnimationEnded;
}

void OnAnimationEnded(object? sender, AAnimation.AnimationEndEventArgs e)
{
if (sender is not AAnimation animation)
{
return;
}

animation.AnimationEnd -= OnAnimationEnded;
FireAnimationEnded();
}
dialog.Window.SetLayout(width, height);
}

public override void OnDismiss(IDialogInterface dialog)
Expand Down
30 changes: 30 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Modal/ModalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,36 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(window, async handler =>
}
#endif

[Fact("Dont leak with Animation")]
public async Task ModalPageDontLeakWithAnimation()
{
SetupBuilder();
var references = new List<WeakReference>();


var page = new ContentPage();
var window = new Window(page);

await CreateHandlerAndAddToWindow<WindowHandlerStub>(window, async handler =>
{
var modalPage = new ContentPage
{
Content = new Label { Text = "Modal Content" }
};
await page.Navigation.PushModalAsync(modalPage,true);
await OnLoadedAsync(modalPage);

references.Add(new WeakReference(modalPage));
references.Add(new WeakReference(modalPage.Handler));
references.Add(new WeakReference(modalPage.Handler.PlatformView));

await page.Navigation.PopModalAsync();
await OnUnloadedAsync(modalPage);
});

await AssertionExtensions.WaitForGC(references.ToArray());
}

class PageTypes : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
Expand Down