1import React, {Component} from 'react';
2import {View, Text, TouchableOpacity, Platform, UIManager} from 'react-native';
3
4if (
5 Platform.OS === 'android' &&
6 UIManager.setLayoutAnimationEnabledExperimental
7) {
8 UIManager.setLayoutAnimationEnabledExperimental(true);
9}
10class AnimatedCollapsible extends React.Component {
11 state = {expanded: false};
12 render() {
13 return (
14 <View style={{overflow: 'hidden'}}>
15 <TouchableOpacity
16 onPress={() => {
17 LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
18 this.setState({expanded: !this.state.expanded});
19 }}>
20 <Text>
21 Press me to {this.state.expanded ? 'collapse' : 'expand'}!
22 </Text>
23 </TouchableOpacity>
24 {this.state.expanded && <Text>I disappear sometimes!</Text>}
25 </View>
26 );
27 }
28}
29
1if (Platform.OS === 'android') {
2 if (UIManager.setLayoutAnimationEnabledExperimental) {
3 UIManager.setLayoutAnimationEnabledExperimental(true);
4 }
5}
6