1 Star 0 Fork 0

sqqlyd/rn-confirm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
App.js 3.77 KB
一键复制 编辑 原始数据 按行查看 历史
sqqlyd 提交于 2020-05-28 23:21 . hidden bottom navigation area buttons
import React, {Component} from 'react';
import {StyleSheet, View, Button, Alert} from 'react-native';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import AppInit from './views/AppInit';
import Home from './views/Home';
import Manage from './views/Manage';
import PrintPage from './views/PrintPage';
import ErrorPage from './views/ErrorPage';
import NetInfo from '@react-native-community/netinfo';
const HomeNavigation = createStackNavigator(
{
Home: {screen: Home},
Manage: {screen: Manage},
},
{initialRouteName: 'Home', headerMode: 'none'},
);
const NestNavigation = createStackNavigator(
{
HomeNavigation: {screen: HomeNavigation},
// Modal: {screen: Modal},
},
{initialRouteName: 'HomeNavigation', mode: 'modal', headerMode: 'none'},
);
const routes = {
AppInit: {
screen: AppInit,
navigationOptions: {
title: 'AppInit',
},
},
Home: {
screen: Home,
navigationOptions: {
title: 'Home',
},
},
Manage: {
screen: Manage,
navigationOptions: {
title: 'Manage',
},
},
PrintPage: {
screen: PrintPage,
navigationOptions: {
title: 'PrintPage',
},
},
ErrorPage: {
screen: ErrorPage,
navigationOptions: {
title: 'ErrorPage',
},
},
};
// const AppContainer = createAppContainer(NestNavigation);
type Props = {};
// const unsubscribe;
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
wifiChecking: true,
connectionInfo: {
type: 'none',
isConnected: false,
},
// defaultPage: 'AppInit',
defaultPage: 'Home',
};
}
async componentDidMount() {
// Subscribe
this.unsubscribe = NetInfo.addEventListener(state => {
this.checkWIFIStatus(state);
console.log('subscribe Connection type', state.type);
console.log('subscribe Is connected?', state.isConnected);
});
}
componentWillUnmount() {
this.unsubscribe();
console.log('>>>><<<<<<<< : componentWillUnmount');
}
getNetStatus() {
NetInfo.fetch().then(state => {
console.log('getNetStatus type', state.type);
console.log('getNetStatus IS connected?', state.isConnected);
this.setState({
wifiChecking: false,
connectionInfo: {
type: state.type,
isConnected: state.isConnected,
},
defaultPage:
// state.type == 'wifi' && state.isConnected ? 'PrintPage' : 'ErrorPage',
'Home',
});
});
}
/**
*
* @param {*} state
*/
async checkWIFIStatus(state) {
console.log('--- checkWIFIStatus');
if (state.type == 'wifi' && state.isConnected) {
this.setState({
wifiChecking: false,
connectionInfo: {
type: state.type,
isConnected: state.isConnected,
},
// defaultPage: 'PrintPage',
defaultPage: 'Home',
});
return new Promise(resolve =>
setTimeout(() => {
resolve('result');
}, 0),
);
} else {
this.setState({wifiChecking: true});
// setTimeout(this.getNetStatus(), 300000);
return new Promise(resolve =>
setTimeout(() => {
this.getNetStatus();
resolve('result');
}, 30000),
);
}
}
createDynamicRoutes = initiaRoute => {
return createAppContainer(
createStackNavigator(routes, {
initialRouteName: initiaRoute,
}),
);
};
render() {
console.log(
' --- Render >>> this.state.defaultPage :',
this.state.defaultPage,
);
const AppContainer = this.createDynamicRoutes(this.state.defaultPage);
return (
<AppContainer
ref={nav => {
this.navigator = nav;
}}
/>
);
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/sqqlyd/rn-confirm.git
[email protected]:sqqlyd/rn-confirm.git
sqqlyd
rn-confirm
rn-confirm
master

搜索帮助