innerScrollableDirections function

Map<GestureDirection, bool> innerScrollableDirections(
  1. Element? host,
  2. EventTarget? target
)

Directions in which a parent of target can scroll within the host.

Implementation

Map<GestureDirection, bool> innerScrollableDirections(
    Element? host, EventTarget? target) {
  Map<GestureDirection, bool> directions = {
    GestureDirection.up: false,
    GestureDirection.down: false,
    GestureDirection.left: false,
    GestureDirection.right: false
  };
  Element? element = target as Element?;
  while (element != host && element != null) {
    var style = element.getComputedStyle();
    String overflowX = style.getPropertyValue('overflow-x');
    if (overflowX == 'auto' || overflowX == 'scroll') {
      directions[GestureDirection.left] =
          directions[GestureDirection.left]! || element.scrollLeft > 0;
      directions[GestureDirection.right] =
          directions[GestureDirection.right]! ||
              element.scrollLeft + element.clientWidth < element.scrollWidth;
    }
    String overflowY = style.getPropertyValue('overflow-y');
    if (overflowY == 'auto' || overflowY == 'scroll') {
      directions[GestureDirection.up] =
          directions[GestureDirection.up]! || element.scrollTop > 0;
      directions[GestureDirection.down] = directions[GestureDirection.down]! ||
          element.scrollTop + element.clientHeight < element.scrollHeight;
    }
    element = element.parent;
  }
  return directions;
}