Пример #1
0
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

            var availableSize = ViewHelper.LogicalSizeFromSpec(widthMeasureSpec, heightMeasureSpec);

            var measuredSize = _layouter.Measure(availableSize);

            if (
                !double.IsInfinity(availableSize.Width) &&
                !double.IsInfinity(availableSize.Height)
                )
            {
                measuredSize = this.AdjustSize(availableSize, measuredSize);
            }

            var physicalMeasuredSize = measuredSize
                                       .LogicalToPhysicalPixels();

            // Report our final dimensions.
            var width  = (int)physicalMeasuredSize.Width;
            var height = (int)physicalMeasuredSize.Height;

            SetMeasuredDimension(width, height);

            IFrameworkElementHelper
            .SizeThatFits(this, new Size(width, height).PhysicalToLogicalPixels());
        }
Пример #2
0
        public override CGSize SizeThatFits(CGSize size)
        {
            size = IFrameworkElementHelper.SizeThatFits(this, size);

            size = _layouter.Measure(size.ToFoundationSize());

            return(size);
        }
Пример #3
0
        public override CGSize SizeThatFits(CGSize size)
        {
            var hasSameDesiredSize =
                !_measureInvalidated &&
                _previousAvailableSize != null &&
                _previousDesiredSize.Width == size.Width &&
                _previousDesiredSize.Height == size.Height;

            var isSingleLineNarrower =
                !_measureInvalidated &&
                _previousAvailableSize != null &&
                _previousDesiredSize.Width <= size.Width &&
                _previousDesiredSize.Height == size.Height;

            if (hasSameDesiredSize || isSingleLineNarrower)
            {
                return(_previousDesiredSize);
            }
            else
            {
                _previousAvailableSize = size;
                _measureInvalidated    = false;

                UpdateTypography();

                var horizontalPadding = Padding.Left + Padding.Right;
                var verticalPadding   = Padding.Top + Padding.Bottom;

                // available size considering min/max width/height
                // necessary, because the height of a wrapping TextBlock depends on its width
                size = IFrameworkElementHelper.SizeThatFits(this, size);

                // available size considering padding
                size.Width  -= (nfloat)horizontalPadding;
                size.Height -= (nfloat)verticalPadding;

                var result = base.SizeThatFits(size);

                if (result.Height == 0)                 // this can happen when Text is null or empty
                {
                    // This measures the height correctly, even if the Text is null or empty
                    // This matches Windows where empty TextBlocks still have a height (especially useful when measuring ListView items with no DataContext)
                    result = (Text ?? NSString.Empty).StringSize(this.Font, size);
                }

                if (AdjustsFontSizeToFitWidth && !nfloat.IsNaN(size.Width))
                {
                    result.Width = size.Width;
                }

                result.Width  += (nfloat)horizontalPadding;
                result.Height += (nfloat)verticalPadding;

                result = IFrameworkElementHelper.SizeThatFits(this, result);
                return(_previousDesiredSize = new CGSize(Math.Ceiling(result.Width), Math.Ceiling(result.Height)));
            }
        }
Пример #4
0
        private Size GetConstrainedSize(Size availableSize)
        {
            var constrainedSize = IFrameworkElementHelper.SizeThatFits(_element as IFrameworkElement, availableSize);

#if XAMARIN_IOS
            return(constrainedSize.ToFoundationSize());
#else
            return(constrainedSize);
#endif
        }
Пример #5
0
        public override CGSize SizeThatFits(CGSize size)
        {
            size = IFrameworkElementHelper.SizeThatFits(this, size);

            if (nfloat.IsPositiveInfinity(size.Height) || nfloat.IsPositiveInfinity(size.Width))
            {
                // Changes from IOS 9 doc.
                // See following
                // https://jira.appcelerator.org/browse/TIMOB-19203
                // https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-9.0/
                size = base.SizeThatFits(size);
            }


            return(size);
        }
