Created
December 24, 2019 02:02
-
-
Save dmariogatto/ef34efe62d3512366e493461b85b4e44 to your computer and use it in GitHub Desktop.
Workaround for Xamarin Forms iOS Shell "Nav Stack consistency error"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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