Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using any touchId to scroll. Should help #9554. #9560

Merged
merged 1 commit into from Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/native/ui/viewgroup.cpp
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
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