React Native 第十天
来源:互联网 发布:网络高级工视频 编辑:程序博客网 时间:2024/06/06 07:34
34、ProgressBar组件(Android)
export default class ExampleCode extends Component { constructor(props) { super(props); this.state = { number: 0.5 } } componentDidMount() { var old_num = this.state.number; var _this = this; var timer = setInterval(function () { old_num += 0.1; if (old_num >= 1) { clearInterval(timer); } _this.setState({ number: old_num }) }, 500); } render() { return ( <View style={styles.container}> <ProgressBarAndroid styleAttr="Normal" color="red" indeterminate={false} progress={this.state.number} style={{ width: "100%" }} > <View> <Text>{parseInt(this.state.number * 100)}</Text> </View> </ProgressBarAndroid> </View> ) }}
35、Alert和BackAndroid
2s内连续点击两次退出应用
export default class ExampleCode extends Component { constructor(props) { super(props); this.state = {} } componentDidMount() { BackAndroid.addEventListener('hardwareBackPress', this.myBack.bind(this)); } componentDidunmount() { BackAndroid.removeEventListener('hardwareBackPress', this.myBack.bind(this)); } myBack() { //true : 阻止掉物理按键效果 if (this.timeData && this.timeData + 2000 >= Date.now()) { return false; } var time = Date.now(); this.timeData = time; alert('双击退出app'); return true; } render() { return ( <View style={styles.container}> <TouchableOpacity onPress={()=> { BackAndroid.exitApp(0); }}> <Text>{'退出app'}</Text> ></TouchableOpacity> </View> ) }}
Alert使用方法
export default class ExampleCode extends Component { constructor(props) { super(props); this.state = {} } render() { return ( <View style={styles.container}> <TouchableOpacity onPress={()=> { Alert.alert( '标题', '标题内容' ) }}> <Text>{'点击'}</Text> </TouchableOpacity> <TouchableOpacity onPress={()=> { Alert.alert( '标题', '标题内容', [ { text: '确定', onPress: ()=> { alert('我被点击了') } } ], { cancelable: true } ) }}> <Text>{'点击监听'}</Text> </TouchableOpacity> <TouchableOpacity onPress={()=> { Alert.alert( '标题', '标题内容', [ { text: '确定', onPress: ()=> { alert('我被点击了') } }, { text: '取消', onPress: ()=> { alert('我被点击了') } } ], { cancelable: false } ) }}> <Text>{'点击监听'}</Text> </TouchableOpacity> </View> ) }}
36、Appreister和AppState
Appreister:
export default class ExampleCode extends Component { constructor(props) { super(props); this.state = {} } componentDidMount() { AppRegistry.registerRunnable('aa', function (data) { alert(data[0] + data[1]) }); } render() { return ( <View style={styles.container}> <TouchableOpacity onPress={()=> { //注册了一个全局的方法 }} > <Text>{'注册'}</Text> </TouchableOpacity> <TouchableOpacity onPress={()=> { AppRegistry.runApplication('aa', ['hpc', 'hi']); }} > <Text>{'运行'}</Text> </TouchableOpacity> <TouchableOpacity onPress={()=> { var data = AppRegistry.getAppKeys(0); alert(data); }} > <Text>{'查询一下注册的方法'}</Text> </TouchableOpacity> </View> ) }}
AppState状态:
export default class ExampleCode extends Component { constructor(props) { super(props); this.state = { currentState: AppState.currentState } } componentDidMount() { AppState.addEventListener('change', this.changeState.bind(this)); } componentWillUnmount() { AppState.removeEventListener('change', this.changeState.bind(this)); } changeState(currentState) { this.setState({ currentState }) console.log(this.state.currentState); } render() { return ( <View style={styles.container}> <Text>{'app当前状态' + this.state.currentState}</Text> </View> ) }}const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center' }});
阅读全文
0 0
- React Native 第十天
- React Native 第十一天
- React Native 第十三天
- React native学习第十章:ListView
- React Native 第二天
- React Native 第四天
- React Native 第六天
- React Native 第十二天
- 安卓开发 第十一篇 初尝 React Native
- React Native学习第二天
- react native
- React Native
- React Native
- React- Native
- react-native
- React Native
- React Native
- react native
- ML、DL单词(1)
- leetcode-670-Maximum Swap
- 【51Nod1563】坐标轴上的最大团
- 处理一个表单有多个提交按钮
- canvas 旋转中心点 rotate translate
- React Native 第十天
- 五子棋学习(2)
- What is DB time in AWR?
- unittest 组织单元测试用例
- 删除该字scrStr符串中的所有delStr字符串
- [Leetcode] 394. Decode String 解题报告
- 深度学习之keras使用
- 杭电acm 1241Oil Deposits(dfs搜索入门题)
- POJ3278-Catch That Cow(bfs)