updateActiveIndex method

void updateActiveIndex([
  1. AntdEdge? viewportAlignLine
])

Implementation

void updateActiveIndex([AntdEdge? viewportAlignLine]) {
  if (effectiveViewportSize == null) {
    return;
  }

  viewportAlignLine ??= _scrollConfig.viewportAlign;
  var offset_ = offset + viewportOffset;
  if (offset_ <= 0) {
    if (!hasTarget) {
      _activeIndex = -1;
      return;
    }
  }

  final alignOffset = offset_ + getViewOffset(viewportAlignLine);
  if (_activeIndex != -1) {
    final currentItemOffsetTop = getCurrentItemTopOffset(viewportAlignLine);
    if (currentItemOffsetTop == null) {
      _activeIndex = -1;
      return;
    }
    final itemLength = getCurrentItemLength()!;
    final currentItemOffsetBottom = currentItemOffsetTop + itemLength;

    if (currentItemOffsetBottom > 0 &&
        offset_ >= currentItemOffsetTop &&
        offset_ < currentItemOffsetBottom) {
      _notifyVisibility(
          _activeIndex,
          alignOffset - currentItemOffsetTop + viewportOffset,
          currentItemOffsetBottom - alignOffset - viewportOffset);
      return;
    }
  }

  _traverseItems(isScrollingUp, _activeIndex, (i) {
    final itemOffsetTop = getItemTopOffset(i, viewportAlignLine!);
    if (itemOffsetTop == null) {
      return true;
    }

    final itemBottom = itemOffsetTop + getItemLength(i)!;

    if (itemBottom == offset_) {
      return true;
    }
    if (itemOffsetTop < offset_ && itemBottom >= offset_) {
      final entryDistance = offset_ - itemOffsetTop;
      final remainingDistance = itemBottom - offset_;
      _notifyVisibility(i, entryDistance, remainingDistance);
      return false;
    }
    return true;
  });
}