コード例 #1
0
        /// <summary>
        /// Adjusts the size of the view when the user pans (if <see cref="AllowsManualResize"/> is <value>true</value>).
        /// </summary>
        /// <param name="recognizer">Gesture recognizer that is handling user interaction.</param>
        private void HandleMoveView(UIPanGestureRecognizer recognizer)
        {
            // Do nothing if user resize isn't enabled
            if (!AllowsManualResize)
            {
                return;
            }

            // Get the distance moved
            var translation = recognizer.TranslationInView(View);

            // In compact width scrolling up (negative translation) increases height as the card moves up
            if (TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular)
            {
                // translate height constraint
                _heightConstraint.Constant += translation.Y;
            }
            else
            {
                // translate height constraint
                _heightConstraint.Constant -= translation.Y;
            }

            // Prevent making the view too large
            if (_heightConstraint.Constant > MaxHeightConstraint)
            {
                _heightConstraint.Constant = MaxHeightConstraint;
            }

            // Prevent making the view too small
            if (_heightConstraint.Constant < MinimumHeight)
            {
                _heightConstraint.Constant = MinimumHeight;
            }

            // Enables 'flick' gesture to switch between states
            if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                if (Math.Abs(recognizer.VelocityInView(View).Y) > 0)
                {
                    HandleFlick(recognizer);
                }

                if (_heightConstraint.Constant == MinimumHeight && AllowsMinimizedState)
                {
                    _currentState = BottomSheetState.Minimized;
                }
                else if (_heightConstraint.Constant == MaxHeightConstraint)
                {
                    _currentState = BottomSheetState.Full;
                }
                else
                {
                    _currentState = BottomSheetState.Partial;
                }
            }

            recognizer.SetTranslation(new CoreGraphics.CGPoint(0, 0), View);
        }
コード例 #2
0
        /// <summary>
        /// Layout the bottom sheet to its collapsed state, with animation.
        /// </summary>
        /// <returns>The task.</returns>
        private async Task CollapseBottomSheet()
        {
            var bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top  = Height - bottomSheetSize,
                Size = new Size(Width, bottomSheetSize)
            };
            var buttonRect = new Rectangle
            {
                Top  = bottomSheetRect.Top - Button.Height / 2,
                Size = new Size(Button.Width, Button.Height),
                X    = Button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), Button.LayoutTo(buttonRect), Button.RotateXTo(0));

            bottomSheetState = BottomSheetState.Collapsed;
        }
コード例 #3
0
        /// <summary>
        /// Layout the bottom sheet to its extended state, with animation.
        /// </summary>
        /// <returns>The task.</returns>
        private async Task ExtendBottomSheet()
        {
            var bottomSheetRect = new Rectangle
            {
                Left = 0,
                Top  = Height * (1 - bottomSheetExtensionFraction),
                Size = new Size(Width, Height * bottomSheetExtensionFraction)
            };
            var buttonRect = new Rectangle
            {
                Top  = bottomSheetRect.Top - Button.Height / 2,
                Size = new Size(Button.Width, Button.Height),
                X    = Button.X
            };
            await Task.WhenAll(BottomSheetContentView.LayoutTo(bottomSheetRect), Button.LayoutTo(buttonRect), Button.RotateXTo(180));

            bottomSheetState = BottomSheetState.Extended;
        }
コード例 #4
0
        /// <summary>
        /// Sets the bottom sheet state and updates the height of the sheet as needed.
        /// </summary>
        /// <param name="state"></param>
        public void SetState(BottomSheetState state)
        {
            _currentState = state;
            if (_heightConstraint == null)
            {
                return;
            }
            switch (state)
            {
            case BottomSheetState.Partial:
                _heightConstraint.Constant = GetPartialHeight();
                break;

            case BottomSheetState.Minimized:
                _heightConstraint.Constant = MinimumHeight;
                break;

            case BottomSheetState.Full:
                _heightConstraint.Constant = MaxHeightConstraint;
                break;
            }
        }