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

Prevent scrollView to scroll with dpad when scrollEnabled property is set to false. #25309

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import androidx.core.view.ViewCompat;
import androidx.core.text.TextUtilsCompat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.FocusFinder;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -411,6 +412,16 @@ 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_LEFT ||
eventKeyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) {
return false;
}
return super.executeKeyEvent(event);
}

@Override
public void fling(int velocityX) {

Expand Down
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,16 @@ 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_UP ||
eventKeyCode == KeyEvent.KEYCODE_DPAD_DOWN)) {
return false;
}
return super.executeKeyEvent(event);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please properly format the code? The logical OR operator must be on the same line and the indentations are missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makovkastar I pushed the new modifications, please take a look and tell me if it's Ok for you now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makovkastar I updated to fit your last comments

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