我目前正在构建一个应用程序,当弹出和推入Shell中的导航时,我希望没有动画。
我把它写在Push页面上,因为这只是函数的"False“语句,但是重写Back Button功能似乎对弹出动画没有任何影响。
下面应该覆盖应用程序中所有页面的后退按钮,以执行没有动画的Pop操作,但是仍然有动画发生。
我做错了什么吗?
public partial class AppShell : Xamarin.Forms.Shell
{
public AppShell()
{
InitializeComponent();
}
protected override bool OnBackButtonPressed()
{
Current.Navigation.PopAsync(false);
return true;
}
}发布于 2020-03-11 09:34:06
这是一个与Xamarin一起打开的bug,可以在这个Github问题中找到。
据我所知,xamarin团队认为这是一个突破性的变化,可能需要一段时间才能修复。
建议
这里有一个注释,它使用自定义渲染器以下列方式修复这个问题:
[assembly: ExportRenderer(typeof(NavigationPage), typeof(CNavigationPageRenderer))]
namespace TestApp.Droid
{
public class CNavigationPageRenderer : NavigationPageRenderer
{
public CNavigationPageRenderer(Context context) : base(context)
{
}
protected override Task<bool> OnPushAsync(Page view, bool animated)
{
return base.OnPushAsync(view, false);
}
protected override Task<bool> OnPopViewAsync(Page page, bool animated)
{
return base.OnPopViewAsync(page, false);
}
protected override Task<bool> OnPopToRootAsync(Page page, bool animated)
{
return base.OnPopToRootAsync(page, false);
}
}
}在其他平台上也是如此。正如我所说的,这使得核心中的动画标志毫无用处,但至少它禁用了所有的页面动画,即使当您使用后退按钮时,因为它应该调用OnPopViewAsync。 您可以在这里添加自定义逻辑,以扫描页面类型或特定条件集(就像您的自定义逻辑,即非动画推送应该与该特定页面的非动画弹出耦合)。
如果您有疑问,请随时回来。
https://stackoverflow.com/questions/60632551
复制相似问题