Пример #1
0
        protected override UIWidget BuildTree(Element childView, UIWidget parentWidget)
        {
            /*
             *  1. Return parent widget if child view is null.
             *  Since, We won't be able to create a UIWidget out of the view.
             */

            if (childView == null)
            {
                return(parentWidget);
            }

            /*
             *  2. Create a UIWidget for the child view.
             */

            var childWidget = CreateUIWidget(childView, parentWidget);

            parentWidget.Children.Add(childWidget);

            if (ElementHelper.HasContentProperty(childView))
            {
                childWidget.AllowsManyChildren        = ElementHelper.ContentPropertyAllowsManyChildren(childView);
                childWidget.IsContentPropertyViewType = ElementHelper.IsContentPropertyView(childView);
                childWidget.ContentPropertyTypeName   = ElementHelper.GetContentPropertyTypeName(childView);
                childWidget.HasContentProperty        = true;
                childWidget.IsLayout = false;
            }
            else
            {
                childWidget.HasContentProperty = false;
            }

            /*
             *  3. Determine if the child view has children of it's own.
             */

            var isParentView = childView as ILayoutController;

            if (isParentView != null)
            {
                childWidget.IsLayout = true;
            }

            // ListView check
            IReadOnlyList <Element> grandChildren;
            var isListView = childView as ITemplatedItemsView <Cell>;

            if (isListView == null)
            {
                grandChildren = isParentView?.Children;
            }
            else
            {
                grandChildren = isListView.TemplatedItems;
            }

            // TableView check
            if (grandChildren == null && childView is TableView)
            {
                var tableView = childView as TableView;
                var cells     = new List <Element>();

                foreach (var section in tableView.Root)
                {
                    foreach (var cell in section)
                    {
                        cells.Add(cell);
                    }
                }

                grandChildren = cells.ToArray();
            }

            // no children
            if (grandChildren == null || grandChildren.Count == 0)
            {
                return(parentWidget);
            }

            /*
             *  4. The child does have it's own children.
             */

            foreach (var grandChild in grandChildren)
            {
                if (grandChild != null)
                {
                    if (grandChild is ILayoutController)
                    {
                        BuildTree(grandChild, childWidget);
                    }
                    else if (grandChild is ListView)
                    {
                        BuildTree(grandChild, childWidget);
                    }
                    else if (grandChild is TableView)
                    {
                        var grandTable  = grandChild as TableView;
                        var tableWidget = CreateUIWidget(grandChild, childWidget);

                        childWidget.Children.Add(tableWidget);

                        foreach (var section in grandTable.Root)
                        {
                            foreach (var cell in section)
                            {
                                BuildTree(cell, tableWidget);
                            }
                        }
                    }
                    else if (grandChild is ViewCell)
                    {
                        var grandViewCell       = grandChild as ViewCell;
                        var grandViewCellWidget = CreateUIWidget(grandChild, childWidget);

                        childWidget.Children.Add(grandViewCellWidget);

                        if (grandViewCell.View != null)
                        {
                            BuildTree(grandViewCell.View, grandViewCellWidget);
                        }
                    }
                    else
                    {
                        var grandChildWidget = CreateUIWidget(grandChild, childWidget);

                        if (ElementHelper.HasContentProperty(grandChild))
                        {
                            grandChildWidget.IsLayout = true;
                        }

                        childWidget.Children.Add(grandChildWidget);
                    }
                }
            }

            return(parentWidget);
        }