1.樣式文件style.jsreact
代碼以下:react-native
import {ide
StyleSheet,this
} from 'react-native';spa
export let styles = StyleSheet.create({get
blinkText: {it
fontSize: 20io
},class
});import
截圖以下:
2.業務文件App.js
代碼以下:
import React, {
Component
} from 'react';
import {
View,
Text,
AppRegistry
} from 'react-native';
// 加載樣式文件
import {
styles
} from './static/style/style';
class Blink extends Component {
constructor(props) {
super(props);
this.state = {
isShowingText: true
};
setInterval(() => {
this.setState(previousState => {
return {
isShowingText: !previousState.isShowingText
};
});
}, 1000);
}
render() {
if (!this.state.isShowingText) {
return null;
};
return (
<Text style={styles.blinkText}>{this.props.text}</Text>
);
}
}
export default class BlinkApp extends Component {
render() {
return (
<View>
<Blink text='first blink' />
<Blink text='second blink' />
</View>
);
}
}
AppRegistry.registerComponent('BlinkApp', () => BlinkApp);
截圖以下:
3.運行代碼截圖: