Skip to content

Instantly share code, notes, and snippets.

@dmariogatto
Created December 24, 2019 02:02
Show Gist options
  • Save dmariogatto/ef34efe62d3512366e493461b85b4e44 to your computer and use it in GitHub Desktop.
Save dmariogatto/ef34efe62d3512366e493461b85b4e44 to your computer and use it in GitHub Desktop.
Workaround for Xamarin Forms iOS Shell "Nav Stack consistency error"
using System;
using System.Collections.Generic;
using Foundation;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using YourAwesomeApp.iOS.Renderers;
[assembly: ExportRenderer(typeof(Shell), typeof(ShellCustomRenderer))]
namespace YourAwesomeApp.iOS.Renderers
{
[Preserve(AllMembers = true)]
public class ShellCustomRenderer : ShellRenderer
{
private readonly List<ShellSectionRenderer> _shellSectionRenderers = new List<ShellSectionRenderer>();
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
var renderer = base.CreateShellSectionRenderer(shellSection);
if (renderer is ShellSectionRenderer ssr)
{
_shellSectionRenderers.Add(ssr);
}
return renderer;
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
foreach(var ssr in _shellSectionRenderers)
{
try
{
if (ssr?.InteractivePopGestureRecognizer != null)
{
ssr.InteractivePopGestureRecognizer.Enabled = false;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
_shellSectionRenderers.Clear();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment