Skip to content

Commit

Permalink
Fix snapping in Android horizontal tab switcher when reloading from c…
Browse files Browse the repository at this point in the history
…old start

We currently have a bug in the new horizontal tab switcher on Android where if
tabs get reloaded after a cold start, the snap distance is not set properly, so
the snapping behavior doesn't work properly. The fix is to update the snap
distance in NonOverlappingStack#notifySizeChanged() in addition to
contextChanged() (apparently when reloading tabs, contextChanged() is not called
again after the StackLayout's size is properly set).

Bug: 846961, 831359
Change-Id: I8c1be9f38889d6d1c45adefeb51af30d6a8bb4e3
Reviewed-on: https://chromium-review.googlesource.com/1081091
Reviewed-by: Matthew Jones <mdjones@chromium.org>
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#563647}(cherry picked from commit a73bfcd)
Reviewed-on: https://chromium-review.googlesource.com/1082852
Reviewed-by: Ryan Landay <rlanday@chromium.org>
Cr-Commit-Position: refs/branch-heads/3440@{#94}
Cr-Branched-From: 010ddcf-refs/heads/master@{#561733}
  • Loading branch information
rlanday committed Jun 1, 2018
1 parent 6089721 commit 2b5a634
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ protected boolean evenOutTabs(float amount, boolean allowReverseDirection) {
return false;
}

@Override
public void contextChanged(Context context) {
super.contextChanged(context);
private void updateScrollSnap() {
mScroller.setFrictionMultiplier(FRICTION_MULTIPLIER);
// This is what computeSpacing() returns when there are >= 2 tabs
final int snapDistance =
Expand All @@ -102,6 +100,18 @@ public void contextChanged(Context context) {
mScroller.setYSnapDistance(snapDistance);
}

@Override
public void contextChanged(Context context) {
super.contextChanged(context);
updateScrollSnap();
}

@Override
public void notifySizeChanged(float width, float height, int orientation) {
super.notifySizeChanged(width, height, orientation);
updateScrollSnap();
}

@Override
public void onPinch(long time, float x0, float y0, float x1, float y1, boolean firstEvent) {
return;
Expand Down

0 comments on commit 2b5a634

Please sign in to comment.