$ git show toast

Toast

Basic/anim toast

Slide a message in from the top, hold it, then slide it away on its own.

Main · New Architecture only · worklets live in react-native-worklets

This snippet uses APIs that didn’t change between versions, so the same code runs on Reanimated 4 and 3.

SlideInUpSlideOutUpentering / exiting
toast.tsx · reanimated 4
// Layout animation presets handle the enter and exit
const [toast, setToast] = useState<string | null>(null);
const timer = useRef<ReturnType<typeof setTimeout>>();

const show = (message: string) => {
  clearTimeout(timer.current);
  setToast(message);
  timer.current = setTimeout(() => setToast(null), 2500); // auto dismiss
};

{toast && (
  <Animated.View
    key={toast}
    entering={SlideInUp.springify().damping(16)}
    exiting={SlideOutUp.duration(200)}
    style={[styles.toast, { top: insets.top + 8 }]}>
    <Text style={styles.toastText}>{toast}</Text>
  </Animated.View>
)}