示例#1
0
        public _ReadingOrderSortData _pickNext(List <_ReadingOrderSortData> candidates)
        {
            FocusTravesalUtils.mergeSort <_ReadingOrderSortData>(candidates, compare: (_ReadingOrderSortData a, _ReadingOrderSortData b) => a.rect.top.CompareTo(b.rect.top));
            _ReadingOrderSortData topmost = candidates.First();

            List <_ReadingOrderSortData> inBand(_ReadingOrderSortData current, IEnumerable <_ReadingOrderSortData> _candidates)
            {
                Rect band = Rect.fromLTRB(float.NegativeInfinity, current.rect.top, float.PositiveInfinity, current.rect.bottom);

                return(LinqUtils <_ReadingOrderSortData> .WhereList(_candidates, ((_ReadingOrderSortData item) => {
                    return !item.rect.intersect(band).isEmpty;
                })));
            }

            List <_ReadingOrderSortData> inBandOfTop = inBand(topmost, candidates);

            D.assert(topmost.rect.isEmpty || inBandOfTop.isNotEmpty());
            if (inBandOfTop.Count <= 1)
            {
                return(topmost);
            }
            TextDirection nearestCommonDirectionality = _ReadingOrderSortData.commonDirectionalityOf(inBandOfTop);

            _ReadingOrderSortData.sortWithDirectionality(inBandOfTop, nearestCommonDirectionality);
            List <_ReadingOrderDirectionalGroupData> bandGroups = _collectDirectionalityGroups(inBandOfTop);

            if (bandGroups.Count == 1)
            {
                return(bandGroups.First().members.First());
            }
            _ReadingOrderDirectionalGroupData.sortWithDirectionality(bandGroups, nearestCommonDirectionality);
            return(bandGroups.First().members.First());
        }
示例#2
0
 public Viewport(
     Key key = null,
     AxisDirection axisDirection      = AxisDirection.down,
     AxisDirection?crossAxisDirection = null,
     float anchor                      = 0.0f,
     ViewportOffset offset             = null,
     Key center                        = null,
     float?cacheExtent                 = null,
     CacheExtentStyle cacheExtentStyle = CacheExtentStyle.pixel,
     List <Widget> slivers             = null
     ) : base(key: key, children: slivers)
 {
     D.assert(offset != null);
     D.assert(slivers != null);
     D.assert(center == null || LinqUtils <Widget> .WhereList(slivers, ((Widget child) => child.key == center)).Count() == 1);
     D.assert(cacheExtentStyle != null);
     D.assert(cacheExtentStyle != CacheExtentStyle.viewport || cacheExtent != null);
     this.axisDirection      = axisDirection;
     this.crossAxisDirection = crossAxisDirection;
     this.anchor             = anchor;
     this.offset             = offset;
     this.center             = center;
     this.cacheExtent        = cacheExtent;
     this.cacheExtentStyle   = cacheExtentStyle;
 }
示例#3
0
 public override void debugVisitOnstageChildren(ElementVisitor visitor)
 {
     LinqUtils <Element> .WhereList(children, (e => {
         RenderSliver renderSliver = (RenderSliver)e.renderObject;
         return(renderSliver.geometry.visible);
     })).ForEach(e => visitor(e));
 }
示例#4
0
        protected void collectGarbage(int leadingGarbage, int trailingGarbage)
        {
            D.assert(_debugAssertChildListLocked());
            D.assert(childCount >= leadingGarbage + trailingGarbage);

            invokeLayoutCallback <SliverConstraints>(constraints => {
                while (leadingGarbage > 0)
                {
                    _destroyOrCacheChild(firstChild);
                    leadingGarbage -= 1;
                }

                while (trailingGarbage > 0)
                {
                    _destroyOrCacheChild(lastChild);
                    trailingGarbage -= 1;
                }

                LinqUtils <RenderBox> .WhereList(_keepAliveBucket.Values, (child => {
                    SliverMultiBoxAdaptorParentData childParentData = (SliverMultiBoxAdaptorParentData)child.parentData;
                    return(!childParentData.keepAlive);
                })).ForEach(_childManager.removeChild);

                D.assert(LinqUtils <RenderBox> .WhereList(_keepAliveBucket.Values, (child => {
                    SliverMultiBoxAdaptorParentData childParentData = (SliverMultiBoxAdaptorParentData)child.parentData;
                    return(!childParentData.keepAlive);
                })).isEmpty());
            });
        }
