Skip to content

Commit

Permalink
[Carousel] Fixed focus order when using keyboard navigation for hero …
Browse files Browse the repository at this point in the history
…carousels.

When using the keybaord to move between items, FocusFinder would occasionally skip an item because it was using the unmasked bounds of each item to compare their distance.

PiperOrigin-RevId: 572025177
  • Loading branch information
hunterstich authored and drchen committed Oct 10, 2023
1 parent ed4647d commit 0356f24
Showing 1 changed file with 10 additions and 4 deletions.
Expand Up @@ -19,6 +19,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.MotionEvent;
Expand Down Expand Up @@ -72,6 +73,11 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
}
}

@Override
public void getFocusedRect(Rect r) {
r.set((int) maskRect.left, (int) maskRect.top, (int) maskRect.right, (int) maskRect.bottom);
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
Expand Down Expand Up @@ -133,10 +139,10 @@ public void setMaskXPercentage(float percentage) {

private void updateMaskRectForMaskXPercentage() {
if (maskXPercentage != NOT_SET) {
// Translate the percentage into an actual pixel value of how much of this view should be
// masked away.
float maskWidth = AnimationUtils.lerp(0f, getWidth() / 2F, 0f, 1f, maskXPercentage);
setMaskRectF(new RectF(maskWidth, 0F, (getWidth() - maskWidth), getHeight()));
// Translate the percentage into an actual pixel value of how much of this view should be
// masked away.
float maskWidth = AnimationUtils.lerp(0f, getWidth() / 2F, 0f, 1f, maskXPercentage);
setMaskRectF(new RectF(maskWidth, 0F, (getWidth() - maskWidth), getHeight()));
}
}

Expand Down

0 comments on commit 0356f24

Please sign in to comment.