示例#1
0
            public override bool TryCaptureView(View child, int pointerId)
            {
                if (mBehavior.mState == STATE_DRAGGING)
                {
                    return(false);
                }
                if (mBehavior.mTouchingScrollingChild)
                {
                    return(false);
                }
                if (mBehavior.mState == STATE_EXPANDED && mBehavior.mActivePointerId == pointerId)
                {
                    View scroll;
                    if (mBehavior.mNestedScrollingChildRef.TryGetTarget(out scroll) &&
                        ViewCompat.CanScrollVertically(scroll, -1))
                    {
                        // Let the content scroll up
                        return(false);
                    }
                }

                View currentChild;

                return(mBehavior.mViewRef != null &&
                       mBehavior.mViewRef.TryGetTarget(out currentChild) &&
                       currentChild == child);
            }
示例#2
0
        /**
         * Sets the state of the bottom sheet. The bottom sheet will transition to that state with
         * animation.
         *
         * @param state One of {@link #STATE_COLLAPSED}, {@link #STATE_EXPANDED}, or
         *              {@link #STATE_HIDDEN}.
         */
        public void setState(int state)
        {
            Debug.WriteLineIf(DebugTrace, $"setState {(AnchorBottomSheetState)state}");
            if (state == mState)
            {
                return;
            }

            if (mViewRef == null)
            {
                // The view is not laid out yet; modify mState and let onLayoutChild handle it later
                if (state == STATE_COLLAPSED || state == STATE_EXPANDED || state == STATE_ANCHOR ||
                    (mHideable && state == STATE_HIDDEN))
                {
                    mState = state;
                }
                return;
            }

            View child;

            if (!mViewRef.TryGetTarget(out child))
            {
                return;
            }

            int top;

            if (state == STATE_COLLAPSED)
            {
                top = mMaxOffset;
                View scroll;
                if (mNestedScrollingChildRef.TryGetTarget(out scroll) && ViewCompat.CanScrollVertically(scroll, -1))
                {
                    scroll.ScrollTo(0, 0);
                }
            }
            else if (state == STATE_EXPANDED)
            {
                top = mMinOffset;
            }
            else if (state == STATE_ANCHOR)
            {
                top = mAnchorOffset;
            }
            else if (mHideable && state == STATE_HIDDEN)
            {
                top = mParentHeight;
            }
            else
            {
                throw new ArgumentException("Illegal state argument: " + state, nameof(state));
            }
            setStateInternal(STATE_SETTLING);
            if (mViewDragHelper.SmoothSlideViewTo(child, child.Left, top))
            {
                ViewCompat.PostOnAnimation(child, this.CreateSettleRunnable(child, state));
            }
        }
示例#3
0
            public override bool CanChildScrollUp()
            {
                var listView = listFragment.ListView;

                if (listView != null && listView.Visibility == ViewStates.Visible)
                {
                    return(ViewCompat.CanScrollVertically(listView, -1));
                }
                return(false);
            }
示例#4
0
 /**
  * @return Whether it is possible for the child view of this layout to
  *         scroll up. Override this if the child view is a custom view.
  */
 public bool canChildScrollUp()
 {
     //        //For make it can work when my recycler view is in Gone.
     //        return false;
     if (Build.VERSION.SdkInt < BuildVersionCodes.IceCreamSandwich)
     {// 14
         if (mTarget is AbsListView)
         {
             AbsListView absListView = (AbsListView)mTarget;
             return(absListView.ChildCount > 0 &&
                    (absListView.FirstVisiblePosition > 0 || absListView.GetChildAt(0)
                     .Top < absListView.PaddingTop));
         }
         else
         {
             return(ViewCompat.CanScrollVertically(mTarget, -1) || mTarget.ScrollY > 0);
         }
     }
     else
     {
         return(ViewCompat.CanScrollVertically(mTarget, -1));
     }
 }
 /**
  * Utility method to check whether a {@link ListView} can scroll up from it's current position.
  * Handles platform version differences, providing backwards compatible functionality where
  * needed.
  */
 private static bool CanListViewScrollUp(ListView listView)
 {
     return(ViewCompat.CanScrollVertically(listView, -1));
 }
 // The current SwipeRefreshLayout only check its immediate child scrollability.
 // In our case, ListFragment uses a ListView inside a parent FrameLayout which breaks this.
 public override bool CanChildScrollUp()
 {
     return(GetChildrenRecursively(GetChildAt(0)).Any(v => ViewCompat.CanScrollVertically(v, -1)));
 }
