卡在启动画面上

时间:2019-05-30 20:43:50

标签: react-native react-navigation splash-screen

添加了一个启动屏幕,以在Android模拟器上使用本机(0.59)应用程序与React导航(3.9)进行响应。这是组件$user1 = Read-Host "Terminated User: " Move-ADObject -Identity $user1.distinguishedName -TargetPath "OU=DisabledAccounts,DC=nfii,DC=com"

SplashScreen

安装初始屏幕后,将检索本地数据。然后将检索到的import React, { Component} from 'react'; import {Platform, StyleSheet, Text, View} from 'react-native'; import helper from "../../lib/helper"; class SplashScreen extends React.Component { performTimeConsumingTask = async() => { var result, user; try { result = await helper.getJwtToken(); if (result) { user = await helper._getUser(result.password, result.username); if (user) { return { user, result, success: true } } else { return { user: null, result: result, success: true } }; } else { return { user: null, result: null, success: true }; }; } catch (err) { console.log("Error in retrieving token : ", err); return { success: false, error: err.message }; }; } async componentDidMount() { const data = await this.performTimeConsumingTask(); if (data !== null && data.user !== null && data.success === true) { this.props.navigation.navigate('App', {params : data}); } } render() { return ( <View style={styles.viewStyles}> <Text style={styles.textStyles}> Blitz Reading </Text> </View> ); } } const styles = { viewStyles: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'orange' }, textStyles: { color: 'white', fontSize: 40, fontWeight: 'bold' } } export default SplashScreen; 作为参数传递回data。这是App.js

App.js

除了应在初始屏幕之后加载的import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View} from 'react-native'; import { createBottomTabNavigator, createSwitchNavigator, createStackNavigator, createAppContainer } from 'react-navigation'; import Event from './src/components/event/Event.js'; import Chat from './src/components/chat/Chat.js'; import Signup from "./src/components/signup/Signup.js"; import Verif1 from "./src/components/signup/Verif1.js"; import NewEvent from "./src/components/event/Newevent.js"; import EditUser from "./src/components/user/Edituser"; import NewUser from "./src/components/user/Newuser"; import io from 'socket.io-client'; import GLOBAL from "./src/lib/global"; import SplashScreen from "./src/components/splashscreen/SplashScreen"; const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', }); //socket.io const socket = io(GLOBAL.BASE_URL, { //const socket = io(GLOBAL.BASE_URL, { transports: ['websocket'], jsonp: false }); console.log("socket id in App.js : ", socket.id); socket.on('disconnect', (reason) => { // ... if (reason === 'io server disconnect') { socket.connect(); } // else the socket will automatically try to reconnect }); console.log("In App.js, token retrieved is : ", this.props); const ChatWithSocket = (props) => (<Chat {...props} socket={socket} />) //create the navigator const EventStack = createStackNavigator( { Event: Event, NewEvent: NewEvent, Chat: { screen: ChatWithSocket, }, Signup: Signup, Verif1: Verif1, }, { initialRouteName: 'Verif1', } ); const UserStack = createStackNavigator( { NewUser: NewUser, EditUser: EditUser, }, { initialRouteName: "NewUser", } ); const bottomTabNav = createBottomTabNavigator( { Event: {screen: EventStack}, User: {screen: UserStack}, }, { defaultNavigationOptions: ({ navigation }) => ({ tabBarIcon: ({ focused, tintColor }) => { const { routeName } = navigation.state; let iconName; if (routeName === 'Event') { iconName = `ios-information-circle${focused ? '' : '-outline'}`; } else if (routeName === 'NewUser') { iconName = `ios-options${focused ? '' : '-outline'}`; } return <Text>Hello the world!</Text> }, }), tabBarOptions: { activeTintColor: 'tomato', inactiveTintColor: 'gray', }, } ); const InitialNavigator = createSwitchNavigator({ Splash: SplashScreen, App: bottomTabNav, }); const AppContainer = createAppContainer(InitialNavigator); export default AppContainer; 屏幕之外,初始屏幕已添加到InitialNavigator。这是应用程序日志(console.log已从代码中删除,以便于阅读):

App

似乎初始屏幕已成功渲染,但未检索到任何内容(正确!)。问题是该应用卡在启动屏幕上并且无法继续运行。

0 个答案:

没有答案