Example #1
0
        public void Measure(int widthMeasureSpec, int heightMeasureSpec, int?maxHeightPixels, int?maxWidthPixels)
        {
            //if (width == -1)
            //	width = double.PositiveInfinity;

            //if (height == -1)
            //	height = double.PositiveInfinity;

            //Width = width;
            //Height = height;
            //MaxWidth = maxWidth;
            //MaxHeight = maxHeight;
            //X = x;
            //Y = y;
            var width     = widthMeasureSpec.GetSize();
            var height    = heightMeasureSpec.GetSize();
            var maxWidth  = maxWidthPixels;
            var maxHeight = maxHeightPixels;

            Context context;

            if (Handler == null || !(_context.TryGetTarget(out context)) || !NativeView.IsAlive())
            {
                return;
            }

            if (View == null)
            {
                //MauiView.Measure(0, 0);
                //MauiView.Arrange(Rectangle.Zero);
                return;
            }

            // NativeView.Measure(widthMeasureSpec, heightMeasureSpec);

            var layoutParams = NativeView.LayoutParameters;

            //if (double.IsInfinity(height))
            //	height = request.Height;

            //if (double.IsInfinity(width))
            //	width = request.Width;

            if (height > maxHeight)
            {
                heightMeasureSpec = MeasureSpecMode.AtMost.MakeMeasureSpec(maxHeight.Value);
            }

            if (width > maxWidth)
            {
                widthMeasureSpec = MeasureSpecMode.AtMost.MakeMeasureSpec(maxWidth.Value);
            }

            if (layoutParams.Width != LP.MatchParent && width > 0)
            {
                layoutParams.Width = width;
            }
            else
            {
                widthMeasureSpec = MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            }

            if (layoutParams.Height != LP.MatchParent && height > 0)
            {
                layoutParams.Height = height;
            }
            else
            {
                heightMeasureSpec = MeasureSpecMode.Unspecified.MakeMeasureSpec(0);
            }

            NativeView.LayoutParameters = layoutParams;
            //var c = NativeView.Context;
            //var l = (int)c.ToPixels(x);
            //var t = (int)c.ToPixels(y);
            //var r = (int)c.ToPixels(width) + l;
            //var b = (int)c.ToPixels(height) + t;

            //NativeView.Layout(l, t, r, b);
            NativeView.Measure(widthMeasureSpec, heightMeasureSpec);
        }