示例#5
0
        public UIWidgetsError(List <DiagnosticsNode> diagnostics)
        {
            this.diagnostics = diagnostics;
            D.assert(diagnostics != null && diagnostics.isNotEmpty(), () => new UIWidgetsError(new List <DiagnosticsNode>()
            {
                new ErrorSummary("Empty FlutterError")
            }).ToString());
            D.assert(diagnostics.first().level == DiagnosticLevel.summary,
                     () => new UIWidgetsError(new List <DiagnosticsNode>()
            {
                new ErrorSummary("UIWidgetsError is missing a summary."),
                new ErrorDescription("All UIWidgetsError objects should start with a short (one line) " +
                                     "summary description of the problem that was detected."),
                new DiagnosticsProperty <UIWidgetsError>("Malformed", this, expandableValue: true, showSeparator: false, style: DiagnosticsTreeStyle.whitespace),
                new ErrorDescription(
                    "\nThis error should still help you solve your problem, " +
                    "however please also report this malformed error in the " +
                    "framework by filing a bug on GitHub:\n" +
                    "  https://https://github.com/Unity-Technologies/com.unity.uiwidgets"
                    )
            }).ToString());

            D.assert(() => {
                IEnumerable <DiagnosticsNode> summaries =
                    LinqUtils <DiagnosticsNode> .WhereList(diagnostics, ((DiagnosticsNode node) => node.level == DiagnosticLevel.summary));
                if (summaries.Count() > 1)
                {
                    return(false);
                }
                return(true);
            }, () => {
                IEnumerable <DiagnosticsNode> summaries =
                    LinqUtils <DiagnosticsNode> .WhereList(diagnostics, ((DiagnosticsNode node) => node.level == DiagnosticLevel.summary));
                List <DiagnosticsNode> message = new List <DiagnosticsNode>()
                {
                    new ErrorSummary("UIWidgetsError contained multiple error summaries."),
                    new ErrorDescription(
                        "All UIWidgetsError objects should have only a single short " +
                        "(one line) summary description of the problem that was " +
                        "detected."
                        ),
                    new DiagnosticsProperty <UIWidgetsError>("Malformed", this, expandableValue: true, showSeparator: false, style: DiagnosticsTreeStyle.whitespace)
                };

                int i = 0;
                foreach (DiagnosticsNode summary in summaries)
                {
                    message.Add(new DiagnosticsProperty <DiagnosticsNode>($"Summary {i}", summary, expandableValue: true));
                    i += 1;
                }
                message.Add(new ErrorDescription(
                                "\nThis error should still help you solve your problem, " +
                                "however please also report this malformed error in the " +
                                "framework by filing a bug on GitHub:\n" +
                                "  https://https://github.com/Unity-Technologies/com.unity.uiwidgets"
                                ));

                return(new UIWidgetsError(message).ToString());
            });
        }
 public override void debugVisitOnstageChildren(ElementVisitor visitor)
 {
     foreach (var child in LinqUtils <Element> .WhereList(children, (_shouldPaint)))
     {
         visitor(child);
     }
 }
