react native AppState 使用详解
来源:互联网 发布:ktv手机点歌软件 编辑:程序博客网 时间:2024/06/05 22:47
AppState:当前app的状态,是在前台还是在后台。
- active:应用正在前台运行
- background:正在后台运行
- inactive:过渡状态,不会在正常的React Native应用中出现
属性:
addEventListener:添加监听,
removeEventListener:删除监听
demo:
/** * Created by on 2017/5/31. */import React, {Component} from 'react';import { StyleSheet, View, Text, AppState,} from 'react-native';export default class AppStateDemo extends Component { static navigationOptions = { title: 'AppState' } state = { currentAppState:AppState.currentState, } componentDidMount() { AppState.addEventListener('change', this._handleAppStateChange); } componentWillUnmount() { AppState.removeEventListener('change', this._handleAppStateChange); } _handleAppStateChange = (nextAppState) => { this.setState({currentAppState: nextAppState}); } render() { return ( <View style={{flex:1}}> <Text>当前 state 是: {this.state.currentAppState}</Text> </View> ); }}
github下载地址
阅读全文
0 0
- react native AppState 使用详解
- react native ActivityIndicator使用详解
- react native Button 使用详解
- react native Text 使用详解
- react native Switch使用详解
- react native ScrollView 使用详解
- react native FlatList 使用详解
- react native SectionList 使用详解
- react native TextInput 使用详解
- react native Slider 使用详解
- react native StatusBar 使用详解
- react native DatePickerIOS 使用详解
- react native DrawerLayoutAndroid 使用详解
- react native Image 使用详解
- react native Modal 使用详解
- react native Picker 使用详解
- react native ProgressBarAndroid 使用详解
- react native RefreshControl 使用详解
- Laravel 5 程序优化技巧
- C++ 差集
- 各种导航
- 一次关于loback日志无法输出到文件的问题解决
- jquery无限加载
- react native AppState 使用详解
- Linux与生物信息(第一章——Linux常用命令3)
- ubuntu下下载Oracle VM VirtualBox Extension Pack
- C#委托介绍(delegate、Action、Func、predicate)(二)
- 指针-输入3个数,调用函数,从大到小排列输出
- 量化进阶——如何用量化角度看待传统技术分析
- Sql Server查询10-20条的数据
- 第八届蓝桥杯国赛心得
- 三分套三分(bzoj4885)