Last active
May 24, 2022 18:38
-
-
Save dimonovdd/2de51d270516d4610a83fa38b45d9a9d to your computer and use it in GitHub Desktop.
This file contains 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
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; | |
} | |
} |
This file contains 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
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