import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, Animated, } from 'react-native'; export default class TestProject extends Component { constructor(props) { super(props); this.state = { animation:new Animated.Value(), }; this.isOpen=false; } componentDidMount(){ } render() { return ( <View style={{marginTop:100}}> <Text style={{fontSize:30}} onPress={()=>{ this.isOpen = !this.isOpen; this.state.animation.setValue(this.isOpen?0:100); Animated.spring( this.state.animation, { toValue:this.isOpen?100:0, } ).start(); }}>点我展开/关闭</Text> <Animated.View style={{height:this.state.animation,backgroundColor:'#f00'}}> <Text style={{fontSize:30}}>asdfasdfasdf</Text> </Animated.View> <Text style={{fontSize:30}}>asdfasdfasdf</Text> </View> ); } } AppRegistry.registerComponent('TestProject', () => TestProject);
10-12
95
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-20
08-20
08-20
08-20
08-20
08-20