router icon indicating copy to clipboard operation
router copied to clipboard

add easier system for popping multiple screens in a stack

Open CodySwannGT opened this issue 1 year ago • 2 comments

Summary

Given this navigation, I want the links to act like bottom tabs.

  1. If you are drilled down into "Buy" nav and click "Buy", the app replaces the nav stack with the '/buy' route which is the initial screen for that tab
  2. If you are drilled down into the "Sell" nav and click "Buy", the app jumpsTo the Buy tab. If you click back to "Sell" the app takes you to the last screen you were on

However, if I'm drilled down into "Buy" and click "Buy" (which calls replace('/buy'), nothing happens

Minimal reproducible example

  const segments = useSegments();
  const currentSegment = segments.slice(-1)[0];
  const isInPath = segments.includes(segment);
  const isCurrent = currentSegment === segment;
  const router = useRouter();

  const handlePress = useCallback(
    () =>
      isCurrent
        ? null
        : isInPath
        ? router.replace(`/${segment}`)
        : navigator.jumpTo(segment),
    [isCurrent, isInPath, router, segment, navigator]
  );

CodySwannGT avatar Apr 11 '23 01:04 CodySwannGT