MENU
LayoutAnimation
This automatically animates views to their new positions when the next layout happens.
MethodsconfigureNext()create() | PropertiesTypes PropertiesPresetseaseInEaseOutlinearspring |
RESETRUNFULL
import React, { useState } from "react";import { LayoutAnimation, Platform, StyleSheet, Text, TouchableOpacity,
UIManager, View } from "react-native";if (Platform.OS === "android" &&
UIManager.setLayoutAnimationEnabledExperimental) UIManager.setLayoutAnimationEnabledExperimental(true);const App = () => {
const [expanded, setExpanded] = useState(false);
return (
<View style={style.container}>
<TouchableOpacity
onPress={() => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
setExpanded(!expanded);}}>
<Text>Press me to {expanded ? "collapse" : "expand"}!</Text>
</TouchableOpacity>
{expanded && (
<View style={style.tile}>
<Text>I disappear sometimes!</Text>
</View>
)}
</View>
);};const style = StyleSheet.create({
tile: {
backgroundColor: "lightgrey",
borderWidth: 0.5,
borderColor: "#d6d7da"
},
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
overflow: "hidden"
}});export default App;