@@ -71,6 +71,8 @@ public class StackScrollAlgorithm {
7171 private int mBottomStackSlowDownLength ;
7272 private int mTopStackSlowDownLength ;
7373 private int mCollapseSecondCardPadding ;
74+ private boolean mIsSmallScreen ;
75+ private int mMaxNotificationHeight ;
7476
7577 public StackScrollAlgorithm (Context context ) {
7678 initConstants (context );
@@ -106,6 +108,8 @@ private void initConstants(Context context) {
106108 .getDimensionPixelSize (R .dimen .notification_padding );
107109 mCollapsedSize = context .getResources ()
108110 .getDimensionPixelSize (R .dimen .notification_min_height );
111+ mMaxNotificationHeight = context .getResources ()
112+ .getDimensionPixelSize (R .dimen .notification_max_height );
109113 mTopStackPeekSize = context .getResources ()
110114 .getDimensionPixelSize (R .dimen .top_stack_peek_amount );
111115 mBottomStackPeekSize = context .getResources ()
@@ -377,14 +381,17 @@ private void updatePositionsForState(StackScrollState resultState,
377381 // We are in the top Stack
378382 updateStateForTopStackChild (algorithmState ,
379383 numberOfElementsCompletelyIn , i , childHeight , childViewState , scrollOffset );
380- clampYTranslation (childViewState , childHeight );
384+ clampPositionToTopStackEnd (childViewState , childHeight );
385+
381386 // check if we are overlapping with the bottom stack
382387 if (childViewState .yTranslation + childHeight + mPaddingBetweenElements
383388 >= bottomStackStart && !mIsExpansionChanging && i != 0 ) {
384- // TODO: handle overlapping sizes with end stack better
385- // we just collapse this element
386- childViewState .height = mCollapsedSize ;
389+ // we just collapse this element slightly
390+ int newSize = (int ) Math .max (bottomStackStart - mPaddingBetweenElements -
391+ childViewState .yTranslation , mCollapsedSize );
392+ childViewState .height = newSize ;
387393 }
394+ clampPositionToBottomStackStart (childViewState , childViewState .height );
388395 } else if (nextYPosition >= bottomStackStart ) {
389396 // Case 2:
390397 // We are in the bottom stack.
@@ -489,11 +496,17 @@ private void updateStateForChildTransitioningInBottom(StackScrollAlgorithmState
489496 // the offset starting at the transitionPosition of the bottom stack
490497 float offset = mBottomStackIndentationFunctor .getValue (algorithmState .partialInBottom );
491498 algorithmState .itemsInBottomStack += algorithmState .partialInBottom ;
492- childViewState .yTranslation = transitioningPositionStart + offset - childHeight
499+ int newHeight = childHeight ;
500+ if (childHeight > mCollapsedSize && mIsSmallScreen ) {
501+ newHeight = (int ) Math .max (Math .min (transitioningPositionStart + offset -
502+ mPaddingBetweenElements - currentYPosition , childHeight ), mCollapsedSize );
503+ childViewState .height = newHeight ;
504+ }
505+ childViewState .yTranslation = transitioningPositionStart + offset - newHeight
493506 - mPaddingBetweenElements ;
494-
507+
495508 // We want at least to be at the end of the top stack when collapsing
496- clampPositionToTopStackEnd (childViewState , childHeight );
509+ clampPositionToTopStackEnd (childViewState , newHeight );
497510 childViewState .location = StackScrollState .ViewState .LOCATION_MAIN_AREA ;
498511 }
499512
@@ -705,6 +718,20 @@ private void updateInnerHeight() {
705718 mInnerHeight = mLayoutHeight - mTopPadding ;
706719 }
707720
721+
722+ /**
723+ * Update whether the device is very small, i.e. Notifications can be in both the top and the
724+ * bottom stack at the same time
725+ *
726+ * @param panelHeight The normal height of the panel when it's open
727+ */
728+ public void updateIsSmallScreen (int panelHeight ) {
729+ mIsSmallScreen = panelHeight <
730+ mCollapsedSize /* top stack */
731+ + mBottomStackSlowDownLength + mBottomStackPeekSize /* bottom stack */
732+ + mMaxNotificationHeight ; /* max notification height */
733+ }
734+
708735 public void onExpansionStarted (StackScrollState currentState ) {
709736 mIsExpansionChanging = true ;
710737 mExpandedOnStart = mIsExpanded ;
0 commit comments