recordTabSwap method

NavStackEntry? recordTabSwap({
  1. required UiSnapshot snapshot,
  2. required UiNode tapTarget,
})

Inspect snapshot before a tap is about to fire on tapTarget.

Implementation

NavStackEntry? recordTabSwap({
  required UiSnapshot snapshot,
  required UiNode tapTarget,
}) {
  final targetPath = snapshot.paths[tapTarget.stableId];
  if (targetPath == null || !targetPath.contains('.')) return null;
  final parentPath = targetPath.substring(0, targetPath.lastIndexOf('.'));

  UiNode? selectedSibling;
  var hasTabGroupSignature = false;
  for (final n in snapshot.nodes) {
    final p = snapshot.paths[n.stableId];
    if (p == null) continue;
    if (!p.startsWith('$parentPath.')) continue;
    if (p.substring(parentPath.length + 1).contains('.')) continue;
    if (n.hasAction && n.actions.contains('tap')) {
      if (n.selected) {
        selectedSibling = n;
        hasTabGroupSignature = true;
      } else if (n.actions.contains('tap')) {
      }
    }
  }

  if (!hasTabGroupSignature || selectedSibling == null) return null;
  if (selectedSibling.stableId == tapTarget.stableId) return null;

  final entry = NavStackEntry(
    previousStableId: selectedSibling.stableId,
    screen: snapshot.screen,
    capturedAt: DateTime.now(),
    previousRole: selectedSibling.role,
  );
  _entries.add(entry);
  return entry;
}