示例#7
0
        public IEnumerable <FocusNode> _sortAndFilterHorizontally(
            TraversalDirection direction,
            Rect target,
            FocusNode nearestScope)
        {
            D.assert(direction == TraversalDirection.left || direction == TraversalDirection.right);
            IEnumerable <FocusNode> nodes = nearestScope.traversalDescendants;

            D.assert(!nodes.Contains(nearestScope));
            List <FocusNode> sorted = nodes.ToList();

            FocusTravesalUtils.mergeSort <FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => a.rect.center.dx.CompareTo(b.rect.center.dx));
            IEnumerable <FocusNode> result = new List <FocusNode>();

            switch (direction)
            {
            case TraversalDirection.left:
                result = LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => node.rect != target && node.rect.center.dx <= target.left));

                break;

            case TraversalDirection.right:
                result = LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => node.rect != target && node.rect.center.dx >= target.right));

                break;

            case TraversalDirection.up:
            case TraversalDirection.down:
                break;
            }
            return(result);
        }
示例#8
0
        public DropdownButton(
            Key key = null,
            List <DropdownMenuItem <T> > items = null,
            material_.DropdownButtonBuilder selectedItemBuilder = null,
            T value                    = default,
            Widget hint                = null,
            Widget disabledHint        = null,
            ValueChanged <T> onChanged = null,
            VoidCallback onTap         = null,
            int elevation              = 8,
            TextStyle style            = null,
            Widget underline           = null,
            Widget icon                = null,
            Color iconDisabledColor    = null,
            Color iconEnabledColor     = null,
            float iconSize             = 24.0f,
            bool isDense               = false,
            bool isExpanded            = false,
            float?itemHeight           = material_.kMinInteractiveDimension,
            Color focusColor           = null,
            FocusNode focusNode        = null,
            bool autofocus             = false,
            Color dropdownColor        = null
            ) :
            base(key: key)
        {
            D.assert(items == null || items.isEmpty() || value == null ||
                     LinqUtils <DropdownMenuItem <T> > .WhereList(items, ((DropdownMenuItem <T> item) => { return(item.value.Equals(value)); })).Count() == 1,
                     () => "There should be exactly one item with [DropdownButton]'s value: " +
                     $"{value}. \n" +
                     "Either zero or 2 or more [DropdownMenuItem]s were detected " +
                     "with the same value"
                     );
            D.assert(itemHeight == null || itemHeight >= material_.kMinInteractiveDimension);

            this.items = items;
            this.selectedItemBuilder = selectedItemBuilder;
            this.value             = value;
            this.hint              = hint;
            this.disabledHint      = disabledHint;
            this.onChanged         = onChanged;
            this.onTap             = onTap;
            this.elevation         = elevation;
            this.style             = style;
            this.underline         = underline;
            this.icon              = icon;
            this.iconDisabledColor = iconDisabledColor;
            this.iconEnabledColor  = iconEnabledColor;
            this.iconSize          = iconSize;
            this.isDense           = isDense;
            this.isExpanded        = isExpanded;
            this.itemHeight        = itemHeight;
            this.focusColor        = focusColor;
            this.focusNode         = focusNode;
            this.autofocus         = autofocus;
            this.dropdownColor     = dropdownColor;
        }
示例#9
0
        private static Dictionary <GalleryDemoCategory, List <GalleryDemo> > _generateCategoryToDemos()
        {
            Dictionary <GalleryDemoCategory, List <GalleryDemo> > result =
                new Dictionary <GalleryDemoCategory, List <GalleryDemo> >();

            foreach (var category in kAllGalleryDemoCategories)
            {
                result.Add(category,
                           LinqUtils <GalleryDemo> .WhereList(kAllGalleryDemos, ((GalleryDemo demo) => { return(demo.category == category); })));
            }

            return(result);
        }
示例#10
0
        public override void changedScope(FocusNode node = null, FocusScopeNode oldScope = null)
        {
            base.changedScope(node: node, oldScope: oldScope);
            if (oldScope != null)
            {
                var delEntries = LinqUtils <_DirectionalPolicyDataEntry> .WhereList(_policyData[oldScope]?.history, ((_DirectionalPolicyDataEntry entry) => {
                    return(entry.node == node);
                }));

                foreach (var delEntry in delEntries)
                {
                    _policyData[oldScope]?.history?.Remove(delEntry);
                }
            }
        }
