handleAddItemsEvent method

  1. @visibleForTesting
void handleAddItemsEvent(
  1. NodeAddEvent<INode> event
)

Implementation

@visibleForTesting
void handleAddItemsEvent(NodeAddEvent<INode> event) {
  for (final node in event.items) {
    if (animatedListStateController.containsKey(node.path)) continue;

    if (node.isRoot || node.parent?.isRoot == true) {
      final root = node.root as ITreeNode<Data>;
      if (!root.isExpanded) {
        if (focusToNewNode) {
          expansionBehaviourController.expandNode(root);
        }
      } else {
        animatedListStateController.insertAll(
            animatedListStateController.list.length, List.from(event.items));
      }
      if (focusToNewNode) {
        expansionBehaviourController.scrollToLastVisibleChild(root);
      }
    } else {
      final parentIndex = animatedListStateController.list
          .indexWhere((element) => element.key == node.parent?.key);
      if (parentIndex < 0) continue;

      final parentNode = animatedListStateController.list[parentIndex];

      if (!parentNode.isExpanded) {
        expansionBehaviourController.expandNode(parentNode);
      } else {
        // if the node is expanded, add the items in the flatList and
        // the animatedList
        animatedListStateController.insertAll(
            parentIndex + parentNode.childrenAsList.length,
            List.from(event.items));
      }
      if (focusToNewNode) {
        expansionBehaviourController.scrollToLastVisibleChild(parentNode);
      }
    }
  }
}