Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java

Issue 2759823002: 🏠 Separate bottom sheet current from target state (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java
index 6549ec5fe1feca81f3b860b7d38edc3b3ba23241..b28dab022c8584e84b621b05de66014e8719c51b 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/bottomsheet/BottomSheet.java
@@ -52,12 +52,13 @@ import java.lang.annotation.RetentionPolicy;
public class BottomSheet
extends FrameLayout implements FadingBackgroundView.FadingViewObserver, NativePageHost {
/** The different states that the bottom sheet can have. */
- @IntDef({SHEET_STATE_PEEK, SHEET_STATE_HALF, SHEET_STATE_FULL})
+ @IntDef({SHEET_STATE_PEEK, SHEET_STATE_HALF, SHEET_STATE_FULL, SHEET_STATE_SCROLLING})
@Retention(RetentionPolicy.SOURCE)
public @interface SheetState {}
public static final int SHEET_STATE_PEEK = 0;
public static final int SHEET_STATE_HALF = 1;
public static final int SHEET_STATE_FULL = 2;
+ public static final int SHEET_STATE_SCROLLING = 3;
/**
* The base duration of the settling animation of the sheet. 218 ms is a spec for material
@@ -112,9 +113,12 @@ public class BottomSheet
/** The height of the view that contains the bottom sheet. */
private float mContainerHeight;
- /** The current sheet state. If the sheet is moving, this will be the target state. */
+ /** The current state that the sheet is in. */
private int mCurrentState;
+ /** The target sheet state. This is the state that the sheet is currently moving to. */
+ private int mTargetState;
+
/** Used for getting the current tab. */
private TabModelSelector mTabModelSelector;
@@ -238,6 +242,7 @@ public class BottomSheet
float newOffset = getSheetOffsetFromBottom() + distanceY;
setSheetOffsetFromBottom(MathUtils.clamp(newOffset, getMinOffset(), getMaxOffset()));
+ setInternalCurrentState(SHEET_STATE_SCROLLING);
mIsScrolling = true;
return true;
}
@@ -359,7 +364,7 @@ public class BottomSheet
mBottomSheetContentContainer = (FrameLayout) findViewById(R.id.bottom_sheet_content);
- mCurrentState = SHEET_STATE_PEEK;
+ setInternalCurrentState(SHEET_STATE_SCROLLING);
Theresa 2017/03/17 23:36:19 I would have expected this to stay SHEET_STATE_PEE
mdjones 2017/03/20 16:09:16 Whoops, definitely a mistake. Fixed.
// Listen to height changes on the root.
root.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@@ -376,7 +381,7 @@ public class BottomSheet
updateSheetDimensions();
cancelAnimation();
- setSheetState(mCurrentState, false);
+ setSheetState(mTargetState, false);
}
});
@@ -394,7 +399,7 @@ public class BottomSheet
updateSheetDimensions();
cancelAnimation();
- setSheetState(mCurrentState, false);
+ setSheetState(mTargetState, false);
}
});
@@ -587,7 +592,7 @@ public class BottomSheet
* @param targetState The target state.
*/
private void createSettleAnimation(@SheetState int targetState) {
- mCurrentState = targetState;
+ mTargetState = targetState;
mSettleAnimator = ValueAnimator.ofFloat(
getSheetOffsetFromBottom(), getSheetHeightForState(targetState));
mSettleAnimator.setDuration(BASE_ANIMATION_DURATION_MS);
@@ -598,6 +603,7 @@ public class BottomSheet
@Override
public void onAnimationEnd(Animator animator) {
mSettleAnimator = null;
+ setInternalCurrentState(mTargetState);
}
});
@@ -609,6 +615,7 @@ public class BottomSheet
});
mSettleAnimator.start();
+ setInternalCurrentState(SHEET_STATE_SCROLLING);
}
/**
@@ -728,12 +735,15 @@ public class BottomSheet
* move there instantly.
*/
public void setSheetState(@SheetState int state, boolean animate) {
- mCurrentState = state;
+ assert state != SHEET_STATE_SCROLLING;
+
+ mTargetState = state;
if (animate) {
createSettleAnimation(state);
} else {
setSheetOffsetFromBottom(getSheetHeightForState(state));
+ setInternalCurrentState(mTargetState);
}
}
@@ -746,6 +756,16 @@ public class BottomSheet
}
/**
+ * Set the current state of the bottom sheet. This is for internal use to notify observers of
+ * state change events.
+ * @param state The current state of the sheet.
+ */
+ private void setInternalCurrentState(@SheetState int state) {
+ // TODO(mdjones): Trigger onSheetStateChanged here.
+ mCurrentState = state;
+ }
+
+ /**
* If the animation to settle the sheet in one of its states is running.
* @return True if the animation is running.
*/
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698