Пример #6
0
        public override CGSize SizeThatFits(CGSize size)
        {
            var textBox = _textBox.GetTarget();

            if (textBox != null)
            {
                //bug in base.SizeThatFits(size) where we get stuck and size is never return for value NaN
                if (nfloat.IsNaN(size.Width))
                {
                    size = new CGSize(nfloat.PositiveInfinity, nfloat.PositiveInfinity);
                }

                //at this point size returned represent all the space available
                //to have the same behavior of Windows, we need to call UIView.SizeThatFits() to return a size that best fits
                var expectedSize = base.SizeThatFits(size);

                //Disable the scroll if you are given enough space. Else framework will use the scrollview to move text up
                ScrollEnabled = expectedSize.Height >= size.Height;

                var canTakeAllSpace = expectedSize.Height < size.Height && !nfloat.IsInfinity(size.Height) && size.Height != textBox.MaxHeight;
                // if textBox.Height is set, size.Height will be the same
                var shouldTakeAllSpace = !double.IsNaN(textBox.Height) || textBox.VerticalAlignment == VerticalAlignment.Stretch;
                if (canTakeAllSpace && shouldTakeAllSpace)
                {
                    expectedSize.Height = size.Height;                    //Take all the space given
                }

                canTakeAllSpace = expectedSize.Width < size.Width && !nfloat.IsInfinity(size.Width) && size.Width != textBox.MaxWidth;
                // if textBox.Width is set, size.Width will be the same
                shouldTakeAllSpace = !double.IsNaN(textBox.Width) || textBox.HorizontalAlignment == HorizontalAlignment.Stretch;
                if (canTakeAllSpace && shouldTakeAllSpace)
                {
                    expectedSize.Width = size.Width;                    //Take all the space given
                }

                var result = IFrameworkElementHelper.SizeThatFits(this, expectedSize);                //Adjust for NaN and MaxHeight..

                return(result);
            }
            else
            {
                return(CGSize.Empty);
            }
        }
Пример #7
0
            protected override Size MeasureOverride(Size availableSize)
            {
                var sizeThatFits = IFrameworkElementHelper.SizeThatFits(Panel, availableSize);

                double maxChildWidth = 0f, maxChildHeight = 0f;

                //Per the link, if the NativePagedView has no fixed size in a dimension, wrap it to the size of its largest child. - http://stackoverflow.com/questions/8394681/android-i-am-unable-to-have-viewpager-wrap-content
                //This might be brittle if items have varying dimensions along the unfixed axis; one (hackish) solution would be to increase OffscreenPageLimit (the number of offscreen pages that are kept).
                if (double.IsPositiveInfinity(sizeThatFits.Width) || double.IsPositiveInfinity(sizeThatFits.Height))
                {
                    foreach (var child in this.GetChildren())
                    {
                        var desiredChildSize = MeasureChild(child, sizeThatFits);
                        maxChildWidth  = Math.Max(maxChildWidth, desiredChildSize.Width);
                        maxChildHeight = Math.Max(maxChildHeight, desiredChildSize.Height);
                    }
                }

                return(new Size(
                           !double.IsPositiveInfinity(sizeThatFits.Width) ? sizeThatFits.Width : maxChildWidth,
                           !double.IsPositiveInfinity(sizeThatFits.Height) ? sizeThatFits.Height : maxChildHeight
                           ));
            }
Пример #8
0
        public override CGSize SizeThatFits(CGSize size)
        {
            size = IFrameworkElementHelper.SizeThatFits(this, size);

            if (nfloat.IsPositiveInfinity(size.Height) || nfloat.IsPositiveInfinity(size.Width))
            {
                // Changes from IOS 9 doc.
                // See following
                // https://jira.appcelerator.org/browse/TIMOB-19203
                // https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-9.0/
                size = base.SizeThatFits(size);
            }

            if (this.Frame.Size != size)
            {
                this.SetDimensions(size.Width, size.Height);

                // forces PickerModel.GetComponentWidth to get called,
                // which then receives the new dimensions (which might differ from the default value of 320)
                this.SetNeedsLayout();
            }

            return(size);
        }
Пример #9
0
 public override CGSize SizeThatFits(CGSize size)
 {
     return(IFrameworkElementHelper.SizeThatFits(this, base.SizeThatFits(size)));
 }
Пример #10
0
 public override CGSize SizeThatFits(CGSize size)
 {
     size = base.SizeThatFits(size);
     size = IFrameworkElementHelper.SizeThatFits(this, size);
     return(size);
 }