Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 在react native中从StackNavigator返回组件时出现问题。获取一个空白屏幕,但cosole.log正常_Reactjs_React Native_React Navigation_React Navigation Stack_React Navigation Drawer - Fatal编程技术网

Reactjs 在react native中从StackNavigator返回组件时出现问题。获取一个空白屏幕,但cosole.log正常

Reactjs 在react native中从StackNavigator返回组件时出现问题。获取一个空白屏幕,但cosole.log正常,reactjs,react-native,react-navigation,react-navigation-stack,react-navigation-drawer,Reactjs,React Native,React Navigation,React Navigation Stack,React Navigation Drawer,我想做的是在我的应用程序的最顶部安装一个名为MainNavigator的开关导航器,它重定向到一个加载屏幕,由加载屏幕确定用户是否已登录,并导航到AuthNavigator或AppNavigator。 AuthNavigator本身就是一个stackNavigator,可以显示“LoginScreen”或“SignUpScreen”屏幕。 AppNavigator是一款具有多屏幕配置文件、主页 我遇到的问题是,return方法似乎有效,因为我可以从“LoginScreen”组件在控制台中看到日志

我想做的是在我的应用程序的最顶部安装一个名为MainNavigator的开关导航器,它重定向到一个加载屏幕,由加载屏幕确定用户是否已登录,并导航到AuthNavigator或AppNavigator。 AuthNavigator本身就是一个stackNavigator,可以显示“LoginScreen”或“SignUpScreen”屏幕。 AppNavigator是一款具有多屏幕配置文件、主页

我遇到的问题是,return方法似乎有效,因为我可以从“LoginScreen”组件在控制台中看到日志,但在屏幕上,唯一的返回是白色屏幕。。当我使用以下命令从LoadingScreen组件直接调用我的“LoginScreen”组件时:

_bootstrapAsync = async () => {
const userToken = await AsyncStorage.getItem('userToken');

// This will switch to the App screen or Auth screen and this loading
// screen will be unmounted and thrown away. switched to develop the app
this.props.navigation.navigate(userToken ? 'App' : 'LoginScreen');

};
我在我的设备上呈现了LoginScreen组件

我知道问题来自我的AuthNavigator和AppNavigator,因为我可以从AuthLoading或MainNavigator返回屏幕组件 下面是一些代码:

 * Main Navigator: entry point of the app
 * Redirect to AuthLoadingScreen by default,
 * if user is signed (AsyncStorage) or successly signIn
 * redirect to AppNavigator else if user isn't SignIn
 * go to AuthNavigator

import { createAppContainer, createSwitchNavigator } from 'react- 
navigation';

import AuthNavigator from './auth/AuthNavigator'
import AppNavigator from './app/AppNavigator'
import AuthLoadingScreen from '../screens/auth/AuthLoadingScreen'


export default createAppContainer(createSwitchNavigator(
  {
  // You could add another route here for authentication.
  // Read more at https://reactnavigation.org/docs/en/auth-flow.html
  AuthLoading: AuthLoadingScreen,
  App: AppNavigator,
  Auth: AuthNavigator,
  },
  {
    initialRouteName: 'AuthLoading',
  }

  ));
授权加载:

import React from 'react';
import {
  ActivityIndicator,
  AsyncStorage,
  StatusBar,
  StyleSheet,
  View,
  Text
} from 'react-native';

export default class AuthLoadingScreen extends React.Component {
  constructor(props) {
    super(props);
    this._bootstrapAsync();
  }

  // Fetch the token from storage then navigate to our appropriate place
  _bootstrapAsync = async () => {
    const userToken = await AsyncStorage.getItem('userToken');

    // This will switch to the App screen or Auth screen and this loading
    // screen will be unmounted and thrown away. switched to develop the app
    this.props.navigation.navigate(userToken ? 'App' : 'Auth');
  };

  // Render any loading content that you like here
  render() {

    return (
      <View>
      <Text>Loading</Text>
        <ActivityIndicator />
        <StatusBar barStyle="default" />
      </View>
    );
  }
}
登录筛选:

import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';

export default class LoginScreen extends Component {
    render() {
      console.log('LOGIN SCREEN')
      return (
        <View style={styles.container}>
          <Text style={styles.text}>Login</Text>
        </View>
      );
    }
}


  const styles = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
    },
    text : {
      fontSize: 20,
    }
  });
我找不到错误,但我知道它来自AuthNavigator和AppNavigator。我可以看到“登录屏幕”或“应用屏幕”,如果我将AuthLoading路由设置为在控制台中呈现应用程序,但屏幕上没有任何内容,当我在MainNavigator中初始化新路由登录屏幕并从AuthLoading导航到该路由时,屏幕上会显示一个漂亮的文本

我知道这可能是一个明显的错误,但我自己花了几个小时来解决这个问题,却找不到,所以如果有人能帮我,那就太好了


提前谢谢

问题解决了。。。因为在app.js中我的应用程序的顶部,我像那样包装了我的MainNavigator

<View>
<StatusBar hidden={true} /> 
<MainNavigator />
</View>

所以我删除了视图和状态栏。。。它是有效的。4天来解决这个问题。。。我喜欢它!:'

我在安卓设备上仍然面临同样的问题,它在iOS设备上运行良好,但在安卓设备上运行不好。当从抽屉的另一个屏幕返回同一屏幕时,屏幕变为白色。
<View>
<StatusBar hidden={true} /> 
<MainNavigator />
</View>