Skip to content

Commit

Permalink
Prevent scrollView to scroll with dpad when scrollEnabled property is…
Browse files Browse the repository at this point in the history
… set to false.
  • Loading branch information
aamalric committed Jun 19, 2019
1 parent a89e932 commit a150143
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.graphics.drawable.Drawable;
import androidx.core.view.ViewCompat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -300,6 +301,23 @@ public boolean onTouchEvent(MotionEvent ev) {
return super.onTouchEvent(ev);
}

@Override
public boolean executeKeyEvent(KeyEvent event) {
int eventKeyCode = event.getKeyCode();
if (!mScrollEnabled
&& (eventKeyCode == KeyEvent.KEYCODE_DPAD_DOWN
|| eventKeyCode == KeyEvent.KEYCODE_DPAD_DOWN_LEFT
|| eventKeyCode == KeyEvent.KEYCODE_DPAD_DOWN_RIGHT
|| eventKeyCode == KeyEvent.KEYCODE_DPAD_UP
|| eventKeyCode == KeyEvent.KEYCODE_DPAD_UP_LEFT
|| eventKeyCode == KeyEvent.KEYCODE_DPAD_UP_RIGHT
|| eventKeyCode == KeyEvent.KEYCODE_DPAD_LEFT
|| eventKeyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) {
return false;
}
return super.executeKeyEvent(event);
}

@Override
public void setRemoveClippedSubviews(boolean removeClippedSubviews) {
if (removeClippedSubviews && mClippingRect == null) {
Expand Down

0 comments on commit a150143

Please sign in to comment.