When a card expands, its parent grows and every row below it moves down. Animating that with Animated means measuring the new sizes and coordinating several components, and the native driver can't animate height or position at all. LayoutAnimation works at the level of the layout instead: you configure how the next layout pass animates, change state, and the views animate to their new positions without any measuring.
Key terms
- LayoutAnimation: the API that animates views to their new positions when the next layout happens.
- configureNext:
LayoutAnimation.configureNext(config), which sets the animation used by all views in the next render and layout cycle. - LayoutAnimation.Presets: three ready-made configs,
easeInEaseOut,linearandspring. - create, update and delete: the three optional sub-configs of a LayoutAnimation config, which animate new views in, views that were updated, and views as they are removed.
Configure, then change state
The usual pattern is two lines: call configureNext, then update state.
tsxLayoutAnimation.configureNext(LayoutAnimation.Presets.spring); setExpanded(!expanded);
The config applies to the next layout, so it has to be set before the state update that causes that layout. It applies globally: every view that changes in that cycle animates, including ancestors and siblings of the component that changed. A "see more" button that grows its card and pushes the next row down needs no coordination between those components.
configureNext also takes two optional callbacks. onAnimationDidEnd is guaranteed to run when the animation completes. onAnimationDidFail is never called on the Legacy Architecture, and on the New Architecture only when the config fails to parse, so don't rely on it for error handling.
The three presets
Presets.easeInEaseOutlasts 300 ms and fades views in and out by opacity with an ease in, ease out curve.Presets.linearlasts 500 ms with the same opacity fade on a linear curve.Presets.springlasts 700 ms, fades created and deleted views linearly by opacity, and springs updated views withspringDamping: 0.4.
LayoutAnimation.easeInEaseOut(), LayoutAnimation.linear() and LayoutAnimation.spring() are shortcuts that call configureNext with the matching preset.
A config of your own
A custom config is an object with a required duration and optional create, update and delete keys. Each of those three accepts the same optional fields:
type: one of'spring','linear','easeInEaseOut','easeIn','easeOut'or'keyboard'property: one of'opacity','scaleX','scaleY'or'scaleXY', optional but recommended forcreateanddeletedurationanddelayspringDampingandinitialVelocity, wherespringDampingonly applies totype: 'spring'
LayoutAnimation.create(duration, type, property) builds the common shape for you: create and delete get the type and property, and update gets the type only.
The OrderSummary example below the lesson toggles a list of order lines inside a card. Its toggleDetails function writes the config out in full, with a 250 ms 'easeInEaseOut' for all three keys and property: 'opacity' on create and delete. That object is what LayoutAnimation.create(250, 'easeInEaseOut', 'opacity') returns. When the lines appear, they fade in, the card grows, and the delivery note below the card slides down within the same animation.
The Android flag
On Android with the Legacy Architecture, layout animations have to be enabled with UIManager.setLayoutAnimationEnabledExperimental?.(true). The method is optional in the UIManager types, so TypeScript rejects an unguarded call; the optional call ?.() (or an if check first) compiles. On the New Architecture they are enabled automatically, and the call is a no-op that logs a warning in development. The Animations guide still tells you to set the flag on Android without mentioning the architecture, so treat that call as Legacy Architecture setup only.
LayoutAnimation or Animated
LayoutAnimation gives you much less control than Animated. It only handles fire-and-forget animations, so an animation that must be interruptible needs Animated.
In exchange, LayoutAnimation is unaffected by frame drops on the JS thread and the main thread, while Animated computes each frame on the JS thread unless the native driver is on. If heavy JavaScript work has to run while the animation plays and you can't defer it, consider LayoutAnimation. For a size change that moves the views around it, such as expanding content, it is usually the better fit, since the native driver rules out height, width and position.
Code Examples
import {useState} from 'react';
import {LayoutAnimation, Pressable, StyleSheet, Text, View} from 'react-native';
type OrderLine = {id: string; label: string; amount: string};
export function OrderSummary({lines, total}: {lines: OrderLine[]; total: string}) {
const [expanded, setExpanded] = useState(false);
function toggleDetails() {
LayoutAnimation.configureNext({
duration: 250,
create: {type: 'easeInEaseOut', property: 'opacity'},
update: {type: 'easeInEaseOut'},
delete: {type: 'easeInEaseOut', property: 'opacity'},
});
setExpanded(!expanded);
}
return (
<View style={styles.screen}>
<View style={styles.card}>
<View style={styles.row}>
<Text style={styles.title}>Total</Text>
<Text style={styles.title}>{total}</Text>
</View>
{expanded &&
lines.map(line => (
<View key={line.id} style={styles.row}>
<Text>{line.label}</Text>
<Text>{line.amount}</Text>
</View>
))}
<Pressable onPress={toggleDetails}>
<Text style={styles.link}>{expanded ? 'Hide details' : 'Show details'}</Text>
</Pressable>
</View>
<Text style={styles.note}>Delivery in 2 to 3 days</Text>
</View>
);
}
const styles = StyleSheet.create({
screen: {padding: 16},
card: {padding: 16, borderRadius: 12, backgroundColor: 'white'},
row: {flexDirection: 'row', justifyContent: 'space-between', paddingVertical: 4},
title: {fontSize: 18, fontWeight: '600'},
link: {marginTop: 8, color: 'rgb(37, 99, 235)'},
note: {marginTop: 16, color: 'gray'},
});