示例#11
0
        void _updateSelectedIndex()
        {
            if (!_enabled)
            {
                return;
            }

            D.assert(widget.value == null ||
                     LinqUtils <DropdownMenuItem <T> > .WhereList(widget.items, ((DropdownMenuItem <T> item) => item.value.Equals(widget.value))
                                                                  ).Count == 1);
            _selectedIndex = null;
            for (int itemIndex = 0; itemIndex < widget.items.Count; itemIndex++)
            {
                if (widget.items[itemIndex].value.Equals(widget.value))
                {
                    _selectedIndex = itemIndex;
                    return;
                }
            }
        }
示例#12
0
        protected void reportError(
            DiagnosticsNode context = null,
            Exception exception     = null,
            InformationCollector informationCollector = null,
            bool silent = false)
        {
            _currentError = new UIWidgetsErrorDetails(
                exception: exception,
                library: "image resource service",
                context: context,
                informationCollector: informationCollector,
                silent: silent
                );

            var localErrorListeners = LinqUtils <ImageErrorListener> .WhereList(
                LinqUtils <ImageErrorListener, ImageStreamListener> .SelectList(_listeners, (l => l.onError)),
                (l => l != null));

            if (localErrorListeners.isEmpty())
            {
                UIWidgetsError.reportError(_currentError);
            }
            else
            {
                foreach (var errorListener in localErrorListeners)
                {
                    try {
                        errorListener(exception);
                    }
                    catch (Exception ex) {
                        UIWidgetsError.reportError(
                            new UIWidgetsErrorDetails(
                                context: new ErrorDescription("when reporting an error to an image listener"),
                                library: "image resource service",
                                exception: ex
                                )
                            );
                    }
                }
            }
        }
示例#13
0
        public override void didStopUserGesture()
        {
            if (navigator.userGestureInProgress)
            {
                return;
            }

            bool isInvalidFlight(_HeroFlight flight)
            {
                return(flight.manifest.isUserGestureTransition &&
                       flight.manifest.type == HeroFlightDirection.pop &&
                       flight._proxyAnimation.isDismissed);
            }

            List <_HeroFlight> invalidFlights = LinqUtils <_HeroFlight> .WhereList(_flights.Values, isInvalidFlight);

            foreach (_HeroFlight flight in invalidFlights)
            {
                flight._handleAnimationUpdate(AnimationStatus.dismissed);
            }
        }
示例#14
0
        public override void debugVisitOnstageChildren(ElementVisitor visitor)
        {
            LinqUtils <Element> .WhereList(_childElements.Values, (child => {
                SliverMultiBoxAdaptorParentData parentData =
                    (SliverMultiBoxAdaptorParentData)child.renderObject.parentData;
                float itemExtent = 0;
                switch (renderObject.constraints.axis)
                {
                case Axis.horizontal:
                    itemExtent = child.renderObject.paintBounds.width;
                    break;

                case Axis.vertical:
                    itemExtent = child.renderObject.paintBounds.height;
                    break;
                }

                return(parentData.layoutOffset != null &&
                       parentData.layoutOffset < renderObject.constraints.scrollOffset + renderObject.constraints.remainingPaintExtent &&
                       parentData.layoutOffset + itemExtent > renderObject.constraints.scrollOffset);
            })).ForEach(e => visitor(e));
        }
示例#15
0
        public IEnumerable <FocusNode> _sortAndFilterVertically(
            TraversalDirection direction,
            Rect target,
            IEnumerable <FocusNode> nodes)
        {
            List <FocusNode> sorted = nodes.ToList();

            FocusTravesalUtils.mergeSort <FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => a.rect.center.dy.CompareTo(b.rect.center.dy));
            switch (direction)
            {
            case TraversalDirection.up:
                return(LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => node.rect != target && node.rect.center.dy <= target.top)));

            case TraversalDirection.down:
                return(LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => node.rect != target && node.rect.center.dy >= target.bottom)));

            case TraversalDirection.left:
            case TraversalDirection.right:
                break;
            }
            D.assert(direction == TraversalDirection.up || direction == TraversalDirection.down);
            return(null);
        }
