/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import { AppRegistry,Text,View } from 'react-native';
class Blink extends Component {
constructor(props) {
super(props);
this.state = {
showText: true,
}
//每1000ms对showText做一次取反
setInterval(()=>{
this.setState(previousState=>{
return { showText: !previousState.showText }
})
},1000)
}
render() {
let display = this.state.showText ? this.props.text: ''
return(
<Text>
{ display }
</Text>
)
}
}
export default class ShowText extends Component {
render() {
return (
<View>
<Blink text="爱你,却不能开口"/>
<Blink text="在这个世界上,最伤心的莫过于喜欢你却不知道你叫什么名字"/>
<Blink text="若是有缘,那时你未嫁,我未婚,娶你可好?"/>
<Blink text="我想的是你,而你却永远不会知道!你说是不是很搞笑"/>
</View>
)
}
}
AppRegistry.registerComponent('xiao', () => ShowText);
react-native state
最新推荐文章于 2021-02-23 21:46:23 发布