Esempio n. 1
0
        public void TestIsVisible()
        //https://github.com/xamarin/Microsoft.Maui.Controls/issues/2593
        {
            var label0 = new Label
            {
                IsPlatformEnabled = true,
            };
            var label1 = new Label
            {
                IsPlatformEnabled = true,
            };
            var label2 = new Label
            {
                IsPlatformEnabled = true,
            };
            var layout = new FlexLayout
            {
                IsPlatformEnabled = true,
                Direction         = FlexDirection.Column,
                Children          =
                {
                    label0,
                    label1,
                    label2,
                }
            };

            var handler = Substitute.For <IViewHandler>();

            layout.Handler = handler;

            layout.Layout(new Rect(0, 0, 300, 300));
            Assert.That(label0.Bounds, Is.EqualTo(new Rect(0, 0, 300, 20)));
            Assert.That(label1.Bounds, Is.EqualTo(new Rect(0, 20, 300, 20)));
            Assert.That(label2.Bounds, Is.EqualTo(new Rect(0, 40, 300, 20)));

            label1.IsVisible = false;

            // Changing the visibility of the label should have triggered a measure invalidation in the layout
            AssertInvalidated(handler);

            // Fake a native invalidation
            layout.ForceLayout();

            Assert.That(label0.Bounds, Is.EqualTo(new Rect(0, 0, 300, 20)));
            Assert.That(label2.Bounds, Is.EqualTo(new Rect(0, 20, 300, 20)));

            label0.IsVisible = false;
            label1.IsVisible = true;

            // Verify the visibility changes invalidated the layout
            AssertInvalidated(handler);

            // Fake a native invalidation
            layout.ForceLayout();

            Assert.That(label1.Bounds, Is.EqualTo(new Rect(0, 0, 300, 20)));
            Assert.That(label2.Bounds, Is.EqualTo(new Rect(0, 20, 300, 20)));
        }
Esempio n. 2
0
        public void ChangingGrowTriggersLayout()
        //https://github.com/xamarin/Microsoft.Maui.Controls/issues/2821
        {
            var layout = new FlexLayout
            {
                IsPlatformEnabled = true,
                Direction         = FlexDirection.Column,
            };

            var handler = Substitute.For <IViewHandler>();

            layout.Handler = handler;

            layout.Layout(new Rect(0, 0, 300, 300));
            for (var i = 0; i < 3; i++)
            {
                var box = new BoxView
                {
                    IsPlatformEnabled = true,
                };
                layout.Children.Add(box);
                FlexLayout.SetGrow(box, 1f);
            }

            // Verify the changes invalidated the layout
            AssertInvalidated(handler);

            // Fake a native invalidation
            layout.ForceLayout();

            Assert.That(layout.Children[2].Frame, Is.EqualTo(new Rect(0, 200, 300, 100)));
        }