Skip to content

Commit

Permalink
When drawer opens, always place focus at it's start
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-- committed Apr 12, 2020
1 parent 54ceb85 commit 850f51a
Showing 1 changed file with 1 addition and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import java.util.ArrayList;
Expand Down Expand Up @@ -111,28 +108,6 @@ public void addFocusables(final ArrayList<View> views, final int direction,
public void openDrawer(@NonNull final View drawerView, final boolean animate) {
super.openDrawer(drawerView, animate);

LayoutParams params = (LayoutParams) drawerView.getLayoutParams();

int gravity = GravityCompat.getAbsoluteGravity(
params.gravity, ViewCompat.getLayoutDirection(this));

int direction = 0;

switch (gravity) {
case Gravity.LEFT:
direction = FOCUS_LEFT;
break;
case Gravity.RIGHT:
direction = FOCUS_RIGHT;
break;
case Gravity.TOP:
direction = FOCUS_UP;
break;
case Gravity.BOTTOM:
direction = FOCUS_DOWN;
break;
}

drawerView.requestFocus(direction);
drawerView.requestFocus(FOCUS_FORWARD);
}
}

0 comments on commit 850f51a

Please sign in to comment.