示例#16
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            ThemeData             themeData     = Theme.of(context);
            MaterialLocalizations localizations = MaterialLocalizations.of(context);

            List <Widget> headerWidgets = new List <Widget>();

            float startPadding = 24.0f;

            if (_selectedRowCount == 0)
            {
                headerWidgets.Add(new Expanded(child: widget.header));
                if (widget.header is ButtonBar)
                {
                    startPadding = 12.0f;
                }
            }
            else
            {
                headerWidgets.Add(new Expanded(
                                      child: new Text(localizations.selectedRowCountTitle(_selectedRowCount))
                                      ));
            }

            if (widget.actions != null)
            {
                headerWidgets.AddRange(
                    LinqUtils <Widget> .SelectList(widget.actions, ((Widget action) => {
                    return(new Padding(
                               padding: EdgeInsetsDirectional.only(
                                   start: 24.0f - 8.0f * 2.0f),
                               child: action
                               ));
                }))
                    );
            }

            TextStyle     footerTextStyle = themeData.textTheme.caption;
            List <Widget> footerWidgets   = new List <Widget>();

            if (widget.onRowsPerPageChanged != null)
            {
                List <Widget> availableRowsPerPage = LinqUtils <Widget, int> .SelectList(
                    LinqUtils <int> .WhereList(widget.availableRowsPerPage, ((int value) => value <= _rowCount || value == widget.rowsPerPage)),
                    (int value) => {
                    return((Widget) new DropdownMenuItem <int>(
                               value: value,
                               child: new Text($"{value}")
                               ));
                });

                footerWidgets.AddRange(new List <Widget>()
                {
                    new Container(width: 14.0f), // to match trailing padding in case we overflow and end up scrolling
                    new Text(localizations.rowsPerPageTitle),
                    new ConstrainedBox(
                        constraints: new BoxConstraints(minWidth: 64.0f), // 40.0 for the text, 24.0 for the icon
                        child: new Align(
                            alignment: AlignmentDirectional.centerEnd,
                            child: new DropdownButtonHideUnderline(
                                child: new DropdownButton <int>(
                                    items: availableRowsPerPage.Cast <DropdownMenuItem <int> >().ToList(),
                                    value: widget.rowsPerPage,
                                    onChanged: widget.onRowsPerPageChanged,
                                    style: footerTextStyle,
                                    iconSize: 24.0f
                                    )
                                )
                            )
                        ),
                });
            }

            footerWidgets.AddRange(new List <Widget>()
            {
                new Container(width: 32.0f),
                new Text(
                    localizations.pageRowsInfoTitle(
                        _firstRowIndex + 1,
                        _firstRowIndex + widget.rowsPerPage,
                        _rowCount,
                        _rowCountApproximate
                        )
                    ),
                new Container(width: 32.0f),
                new IconButton(
                    icon: new Icon(Icons.chevron_left),
                    padding: EdgeInsets.zero,
                    tooltip:
                    localizations.previousPageTooltip,
                    onPressed: _firstRowIndex <= 0 ? (VoidCallback)null : _handlePrevious),
                new Container(width: 24.0f),
                new IconButton(
                    icon: new Icon(Icons.chevron_right),
                    padding: EdgeInsets.zero,
                    tooltip:
                    localizations.nextPageTooltip,
                    onPressed: (!_rowCountApproximate && (_firstRowIndex + widget.rowsPerPage >= _rowCount))
                        ? (VoidCallback)null
                        : _handleNext
                    ),

                new Container(width: 14.0f),
            });

            return(new LayoutBuilder(
                       builder: (BuildContext _context, BoxConstraints constraints) => {
                return new Card(
                    child: new Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: new List <Widget> {
                    new DefaultTextStyle(
                        style: _selectedRowCount > 0
                                        ? themeData.textTheme.subtitle1.copyWith(color: themeData.accentColor)
                                        : themeData.textTheme.headline6.copyWith(fontWeight: FontWeight.w400),
                        child: IconTheme.merge(
                            data: new IconThemeData(
                                opacity: 0.54f
                                ),
                            child: new Ink(
                                height: 64.0f,
                                color: _selectedRowCount > 0 ? themeData.secondaryHeaderColor : null,
                                child: new Padding(
                                    padding: EdgeInsetsDirectional.only(
                                        start: startPadding, end: 14.0f),
                                    child: new Row(
                                        mainAxisAlignment: MainAxisAlignment.end,
                                        children: headerWidgets
                                        )
                                    )
                                )
                            )
                        ),
                    new SingleChildScrollView(
                        scrollDirection: Axis.horizontal,
                        dragStartBehavior: widget.dragStartBehavior,
                        child: new ConstrainedBox(
                            constraints: new BoxConstraints(minWidth: constraints.minWidth),
                            child: new DataTable(
                                key: _tableKey,
                                columns: widget.columns,
                                sortColumnIndex: widget.sortColumnIndex,
                                sortAscending: widget.sortAscending,
                                onSelectAll: widget.onSelectAll,
                                dataRowHeight: widget.dataRowHeight,
                                headingRowHeight: widget.headingRowHeight,
                                horizontalMargin: widget.horizontalMargin,
                                columnSpacing: widget.columnSpacing,
                                rows: _getRows(_firstRowIndex, widget.rowsPerPage)
                                )
                            )
                        ),
                    new DefaultTextStyle(
                        style: footerTextStyle,
                        child: IconTheme.merge(
                            data: new IconThemeData(
                                opacity: 0.54f
                                ),
                            child:
                            new Container(
                                height: 56.0f,
                                child: new SingleChildScrollView(
                                    dragStartBehavior: widget.dragStartBehavior,
                                    scrollDirection: Axis.horizontal,
                                    reverse: true,
                                    child: new Row(
                                        children: footerWidgets
                                        )
                                    )
                                )
                            )
                        )
                }
                        )
                    );
            }
                       ));
        }