示例#7
0
        public override void OnNestedPreScroll(
            CoordinatorLayout coordinatorLayout,
            Java.Lang.Object childObject,
            View target,
            int dx,
            int dy,
            int[] consumed)
        {
            Debug.WriteLineIf(DebugTrace, $"OnNestedPreScroll");
            View child = Android.Runtime.Extensions.JavaCast <View>(childObject);

            View scrollingChild;

            mNestedScrollingChildRef.TryGetTarget(out scrollingChild);
            if (target != scrollingChild)
            {
                return;
            }

            int currentTop = child.Top;
            int newTop     = currentTop - dy;

            Debug.WriteLineIf(DebugTrace, $"currentTop:{currentTop} newTop:{newTop}");
            if (dy > 0)
            {             // Upward
                Debug.WriteLineIf(DebugTrace, $"dy > 0: Upward");
                if (newTop < mMinOffset)
                {
                    Debug.WriteLineIf(DebugTrace, $"newTop < mMinOffset: STATE_EXPANDED");
                    consumed[1] = currentTop - mMinOffset;
                    ViewCompat.OffsetTopAndBottom(child, -consumed[1]);
                    setStateInternal(STATE_EXPANDED);
                }
                else
                {
                    Debug.WriteLineIf(DebugTrace, $"else: STATE_DRAGGING");
                    consumed[1] = dy;
                    ViewCompat.OffsetTopAndBottom(child, -dy);
                    setStateInternal(STATE_DRAGGING);
                }
            }
            else if (dy < 0)
            {
                // Downward
                Debug.WriteLineIf(DebugTrace, $"dy < 0: Downward");
                if (!ViewCompat.CanScrollVertically(target, -1))
                {
                    if (newTop <= mMaxOffset || mHideable)
                    {
                        Debug.WriteLineIf(DebugTrace, $"newTop <= mMaxOffset || mHideable: STATE_DRAGGING");
                        consumed[1] = dy;
                        ViewCompat.OffsetTopAndBottom(child, -dy);
                        setStateInternal(STATE_DRAGGING);
                    }
                    else
                    {
                        Debug.WriteLineIf(DebugTrace, $"else: STATE_COLLAPSED");
                        consumed[1] = currentTop - mMaxOffset;
                        ViewCompat.OffsetTopAndBottom(child, -consumed[1]);
                        setStateInternal(STATE_COLLAPSED);
                    }
                }
            }

            dispatchOnSlide(child.Top);
            mLastNestedScrollDy = dy;
            mNestedScrolled     = true;
        }
        public override void OnNestedPreScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object cChild, View target, int dx, int dy, int[] consumed, int type)
        {
            var child = cChild.JavaCast <View>();

            _nestedScrollingChildRef.TryGetTarget(out View scrollingChild);
            if (target != scrollingChild)
            {
                return;
            }

            _scrollVelocityTracker.RecordScroll(dy);

            int currentTop = child.Top;
            int newTop     = currentTop - dy;

            // Force stop at the anchor - do not go from collapsed to expanded in one scroll
            if ((_lastStableState == StateCollapsed && newTop < AnchorPoint) ||
                (_lastStableState == StateExpanded && newTop > AnchorPoint))
            {
                consumed[1] = dy;
                ViewCompat.OffsetTopAndBottom(child, AnchorPoint - currentTop);
                DispatchOnSlide(child.Top);
                _nestedScrolled = true;
                return;
            }

            if (dy > 0)
            { // Upward
                if (newTop < _minOffset)
                {
                    consumed[1] = currentTop - _minOffset;
                    ViewCompat.OffsetTopAndBottom(child, -consumed[1]);
                    SetStateInternal(StateExpanded);
                }
                else
                {
                    consumed[1] = dy;
                    ViewCompat.OffsetTopAndBottom(child, -dy);
                    SetStateInternal(StateDragging);
                }
            }
            else if (dy < 0)
            { // Downward
                if (!ViewCompat.CanScrollVertically(target, -1))
                {
                    if (newTop <= _maxOffset || Hideable)
                    {
                        // Restrict STATE_COLLAPSED if restrictedState is set
                        if (Collapsible == true || (Collapsible == false && (AnchorPoint - newTop) >= 0))
                        {
                            consumed[1] = dy;
                            ViewCompat.OffsetTopAndBottom(child, -dy);
                            SetStateInternal(StateDragging);
                        }
                    }
                    else
                    {
                        consumed[1] = currentTop - _maxOffset;
                        ViewCompat.OffsetTopAndBottom(child, -consumed[1]);
                        SetStateInternal(StateCollapsed);
                    }
                }
            }
            DispatchOnSlide(child.Top);
            _nestedScrolled = true;
        }