rotorgames / Rg.Plugins.Popup

Xamarin Forms popup plugin
MIT License
1.15k stars 337 forks source link

Animation runs on wrong view when using ControlTemplate #678

Open Andreas0xffff opened 3 years ago

Andreas0xffff commented 3 years ago

🐛 Bug Report

If the 'ControlTemplate' property of the PopupPage is used, the 'Content' property does not represent the real content of the page. PopupPage should allow the specification of the content for the animation via a overrideable function or similar.

Expected behavior

Not the PopupPage.Content should be the first parameter of the IPopupAnimation functions, the PopupPage.Children.First() is better. The best would be something like that

public class PopupPage : ContentPage
{
protected virtual View GetView4Animation()
{
    return Content;
}

internal async Task AppearingAnimation()
{
    OnAppearingAnimationBegin();
    await OnAppearingAnimationBeginAsync();

    if (IsAnimationEnabled && Animation != null)
        await Animation.Appearing(GetView4Animation()/*Content*/, this);

    OnAppearingAnimationEnd();
    await OnAppearingAnimationEndAsync();
}
}

With this overrideable, there will be no breaking change. Alternativly:

protected virtual View GetView4Animation()
{
    if(ControlTemplate == null)
        return Content;
    else
        return Children.FirstOrDefault() ?? Content;
}

Reproduction steps

Use ControlTemplate zu define a standardized appearance for the PopupPages.

<rg:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              xmlns:rg="http://rotorgames.com"
             ControlTemplate="{StaticResource PopupTemplate}"
              x:Class="Demo.Pages.SettingsPage">

Configuration

Version: 2.0.0.11

Platform: all