示例#17
0
        public virtual string toStringShallow(
            string joiner            = ", ",
            DiagnosticLevel minLevel = DiagnosticLevel.debug
            )
        {
            if (foundation_.kReleaseMode)
            {
                return(toString());
            }
            string shallowString = "";

            D.assert(() => {
                var result = new StringBuilder();
                result.Append(toString());
                result.Append(joiner);
                DiagnosticPropertiesBuilder builder = new DiagnosticPropertiesBuilder();
                debugFillProperties(builder);
                result.Append(string.Join(joiner,
                                          LinqUtils <string, DiagnosticsNode> .SelectList(LinqUtils <DiagnosticsNode> .WhereList(builder.properties, (n => !n.isFiltered(minLevel))), (n => n.ToString())))
                              );
                shallowString = result.ToString();
                return(true);
            });
            return(shallowString);
        }
示例#18
0
        public override bool inDirection(FocusNode currentNode, TraversalDirection direction)
        {
            FocusScopeNode nearestScope = currentNode.nearestScope;
            FocusNode      focusedChild = nearestScope.focusedChild;

            if (focusedChild == null)
            {
                FocusNode firstFocus = findFirstFocusInDirection(currentNode, direction) ?? currentNode;
                switch (direction)
                {
                case TraversalDirection.up:
                case TraversalDirection.left:
                    FocusTravesalUtils._focusAndEnsureVisible(
                        firstFocus,
                        alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart
                        );
                    break;

                case TraversalDirection.right:
                case TraversalDirection.down:
                    FocusTravesalUtils._focusAndEnsureVisible(
                        firstFocus,
                        alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd
                        );
                    break;
                }
                return(true);
            }
            if (_popPolicyDataIfNeeded(direction, nearestScope, focusedChild))
            {
                return(true);
            }
            FocusNode       found             = null;
            ScrollableState focusedScrollable = Scrollable.of(focusedChild.context);

            switch (direction)
            {
            case TraversalDirection.down:
            case TraversalDirection.up:
                IEnumerable <FocusNode> eligibleNodes = _sortAndFilterVertically(
                    direction,
                    focusedChild.rect,
                    nearestScope.traversalDescendants
                    );
                if (focusedScrollable != null && !focusedScrollable.position.atEdge())
                {
                    IEnumerable <FocusNode> filteredEligibleNodes = LinqUtils <FocusNode> .WhereList(eligibleNodes, ((FocusNode node) => Scrollable.of(node.context) == focusedScrollable));

                    if (filteredEligibleNodes.Count() != 0)
                    {
                        eligibleNodes = filteredEligibleNodes;
                    }
                }
                if (eligibleNodes.Count() == 0)
                {
                    break;
                }
                List <FocusNode> sorted = eligibleNodes.ToList();
                if (direction == TraversalDirection.up)
                {
                    //sorted = sorted.reversed.toList();
                    sorted.Reverse();
                    sorted = sorted.ToList();
                }
                Rect band = Rect.fromLTRB(focusedChild.rect.left, float.NegativeInfinity, focusedChild.rect.right, float.PositiveInfinity);
                IEnumerable <FocusNode> inBand = LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => !node.rect.intersect(band).isEmpty));

                if (inBand.Count() != 0)
                {
                    found = inBand.First();
                    break;
                }
                FocusTravesalUtils.mergeSort <FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => {
                    return((a.rect.center.dx - focusedChild.rect.center.dx).abs().CompareTo((b.rect.center.dx - focusedChild.rect.center.dx).abs()));
                });
                found = sorted.First();
                break;

            case TraversalDirection.right:
            case TraversalDirection.left:
                eligibleNodes = _sortAndFilterHorizontally(direction, focusedChild.rect, nearestScope);
                if (focusedScrollable != null && !focusedScrollable.position.atEdge())
                {
                    IEnumerable <FocusNode> filteredEligibleNodes = LinqUtils <FocusNode> .WhereList(eligibleNodes, ((FocusNode node) => Scrollable.of(node.context) == focusedScrollable));

                    if (filteredEligibleNodes.Count() != 0)
                    {
                        eligibleNodes = filteredEligibleNodes;
                    }
                }
                if (eligibleNodes.Count() == 0)
                {
                    break;
                }
                sorted = eligibleNodes.ToList();
                if (direction == TraversalDirection.left)
                {
                    sorted.Reverse();
                    sorted = sorted.ToList();
                    //sorted = sorted.reversed.toList();
                }
                band   = Rect.fromLTRB(float.NegativeInfinity, focusedChild.rect.top, float.PositiveInfinity, focusedChild.rect.bottom);
                inBand = LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => !node.rect.intersect(band).isEmpty));

                if (inBand.Count() != 0)
                {
                    found = inBand.First();
                    break;
                }
                FocusTravesalUtils.mergeSort <FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => {
                    return((a.rect.center.dy - focusedChild.rect.center.dy).abs().CompareTo((b.rect.center.dy - focusedChild.rect.center.dy).abs()));
                });
                found = sorted.First();
                break;
            }
            if (found != null)
            {
                _pushPolicyData(direction, nearestScope, focusedChild);
                switch (direction)
                {
                case TraversalDirection.up:
                case TraversalDirection.left:
                    FocusTravesalUtils._focusAndEnsureVisible(
                        found,
                        alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtStart
                        );
                    break;

                case TraversalDirection.down:
                case TraversalDirection.right:
                    FocusTravesalUtils._focusAndEnsureVisible(
                        found,
                        alignmentPolicy: ScrollPositionAlignmentPolicy.keepVisibleAtEnd
                        );
                    break;
                }
                return(true);
            }
            return(false);
        }