code/tamagui.dev/data/docs/core/animations-css.mdx
The @tamagui/animations-css package works with the Tamagui compiler and
runtime to provide simple ways to share typed animations across all your
components.
yarn add @tamagui/animations-css
Add it to your Tamagui config:
import { createAnimations } from '@tamagui/animations-css'
import { createTamagui } from 'tamagui'
export default createTamagui({
animations: createAnimations({
fast: 'ease-in 150ms',
medium: 'ease-in 300ms',
slow: 'ease-in 450ms',
}),
// ...
})
At runtime, the plugin does very little except to set the transition property
in CSS. At compile-time, the compiler does the same, ensuring you get all the
benefits of prop removal and view flattening even when using animations.
CSS animations use CSS transition syntax:
createAnimations({
quick: 'ease-out 100ms',
bouncy: 'cubic-bezier(0.68, -0.55, 0.265, 1.55) 300ms',
slow: 'ease-in-out 500ms',
})
The format is: <easing-function> <duration>
You can add animation delays using the array syntax:
<Square transition={['quick', { delay: 200 }]} />
The delay (in milliseconds) is applied as CSS transition-delay.
ease - Default easing (equivalent to cubic-bezier(0.25, 0.1, 0.25, 1))linear - No easing, constant speedease-in - Slow startease-out - Slow endease-in-out - Slow start and endcubic-bezier(x1, y1, x2, y2) - Custom cubic bezier curveAdvantages:
Limitations:
import { createAnimations } from '@tamagui/animations-css'
import { YStack, createTamagui } from 'tamagui'
const animations = createAnimations({
quick: 'ease-out 150ms',
bouncy: 'cubic-bezier(0.68, -0.55, 0.265, 1.55) 400ms',
})
export default createTamagui({
animations,
// ... rest of config
})
// Usage in components
export const MyComponent = () => (
<YStack
transition="quick"
hoverStyle={{
scale: 1.1,
}}
/>
)