Skip to content

Commit

Permalink
Merge pull request #9560 from hrydgard/touch-scroll-fix
Browse files Browse the repository at this point in the history
Allow using any touchId to scroll. Should help #9554.
  • Loading branch information
hrydgard authored Apr 5, 2017
2 parents 9078323 + f7da920 commit cc8df3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
8 changes: 5 additions & 3 deletions ext/native/ui/viewgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 11 additions & 19 deletions ext/native/ui/viewgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cc8df3e

Please sign in to comment.