Skip to content

Commit 4434c2e

Browse files
zeyapfacebook-github-bot
authored andcommitted
Do not emit touchCancel at scroll if responderIgnoreScroll is disabled
Summary: ## Changelog: [Android] [Changed] - Do not emit touchCancel at scroll if responderIgnoreScroll is disabled Last change facebook#53951 added `responderIgnoreScroll` prop to ScrollView on android; here is native implementation Differential Revision: D82675049
1 parent 850ef67 commit 4434c2e

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,9 @@ && findDeepestScrollViewForMotionEvent(this, ev) != null) {
712712
}
713713

714714
protected void handleInterceptedTouchEvent(MotionEvent ev) {
715-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
715+
if (mResponderIgnoreScroll) {
716+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
717+
}
716718
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
717719
mDragging = true;
718720
enableFpsListener();
@@ -780,7 +782,9 @@ public boolean onTouchEvent(MotionEvent ev) {
780782
float velocityX = mVelocityHelper.getXVelocity();
781783
float velocityY = mVelocityHelper.getYVelocity();
782784
ReactScrollViewHelper.emitScrollEndDragEvent(this, velocityX, velocityY);
783-
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
785+
if (mResponderIgnoreScroll) {
786+
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
787+
}
784788
mDragging = false;
785789
// After the touch finishes, we may need to do some scrolling afterwards either as a result
786790
// of a fling or because we need to page align the content

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,9 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
595595
}
596596

597597
protected void handleInterceptedTouchEvent(MotionEvent ev) {
598-
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
598+
if (mResponderIgnoreScroll) {
599+
NativeGestureUtil.notifyNativeGestureStarted(this, ev);
600+
}
599601
ReactScrollViewHelper.emitScrollBeginDragEvent(this);
600602
mDragging = true;
601603
enableFpsListener();
@@ -621,7 +623,9 @@ public boolean onTouchEvent(MotionEvent ev) {
621623
float velocityX = mVelocityHelper.getXVelocity();
622624
float velocityY = mVelocityHelper.getYVelocity();
623625
ReactScrollViewHelper.emitScrollEndDragEvent(this, velocityX, velocityY);
624-
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
626+
if (mResponderIgnoreScroll) {
627+
NativeGestureUtil.notifyNativeGestureEnded(this, ev);
628+
}
625629
mDragging = false;
626630
// After the touch finishes, we may need to do some scrolling afterwards either as a result
627631
// of a fling or because we need to page align the content

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ public object ReactScrollViewHelper {
148148
contentView.height,
149149
scrollView.width,
150150
scrollView.height,
151+
if (scrollView is ReactScrollView)
152+
(scrollView as ReactScrollView).responderIgnoreScroll
153+
else if (scrollView is ReactHorizontalScrollView)
154+
(scrollView as ReactHorizontalScrollView).responderIgnoreScroll
155+
else true,
151156
)
152157
)
153158
if (scrollEventType == ScrollEventType.SCROLL) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ScrollEvent.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
3030
private var scrollViewHeight = 0
3131
private var scrollEventType: ScrollEventType? = null
3232
private var timestamp: Long = 0
33+
private var responderIgnoreScroll: Boolean = true
3334

3435
override fun onDispose() {
3536
try {
@@ -53,6 +54,7 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
5354
contentHeight: Int,
5455
scrollViewWidth: Int,
5556
scrollViewHeight: Int,
57+
responderIgnoreScroll: Boolean,
5658
) {
5759
val timestampMs = SystemClock.uptimeMillis()
5860
super.init(surfaceId, viewTag, timestampMs)
@@ -67,6 +69,7 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
6769
this.scrollViewWidth = scrollViewWidth
6870
this.scrollViewHeight = scrollViewHeight
6971
this.timestamp = timestampMs
72+
this.responderIgnoreScroll = responderIgnoreScroll
7073
}
7174

7275
override fun getEventName(): String =
@@ -110,7 +113,7 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
110113
event.putMap("velocity", velocity)
111114
event.putInt("target", viewTag)
112115
event.putDouble("timestamp", timestamp.toDouble())
113-
event.putBoolean("responderIgnoreScroll", true)
116+
event.putBoolean("responderIgnoreScroll", responderIgnoreScroll)
114117
return event
115118
}
116119

@@ -131,6 +134,7 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
131134
contentHeight: Int,
132135
scrollViewWidth: Int,
133136
scrollViewHeight: Int,
137+
responderIgnoreScroll: Boolean,
134138
): ScrollEvent =
135139
(EVENTS_POOL.acquire() ?: ScrollEvent()).apply {
136140
init(
@@ -145,13 +149,14 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
145149
contentHeight,
146150
scrollViewWidth,
147151
scrollViewHeight,
152+
responderIgnoreScroll,
148153
)
149154
}
150155

151156
@Deprecated(
152157
"Use the obtain version that explicitly takes surfaceId as an argument",
153158
ReplaceWith(
154-
"obtain(surfaceId, viewTag, scrollEventType, scrollX, scrollY, xVelocity, yVelocity, contentWidth, contentHeight, scrollViewWidth, scrollViewHeight)"
159+
"obtain(surfaceId, viewTag, scrollEventType, scrollX, scrollY, xVelocity, yVelocity, contentWidth, contentHeight, scrollViewWidth, scrollViewHeight, responderIgnoreScroll)"
155160
),
156161
)
157162
@JvmStatic
@@ -166,6 +171,7 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
166171
contentHeight: Int,
167172
scrollViewWidth: Int,
168173
scrollViewHeight: Int,
174+
responderIgnoreScroll: Boolean,
169175
): ScrollEvent =
170176
obtain(
171177
ViewUtil.NO_SURFACE_ID,
@@ -179,6 +185,7 @@ public class ScrollEvent private constructor() : Event<ScrollEvent>() {
179185
contentHeight,
180186
scrollViewWidth,
181187
scrollViewHeight,
188+
responderIgnoreScroll,
182189
)
183190
}
184191
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextScrollWatcher.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal class ReactTextScrollWatcher(private val editText: ReactEditText) : Scr
3939
0, // can't get content height
4040
editText.width,
4141
editText.height,
42+
true, // responderIgnoreScroll
4243
)
4344

4445
eventDispatcher?.dispatchEvent(event)

0 commit comments

Comments
 (0)