Skip to content

Commit ebf27aa

Browse files
authored
Merge pull request #1512 from ichan-mb/fix_scrollview
Scrolling detect Improvement
2 parents 314eb6a + 2976e1f commit ebf27aa

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Source/Fuse.Controls.Native/Android/Java/FuseScrollView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ private void setupContainer() {
206206
_container = new android.widget.FrameLayout(com.fuse.Activity.getRootActivity());
207207
_container.setFocusable(true);
208208
_container.setFocusableInTouchMode(true);
209-
_container.setLayoutParams(new android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
209+
if (_currentScrollView instanceof VerticalScrollView)
210+
_container.setLayoutParams(new android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
211+
else
212+
_container.setLayoutParams(new android.widget.LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT));
210213
_currentScrollView.addView(_container);
211214
}
212215

Source/Fuse.Controls.Native/Android/Java/HorizontalScrollView.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
7373
if (this.mChildView == null && getChildCount() > 0 || mChildView != getChildAt(0)) {
7474
this.mChildView = getChildAt(0);
7575
}
76-
return super.onInterceptTouchEvent(ev);
76+
return super.onInterceptTouchEvent(ev) && isHorizontalScroll(ev);
77+
}
78+
79+
private boolean isHorizontalScroll(MotionEvent ev) {
80+
try {
81+
return Math.abs(ev.getX() - ev.getHistoricalX(0)) > Math.abs(ev.getY() - ev.getHistoricalY(0));
82+
} catch (IllegalArgumentException e) {
83+
return true;
84+
}
7785
}
7886

7987
@Override
@@ -125,7 +133,7 @@ public void onAnimationUpdate(@NonNull ValueAnimator animation) {
125133
break;
126134
}
127135

128-
return super.onTouchEvent(ev);
136+
return isHorizontalScroll(ev) && super.onTouchEvent(ev);
129137
}
130138

131139
private float calculateDamping() {

Source/Fuse.Controls.Native/Android/Java/VerticalScrollView.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
7474
if (this.mChildView == null && getChildCount() > 0 || mChildView != getChildAt(0)) {
7575
this.mChildView = getChildAt(0);
7676
}
77-
return super.onInterceptTouchEvent(ev);
77+
return super.onInterceptTouchEvent(ev) && isVerticalScroll(ev);
78+
}
79+
80+
private boolean isVerticalScroll(MotionEvent ev) {
81+
try {
82+
return Math.abs(ev.getX() - ev.getHistoricalX(0)) < Math.abs(ev.getY() - ev.getHistoricalY(0));
83+
} catch (IllegalArgumentException e) {
84+
return true;
85+
}
7886
}
7987

8088
@Override
@@ -126,7 +134,7 @@ public void onAnimationUpdate(@NonNull ValueAnimator animation) {
126134
break;
127135
}
128136

129-
return super.onTouchEvent(ev);
137+
return isVerticalScroll(ev) && super.onTouchEvent(ev);
130138
}
131139

132140
private float calculateDamping() {

0 commit comments

Comments
 (0)