Example #1
0
        public static void Measure(
            this UIView view,
            MeasureSpec widthMeasureSpec,
            MeasureSpec heightMeasureSpec)
        {
            var nativeLayout = view as NativeLayout;

            if (null != nativeLayout)
            {
                nativeLayout.Measure(widthMeasureSpec, heightMeasureSpec);
            }
            else
            {
                var containerSize = new CGSize()
                {
                    Width  = widthMeasureSpec.Size,
                    Height = heightMeasureSpec.Size,
                };

                var measuredSize = view.SizeThatFits(containerSize);

                //var dimensionX = GetDefaultSize(measuredSize.Width, widthMeasureSpec);
                //var dimensionY = GetDefaultSize(measuredSize.Height, heightMeasureSpec);
                var dimensionX = new MeasuredDimension()
                {
                    Size = (float)measuredSize.Width
                };
                var dimensionY = new MeasuredDimension()
                {
                    Size = (float)measuredSize.Height
                };

                view.SetMeasuredSize(dimensionX, dimensionY);
            }
        }
Example #2
0
 public MeasuredSize(
     MeasuredDimension width,
     MeasuredDimension height)
 {
     this.Width       = width.Size;
     this.Height      = height.Size;
     this.WidthState  = width.State;
     this.HeightState = height.State;
 }
Example #3
0
        //private static MeasuredDimension GetDefaultSize(
        //          nfloat size,
        //          MeasureSpec measureSpec)
        //{
        //          MeasuredDimension result = new MeasuredDimension();
        //	var specMode = measureSpec.Mode;
        //	var specSize = measureSpec.Size;
        //	switch (specMode)
        //	{
        //		case MeasureMode.Unspecified:
        //			result.Size = (float)size;
        //			break;
        //		case MeasureMode.AtMost:
        //		case MeasureMode.Exactly:
        //			result.Size = specSize;
        //			break;
        //              default:
        //                  result.Size = (float)size;
        //                  break;
        //	}
        //	return result;
        //}

        public static void SetMeasuredSize(
            this UIView view,
            MeasuredDimension dimensionX,
            MeasuredDimension dimensionY)
        {
            var layoutProperties = view.LayoutProperties();

            layoutProperties.MeasuredSize = new MeasuredSize(dimensionX, dimensionY);
        }
Example #4
0
        protected static MeasuredDimension ResolveSizeAndState(
            float size,
            MeasureSpec measureSpec,
            MeasuredStateFlags childMeasuredState)
        {
            MeasuredDimension result = new MeasuredDimension();

            MeasureMode specMode = measureSpec.Mode;
            float       specSize = measureSpec.Size;

            switch (specMode)
            {
            case MeasureSpec.Unspecified:
                result.Size = size;
                break;

            case MeasureSpec.AtMost:
                if (specSize < size)
                {
                    result.Size   = specSize;
                    result.State |= MeasuredStateFlags.TooSmall;
                }
                else
                {
                    result.Size = size;
                }
                break;

            case MeasureSpec.Exactly:
                result.Size = specSize;
                break;
            }

            result.State |= childMeasuredState;

            return(result);
        }