Skip to content

Commit fdaff78

Browse files
imhappileticiarossi
authored andcommitted
[TopAppBar] Removing keyboard scroll event workaround for AppBarLayout since CoordinatorLayout issue has been fixed in androidx.core:core:1.10.0
Resolves #2249 PiperOrigin-RevId: 525775019
1 parent 3b2b827 commit fdaff78

File tree

1 file changed

+0
-49
lines changed

1 file changed

+0
-49
lines changed

lib/java/com/google/android/material/appbar/AppBarLayout.java

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import android.os.Parcelable;
4343
import androidx.appcompat.content.res.AppCompatResources;
4444
import android.util.AttributeSet;
45-
import android.view.KeyEvent;
4645
import android.view.View;
4746
import android.view.ViewGroup;
4847
import android.view.ViewOutlineProvider;
@@ -1445,7 +1444,6 @@ public Behavior(Context context, AttributeSet attrs) {
14451444
// TODO(b/76413401): remove this base class and generic type after the widget migration is done
14461445
protected static class BaseBehavior<T extends AppBarLayout> extends HeaderBehavior<T> {
14471446
private static final int MAX_OFFSET_ANIMATION_DURATION = 600; // ms
1448-
private static final double EXPAND_BY_KEY_EVENT_THRESHOLD_PERCENTAGE = 0.1;
14491447

14501448
/** Callback to allow control over any {@link AppBarLayout} dragging. */
14511449
// TODO(b/76413401): remove this base class and generic type after the widget migration
@@ -1827,56 +1825,9 @@ public boolean onLayoutChild(
18271825
abl.onOffsetChanged(getTopAndBottomOffset());
18281826

18291827
updateAccessibilityActions(parent, abl);
1830-
// TODO(b/243555083): Until CoordinatorLayout fixes triggering scroll events with physical
1831-
// keyboard scrolling, we have this hack in place.
1832-
View v = findFirstScrollingChild(parent);
1833-
if (v != null) {
1834-
if (VERSION.SDK_INT >= VERSION_CODES.P) {
1835-
v.addOnUnhandledKeyEventListener(
1836-
(v1, event) -> {
1837-
controlExpansionOnKeyPress(event, v, abl);
1838-
return false;
1839-
});
1840-
} else {
1841-
// Unfortunately if not using >= API 28, we don't have access to the unhandled key event
1842-
// handler. Using setOnKeyListener is less ideal since it will replace any listener
1843-
// already on the scrollable child. Furthermore, the 'scrolling' may be occurring due to
1844-
// switching focus between children of the scrollable child, which will not trigger this
1845-
// listener.
1846-
v.setOnKeyListener(
1847-
(v1, keyCode, event) -> {
1848-
controlExpansionOnKeyPress(event, v, abl);
1849-
return false;
1850-
});
1851-
}
1852-
}
18531828
return handled;
18541829
}
18551830

1856-
// TODO(b/243555083): Until CoordinatorLayout fixes triggering scroll events with physical
1857-
// keyboard scrolling, we have this hack in place.
1858-
private void controlExpansionOnKeyPress(
1859-
KeyEvent event, View scrollableChild, AppBarLayout abl) {
1860-
if (event.getAction() == KeyEvent.ACTION_DOWN || event.getAction() == KeyEvent.ACTION_UP) {
1861-
int keyCode = event.getKeyCode();
1862-
if (keyCode == KeyEvent.KEYCODE_DPAD_UP
1863-
|| keyCode == KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP
1864-
|| keyCode == KeyEvent.KEYCODE_PAGE_UP) {
1865-
// If within height threshold, we expand.
1866-
if (scrollableChild.getScrollY()
1867-
< scrollableChild.getMeasuredHeight() * EXPAND_BY_KEY_EVENT_THRESHOLD_PERCENTAGE) {
1868-
abl.setExpanded(true);
1869-
}
1870-
} else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN
1871-
|| keyCode == KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN
1872-
|| keyCode == KeyEvent.KEYCODE_PAGE_DOWN) {
1873-
if (scrollableChild.getScrollY() > 0) {
1874-
abl.setExpanded(false);
1875-
}
1876-
}
1877-
}
1878-
}
1879-
18801831
private void updateAccessibilityActions(
18811832
CoordinatorLayout coordinatorLayout, @NonNull T appBarLayout) {
18821833
ViewCompat.removeAccessibilityAction(coordinatorLayout, ACTION_SCROLL_FORWARD.getId());

0 commit comments

Comments
 (0)