Skip to content

Commit c38c78f

Browse files
aamalricM-i-k-e-l
authored andcommitted
Prevent scrollView to scroll with dpad when scrollEnabled property is set to false. (facebook#25309)
Summary: ScrollView doesn't handle the scrollEnabled property using dpad. When set to false, the directionnal pad still allows to scroll in the view. ## Changelog [ANDROID] [ADDED] - Prevent scrollView to scroll with dpad when scrollEnabled property is set to false. Pull Request resolved: facebook#25309 Test Plan: Add P67680731 to Playground.js and start the Catalyst Android app: ```buck install -r catalyst``` Send the following adb commands to the device/emulator: ```adb shell input keyevent DPAD_RIGHT_LEFT``` ```adb shell input keyevent DPAD_RIGHT_RIGHT``` Make sure the ScrollView doesn't scroll to the left and right. Add ```horizontal={true}``` to ScrollView and send the following adb commands to the device/emulator: ```adb shell input keyevent DPAD_RIGHT_TOP``` ```adb shell input keyevent DPAD_RIGHT_BOTTOM``` Make sure the ScrollView doesn't scroll to the top and bottom. Reviewed By: mdvacca Differential Revision: D15983785 Pulled By: makovkastar fbshipit-source-id: 678cc801a168531d71c8651b986c99ecd9da400e
1 parent c54c149 commit c38c78f

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import androidx.core.view.ViewCompat;
1919
import androidx.core.text.TextUtilsCompat;
2020
import android.util.Log;
21+
import android.view.KeyEvent;
2122
import android.view.FocusFinder;
2223
import android.view.MotionEvent;
2324
import android.view.View;
@@ -411,6 +412,16 @@ public boolean onTouchEvent(MotionEvent ev) {
411412
return super.onTouchEvent(ev);
412413
}
413414

415+
@Override
416+
public boolean executeKeyEvent(KeyEvent event) {
417+
int eventKeyCode = event.getKeyCode();
418+
if (!mScrollEnabled && (eventKeyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
419+
eventKeyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) {
420+
return false;
421+
}
422+
return super.executeKeyEvent(event);
423+
}
424+
414425
@Override
415426
public void fling(int velocityX) {
416427

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.graphics.drawable.Drawable;
1515
import androidx.core.view.ViewCompat;
1616
import android.util.Log;
17+
import android.view.KeyEvent;
1718
import android.view.MotionEvent;
1819
import android.view.View;
1920
import android.view.ViewGroup;
@@ -300,6 +301,16 @@ public boolean onTouchEvent(MotionEvent ev) {
300301
return super.onTouchEvent(ev);
301302
}
302303

304+
@Override
305+
public boolean executeKeyEvent(KeyEvent event) {
306+
int eventKeyCode = event.getKeyCode();
307+
if (!mScrollEnabled && (eventKeyCode == KeyEvent.KEYCODE_DPAD_UP ||
308+
eventKeyCode == KeyEvent.KEYCODE_DPAD_DOWN)) {
309+
return false;
310+
}
311+
return super.executeKeyEvent(event);
312+
}
313+
303314
@Override
304315
public void setRemoveClippedSubviews(boolean removeClippedSubviews) {
305316
if (removeClippedSubviews && mClippingRect == null) {

0 commit comments

Comments
 (0)