AnimatePresence
Animate components as they mount and unmount
AnimatePresence animates direct children before they unmount. It works with every animation driver in Tamagui.
It is inspired by and forked from Framer Motion.
To use with @tamagui/core, install and import @tamagui/animate-presence. It’s already bundled and exported from tamagui.
Basic usage
Use enter and exit object keys or string clauses to define how each
property animates in and out:
String
Typed
Note you don’t even need to set opacity on the base style. Tamagui knows to normalize
styles like opacity and scale to 1 (and y to 0) if it’s not defined on the base styles
but has an enter: or exit: clause.
Animated child components must each have a unique key prop so AnimatePresence can track their presence in the tree.
Enter/exit transitions
Set enter and exit transitions when mount and unmount should differ:
enter and exit each take a whole transition value, so they accept a preset
name, a CSS transition string, or an object. The rest of the transition is what
property changes use while the element is mounted:
Because they are whole transition values, they can carry a delay and their own per-property entries:
An enter or exit value replaces the base while it applies rather than
merging into it, the same way a later CSS transition declaration replaces an
earlier one.
This works with all four animation drivers (CSS, React Native, Reanimated, Motion).
The custom prop
The custom prop updates a child’s variant before its exit animation runs, so it can leave in a different direction than it entered:
API reference
AnimatePresence Props
children: one or more Tamagui components with uniquekeypropsinitial: iffalse, children entering on initial mount will not animate (default:true)custom: pass data to children’s variants for dynamic exit animationsmode: determines how entering and exiting children render. Use"wait"to render one child at a time.onExitComplete: callback fired when all exiting children have finished animating
Component Props
When used inside AnimatePresence:
enter:clauses: values to animate from when mountingexit:clauses: values to animate to when unmountingtransition: animation configuration (supports{ enter, exit }syntax)key: required unique identifier for AnimatePresence tracking
