summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2017-01-03 11:30:35 (GMT)
committerRui Marinho <me@ruimarinho.net>2017-01-03 11:30:35 (GMT)
commitcc0eb5ba4326de96a52c0318a61b89c3bcb098e5 (patch)
tree71fcbef6e68b39289d362c84d735df1381054c3f /Xamarin.Forms.Platform.iOS
parent8c5fd096945301a2db0d85baf77ce46812a8d89f (diff)
downloadxamarin-forms-cc0eb5ba4326de96a52c0318a61b89c3bcb098e5.zip
xamarin-forms-cc0eb5ba4326de96a52c0318a61b89c3bcb098e5.tar.gz
xamarin-forms-cc0eb5ba4326de96a52c0318a61b89c3bcb098e5.tar.bz2
[iOS] Prevent multiple ListView cells from being swiped simultaneously (#578)
* disable multiple cell swipe * add sample code * refactored * convert to weakreference * remove null setting * change weakreference setting place * remove if * revert isopen changes * add instructions
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs31
1 files changed, 27 insertions, 4 deletions
diff --git a/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs b/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs
index 14f95a7..9d5debf 100644
--- a/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs
+++ b/Xamarin.Forms.Platform.iOS/ContextScrollViewDelegate.cs
@@ -45,7 +45,7 @@ namespace Xamarin.Forms.Platform.iOS
GlobalCloseContextGestureRecognizer _globalCloser;
bool _isDisposed;
-
+ static WeakReference<UIScrollView> s_scrollViewBeingScrolled;
UITableView _table;
public ContextScrollViewDelegate(UIView container, List<UIButton> buttons, bool isOpen)
@@ -72,6 +72,11 @@ namespace Xamarin.Forms.Platform.iOS
public override void DraggingStarted(UIScrollView scrollView)
{
+ if (ShouldIgnoreScrolling(scrollView))
+ return;
+
+ s_scrollViewBeingScrolled = new WeakReference<UIScrollView>(scrollView);
+
if (!IsOpen)
SetButtonsShowing(true);
@@ -90,6 +95,9 @@ namespace Xamarin.Forms.Platform.iOS
public override void Scrolled(UIScrollView scrollView)
{
+ if (ShouldIgnoreScrolling(scrollView))
+ return;
+
var width = _finalButtonSize;
var count = _buttons.Count;
@@ -116,10 +124,9 @@ namespace Xamarin.Forms.Platform.iOS
SetButtonsShowing(false);
RestoreHighlight(scrollView);
+ s_scrollViewBeingScrolled = null;
ClearCloserRecognizer(scrollView);
-
- if (ClosedCallback != null)
- ClosedCallback();
+ ClosedCallback?.Invoke();
}
}
@@ -131,6 +138,9 @@ namespace Xamarin.Forms.Platform.iOS
public override void WillEndDragging(UIScrollView scrollView, PointF velocity, ref PointF targetContentOffset)
{
+ if (ShouldIgnoreScrolling(scrollView))
+ return;
+
var width = ButtonsWidth;
var x = targetContentOffset.X;
var parentThreshold = scrollView.Frame.Width * .4f;
@@ -187,6 +197,19 @@ namespace Xamarin.Forms.Platform.iOS
}
}
+ static bool ShouldIgnoreScrolling(UIScrollView scrollView)
+ {
+ if (s_scrollViewBeingScrolled == null)
+ return false;
+
+ UIScrollView scrollViewBeingScrolled;
+ if (!s_scrollViewBeingScrolled.TryGetTarget(out scrollViewBeingScrolled) || ReferenceEquals(scrollViewBeingScrolled, scrollView))
+ return false;
+
+ scrollView.SetContentOffset(new PointF(0, 0), false);
+ return true;
+ }
+
protected override void Dispose(bool disposing)
{
if (_isDisposed)