From f7da9204c13ad098bba18e36864eca7a60cf4f35 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 5 Apr 2017 09:57:26 +0200 Subject: [PATCH] Allow using any touchId to scroll. Should help #9554. --- ext/native/ui/viewgroup.cpp | 8 +++++--- ext/native/ui/viewgroup.h | 30 +++++++++++------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index bd7a25d8c59d..2c0e248599ff 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -734,25 +734,27 @@ const float friction = 0.92f; const float stop_threshold = 0.1f; void ScrollView::Touch(const TouchInput &input) { - if ((input.flags & TOUCH_DOWN) && input.id == 0) { + if ((input.flags & TOUCH_DOWN) && scrollTouchId_ == -1) { scrollStart_ = scrollPos_; inertia_ = 0.0f; + scrollTouchId_ = input.id; } Gesture gesture = orientation_ == ORIENT_VERTICAL ? GESTURE_DRAG_VERTICAL : GESTURE_DRAG_HORIZONTAL; - if (input.flags & TOUCH_UP) { + if ((input.flags & TOUCH_UP) && input.id == scrollTouchId_) { float info[4]; if (gesture_.GetGestureInfo(gesture, info)) { inertia_ = info[1]; } + scrollTouchId_ = -1; } TouchInput input2; if (CanScroll()) { input2 = gesture_.Update(input, bounds_); float info[4]; - if (gesture_.GetGestureInfo(gesture, info) && !(input.flags & TOUCH_DOWN)) { + if (gesture_.GetGestureInfo(gesture, info) && !(input.flags & TOUCH_DOWN) && input.id == scrollTouchId_) { float pos = scrollStart_ - info[0]; scrollPos_ = pos; scrollTarget_ = pos; diff --git a/ext/native/ui/viewgroup.h b/ext/native/ui/viewgroup.h index 8dcf49b57563..65d89a5a1ff4 100644 --- a/ext/native/ui/viewgroup.h +++ b/ext/native/ui/viewgroup.h @@ -222,17 +222,8 @@ class GridLayout : public ViewGroup { // A scrollview usually contains just a single child - a linear layout or similar. class ScrollView : public ViewGroup { public: - ScrollView(Orientation orientation, LayoutParams *layoutParams = 0) : - ViewGroup(layoutParams), - orientation_(orientation), - scrollPos_(0), - scrollStart_(0), - scrollTarget_(0), - scrollToTarget_(false), - inertia_(0.0f), - pull_(0.0f), - lastViewSize_(0.0f), - scrollToTopOnSizeChange_(false) {} + ScrollView(Orientation orientation, LayoutParams *layoutParams = 0) + : ViewGroup(layoutParams), orientation_(orientation) {} void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override; void Layout() override; @@ -261,14 +252,15 @@ class ScrollView : public ViewGroup { GestureDetector gesture_; Orientation orientation_; - float scrollPos_; - float scrollStart_; - float scrollTarget_; - bool scrollToTarget_; - float inertia_; - float pull_; - float lastViewSize_; - bool scrollToTopOnSizeChange_; + float scrollPos_ = 0.0f; + float scrollStart_ = 0.0f; + float scrollTarget_ = 0.0f; + int scrollTouchId_ = -1; + bool scrollToTarget_ = false; + float inertia_ = 0.0f; + float pull_ = 0.0f; + float lastViewSize_ = 0.0f; + bool scrollToTopOnSizeChange_ = false; }; class ViewPager : public ScrollView {