Пример #1
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (View == null)
            {
                SetMeasuredDimension(0, 0);
                return;
            }
            if (!View.IsVisible)
            {
                View.Measure(0, 0);
                SetMeasuredDimension(0, 0);
                return;
            }

            var width  = widthMeasureSpec.GetSize();
            var height = heightMeasureSpec.GetSize();

            var measureWidth  = width > 0 ? width : MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            var measureHeight = height > 0 ? height : MeasureSpecMode.Unspecified.MakeMeasureSpec(0);

            double?maxHeight = null;

            if (MeasureHeight)
            {
                measureHeight = MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            }
            else if (MatchWidth)
            {
                measureWidth = widthMeasureSpec;
            }
            else if (MatchHeight)
            {
                measureHeight = heightMeasureSpec;
                maxHeight     = heightMeasureSpec.GetSize();
            }

            var size = _shellContentView.Measure(measureWidth, measureHeight, null, (int?)maxHeight);

            SetMeasuredDimension((int)size.Width, (int)size.Height);
        }
Пример #2
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            if (View == null)
            {
                SetMeasuredDimension(0, 0);
                return;
            }
            if (!View.IsVisible)
            {
                View.Measure(0, 0);
                SetMeasuredDimension(0, 0);
                return;
            }

            var width  = widthMeasureSpec.GetSize();
            var height = heightMeasureSpec.GetSize();

            var measureWidth  = width > 0 ? MeasureSpecMode.Exactly.MakeMeasureSpec(width) : MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            var measureHeight = height > 0 ? MeasureSpecMode.Exactly.MakeMeasureSpec(height) : MeasureSpecMode.Unspecified.MakeMeasureSpec(0);

            double?maxHeight = null;

            if (MeasureHeight)
            {
                measureHeight = MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            }
            else if (MatchWidth)
            {
                measureWidth = widthMeasureSpec;
            }
            else if (MatchHeight)
            {
                measureHeight = heightMeasureSpec;
                maxHeight     = heightMeasureSpec.GetSize();
            }

            var size = _shellContentView.Measure(measureWidth, measureHeight, null, (int?)maxHeight);

            if (size.Height < this.MinimumHeight)
            {
                size = new Graphics.Size(size.Width, this.MinimumHeight);
            }

            DesiredSize = size;
            var newHeight = size.Height;

            if (_parentTopPadding > 0)
            {
                newHeight -= _parentTopPadding;
            }

            if (newHeight != size.Height)
            {
                // Android treats zero as unspecified so we need to set the height to at least 1.
                // If there's a view that's able to squish/stretch then passing in zero will give it's stretched size
                // but what we want here is the squished size.
                var minHeightMeasureSpec = 1;

                if (MinimumHeight > 0)
                {
                    minHeightMeasureSpec = MinimumHeight;
                }

                if (newHeight <= 0)
                {
                    newHeight = minHeightMeasureSpec;
                }

                // For collapse on scroll we need to know the minimum size the view can reach so we can set the minimum size
                // on the headers container. This is the only way to get the AppBarLayout collapse behavior to stop producing
                // offset changes once the header has reached the minimum size it can get to
                MinimumSize = _shellContentView.Measure(measureWidth, MeasureSpecMode.Exactly.MakeMeasureSpec(minHeightMeasureSpec), null, (int?)maxHeight);

                // If the offset of the appbar layout hasn't reached the minimum size then
                // we use the new collapsed size to remeasure so everything is the correct size
                if (newHeight > minHeightMeasureSpec)
                {
                    size = _shellContentView.Measure(measureWidth, MeasureSpecMode.Exactly.MakeMeasureSpec((int)newHeight), null, (int?)maxHeight);
                }
                else
                {
                    size = MinimumSize;
                }
            }
            else
            {
                this.MinimumSize = new Graphics.Size((int)size.Width, this.MinimumHeight);
            }

            SetMeasuredDimension((int)size.Width, (int)size.Height);
        }