public override bool OnLayoutChild(CoordinatorLayout parent, Java.Lang.Object cChild, int layoutDirection) { // return base.OnLayoutChild(parent, child, layoutDirection); var child = cChild.JavaCast <View>(); // First let the parent lay it out if (_state != StateDragging && _state != StateSettling) { if (parent.FitsSystemWindows && !child.FitsSystemWindows) { child.SetFitsSystemWindows(true); } parent.OnLayoutChild(child, layoutDirection); } // Offset the bottom sheet _parentHeight = parent.Height; _minOffset = System.Math.Max(0, _parentHeight - child.Height); _maxOffset = System.Math.Max(_parentHeight - _peekHeight, _minOffset); /** * New behavior */ switch (_state) { case StateAnchorPoint: ViewCompat.OffsetTopAndBottom(child, AnchorPoint); break; case StateExpanded: ViewCompat.OffsetTopAndBottom(child, _minOffset); break; case StateHidden: if (Hideable) { ViewCompat.OffsetTopAndBottom(child, _parentHeight); } break; case StateCollapsed: ViewCompat.OffsetTopAndBottom(child, _maxOffset); break; } ; if (_viewDragHelper == null) { _viewDragHelper = ViewDragHelper.Create(parent, _dragCallback); } _viewRef = new WeakReference <View>(child); _nestedScrollingChildRef = new WeakReference <View>(FindScrollingChild(child)); return(true); }
public override bool OnLayoutChild( CoordinatorLayout parent, Java.Lang.Object childObject, int layoutDirection) { Debug.WriteLineIf(DebugTrace, $"OnLayoutChild"); View child = Android.Runtime.Extensions.JavaCast <View>(childObject); if (ViewCompat.GetFitsSystemWindows(parent) && !ViewCompat.GetFitsSystemWindows(child)) { ViewCompat.SetFitsSystemWindows(child, true); } int savedTop = child.Top; // First let the parent lay it out parent.OnLayoutChild(child, layoutDirection); // Offset the bottom sheet mParentHeight = parent.Height; mMinOffset = Math.Max(0, mParentHeight - child.Height); mMaxOffset = Math.Max(mParentHeight - mPeekHeight, mMinOffset); mAnchorOffset = (int)Math.Max(mParentHeight * mAnchorThreshold, mMinOffset); Debug.WriteLineIf(DebugTrace, $"offset computed => savedTop:{savedTop} mMinOffset:{mMinOffset} mMaxOffset:{mMaxOffset} mAnchorOffset:{mAnchorOffset} "); if (mState == STATE_EXPANDED) { ViewCompat.OffsetTopAndBottom(child, mMinOffset); } else if (mState == STATE_ANCHOR) { ViewCompat.OffsetTopAndBottom(child, mAnchorOffset); } else if (mHideable && mState == STATE_HIDDEN) { ViewCompat.OffsetTopAndBottom(child, mParentHeight); } else if (mState == STATE_COLLAPSED) { ViewCompat.OffsetTopAndBottom(child, mMaxOffset); } else if (mState == STATE_DRAGGING || mState == STATE_SETTLING) { ViewCompat.OffsetTopAndBottom(child, savedTop - child.Top); } if (mViewDragHelper == null || mViewDragHelper.Handle == IntPtr.Zero) { mViewDragHelper = ViewDragHelper.Create(parent, mDragCallback); } mViewRef = new WeakReference <View>(child); mNestedScrollingChildRef = new WeakReference <View>(findScrollingChild(child)); return(true); }
public override bool OnLayoutChild(CoordinatorLayout parent, Java.Lang.Object child, int layoutDirection) { if (!(child is NestedScrollView view)) { return(base.OnLayoutChild(parent, child, layoutDirection)); } // First layout the child as normal. parent.OnLayoutChild(view, layoutDirection); // Center the FAB vertically along the top edge of the card. int fabHalfHeight = view.FindViewById(Resource.Id.fab).Height / 2; SetTopMargin(view.FindViewById(Resource.Id.cardview), fabHalfHeight); // Give the RecyclerView a maximum height to ensure the card will never // overlap the toolbar as it scrolls. int rvMaxHeight = view.Height - fabHalfHeight - view.FindViewById(Resource.Id.card_title).Height - view.FindViewById(Resource.Id.card_subtitle).Height; MaxHeightRecyclerView rv = view.FindViewById <MaxHeightRecyclerView>(Resource.Id.card_recyclerview); rv.SetMaxHeight(rvMaxHeight); // Give the card container top padding so that only the top edge of the card // initially appears at the bottom of the screen. The total padding will // be the distance from the top of the screen to the FAB's top edge. View cardContainer = view.FindViewById(Resource.Id.card_container); int toolbarContainerHeight = parent.GetDependencies(view)[0].Height; SetPaddingTop(cardContainer, rvMaxHeight - toolbarContainerHeight); // Offset the child's height so that its bounds don't overlap the // toolbar container. ViewCompat.OffsetTopAndBottom(view, toolbarContainerHeight); // Add the same amount of bottom padding to the RecyclerView so it doesn't // display its content underneath the navigation bar. SetPaddingBottom(rv, toolbarContainerHeight); // Return true so that the parent doesn't waste time laying out the // child again (any modifications made above will have triggered a second // layout pass anyway). return(true); }