Skip to content

Instantly share code, notes, and snippets.

@dimonovdd
Last active May 24, 2022 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimonovdd/2de51d270516d4610a83fa38b45d9a9d to your computer and use it in GitHub Desktop.
Save dimonovdd/2de51d270516d4610a83fa38b45d9a9d to your computer and use it in GitHub Desktop.
public static class PageSpecific
{
public static readonly BindableProperty BackSwipeEnableProperty =
BindableProperty.Create("BackSwipeEnable", typeof(bool), typeof(Page), true, BindingMode.OneTime);
public static bool GetBackSwipeEnable(BindableObject element)
=> (bool) element.GetValue(BackSwipeEnableProperty);
public static void SetBackSwipeEnable(BindableObject element, bool value)
=> element.SetValue(BackSwipeEnableProperty, value);
public static bool GetBackSwipeEnable(this IPlatformElementConfiguration<iOSPlatform, Page> config)
=> GetBackSwipeEnable(config.Element);
public static IPlatformElementConfiguration<iOSPlatform, Page> SetBackSwipeEnable(this IPlatformElementConfiguration<iOSPlatform, Page> config, bool value)
{
SetBackSwipeEnable(config.Element, value);
return config;
}
}
public class ContentPageRenderer : PageRenderer, IUIGestureRecognizerDelegate
{
private static bool _backSwipeEnable = true;
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var page = (Page)Element;
_backSwipeEnable = page?.On<iOSConfig>()?.GetBackSwipeEnable() ?? true;
if (!CheckCanInteractivePopGesture() || (page != null && NavigationPage.GetHasNavigationBar(page)))
return;
ViewController.NavigationController.InteractivePopGestureRecognizer.Delegate = this;
}
[Export("gestureRecognizerShouldBegin:")]
public bool ShouldBegin(UIGestureRecognizer recognizer)
=> CheckCanInteractivePopGesture();
private bool CheckCanInteractivePopGesture()
=> _backSwipeEnable
&& ViewController?.NavigationController?.ViewControllers?.Length > 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment