public void Add(IView child)
        {
            _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            NativeView.AddView(child.ToNative(MauiContext), 0);
        }
Beispiel #2
0
        public void Update(int index, IView child)
        {
            _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            NativeView.RemoveViewAt(index);
            NativeView.AddView(child.ToNative(MauiContext), index);
        }
Beispiel #3
0
        public void Insert(int index, IView child)
        {
            _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            var targetIndex = VirtualView.GetLayoutHandlerIndex(child);

            NativeView.AddView(child.ToNative(MauiContext), targetIndex);
        }
Beispiel #4
0
        void UpdateContent()
        {
            _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");

            NativeView.RemoveAllViews();

            if (VirtualView.PresentedContent is IView view)
            {
                NativeView.AddView(view.ToNative(MauiContext));
            }
        }
Beispiel #5
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            NativeView.CrossPlatformMeasure = VirtualView.Measure;
            NativeView.CrossPlatformArrange = VirtualView.Arrange;

            NativeView.AddView(VirtualView.Content.ToNative(MauiContext));
        }
Beispiel #6
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            NativeView.CrossPlatformMeasure = VirtualView.Measure;
            NativeView.CrossPlatformArrange = VirtualView.Arrange;
            NativeView.RemoveAllViews();
            //var wrap = ViewGroup.LayoutParams.WrapContent;
            NativeView.AddView(VirtualView.Content.ToNative(MauiContext));             // , new ViewGroup.LayoutParams(wrap, wrap));
        }
Beispiel #7
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            NativeView.CrossPlatformMeasure = VirtualView.CrossPlatformMeasure;
            NativeView.CrossPlatformArrange = VirtualView.CrossPlatformArrange;

            NativeView.RemoveAllViews();

            foreach (var child in VirtualView.OrderByZIndex())
            {
                NativeView.AddView(child.ToNative(MauiContext));
            }
        }
Beispiel #8
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            var newContent = VirtualView.Content?.ToNative(MauiContext);

            if (_content == null || newContent != _content)
            {
                if (_content != null)
                {
                    NativeView.RemoveView(_content);
                }

                _content = newContent;

                if (_content != null)
                {
                    NativeView.AddView(_content);
                }
            }
        }
        void UpdateFlyout()
        {
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");
            _ = VirtualView.Flyout.ToNative(MauiContext);

            var newFlyoutView = VirtualView.Flyout.GetNative(true);

            if (_flyoutView == newFlyoutView)
            {
                return;
            }

            if (_flyoutView != null)
            {
                _flyoutView.RemoveFromParent();
            }

            _flyoutView = newFlyoutView;
            if (_flyoutView == null)
            {
                return;
            }

            _flyoutView.LayoutParameters =
                new DrawerLayout.LayoutParams(
                    DrawerLayout.LayoutParams.WrapContent,
                    DrawerLayout.LayoutParams.MatchParent,
                    (int)GravityFlags.Start);

            NativeView.AddView(_flyoutView);


            if (VirtualView.Flyout.Background == null && Context?.Theme != null)
            {
                var colors = Context.Theme.ObtainStyledAttributes(new[] { global::Android.Resource.Attribute.ColorBackground });
                _flyoutView.SetBackgroundColor(new global::Android.Graphics.Color(colors.GetColor(0, 0)));
            }
        }
Beispiel #10
0
        void EnsureZIndexOrder(IView child)
        {
            if (NativeView.ChildCount == 0)
            {
                return;
            }

            AView nativeChildView = child.ToNative(MauiContext !);
            var   currentIndex    = IndexOf(NativeView, nativeChildView);

            if (currentIndex == -1)
            {
                return;
            }

            var targetIndex = VirtualView.GetLayoutHandlerIndex(child);

            if (currentIndex != targetIndex)
            {
                NativeView.RemoveViewAt(currentIndex);
                NativeView.AddView(nativeChildView, targetIndex);
            }
        }