コード例 #1
0
        void OnChildAdded(object sender, ElementEventArgs e)
        {
            var view = e.Element as VisualElement;

            if (view != null)
            {
                AddChild(view);
            }

            int itemCount = ElementController.LogicalChildren.Count;

            if (itemCount <= 1)
            {
                return;
            }

            Element lastChild = ElementController.LogicalChildren[itemCount - 1];

            if (lastChild != view)
            {
                EnsureChildOrder();
                return;
            }

            if (!System.Maui.Maui.IsLollipopOrNewer)
            {
                return;
            }

            Element previousChild = ElementController.LogicalChildren[itemCount - 2];

            IVisualElementRenderer lastRenderer     = null;
            IVisualElementRenderer previousRenderer = null;

            if (lastChild is VisualElement last)
            {
                lastRenderer = Platform.GetRenderer(last);
            }

            if (previousChild is VisualElement previous)
            {
                previousRenderer = Platform.GetRenderer(previous);
            }

            if (ElevationHelper.GetElevation(lastRenderer?.View) < ElevationHelper.GetElevation(previousRenderer?.View))
            {
                EnsureChildOrder();
            }
        }
コード例 #2
0
        void EnsureChildOrder(bool onlyUpdateElevations)
        {
            float elevationToSet = 0;

            for (var i = 0; i < ElementController.LogicalChildren.Count; i++)
            {
                Element child   = ElementController.LogicalChildren[i];
                var     element = (VisualElement)child;
                if (element != null)
                {
                    IVisualElementRenderer r = Platform.GetRenderer(element);
                    if (r != null)
                    {
                        if (System.Maui.Maui.IsLollipopOrNewer)
                        {
                            var elevation        = ElevationHelper.GetElevation(r.View) ?? 0;
                            var elementElevation = ElevationHelper.GetElevation(element, r.View.Context);

                            if (elementElevation == null)
                            {
                                if (elevation > elevationToSet)
                                {
                                    elevationToSet = elevation;
                                }

                                r.View.Elevation = elevationToSet;
                            }
                        }

                        if (!onlyUpdateElevations)
                        {
                            (_renderer.View as ViewGroup)?.BringChildToFront(r.View);
                        }
                    }
                }
            }
        }