Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.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
Javascript 世博项目中如何从一个屏幕切换到另一个屏幕?_Javascript_Android_Ios_React Native_Expo - Fatal编程技术网

Javascript 世博项目中如何从一个屏幕切换到另一个屏幕?

Javascript 世博项目中如何从一个屏幕切换到另一个屏幕?,javascript,android,ios,react-native,expo,Javascript,Android,Ios,React Native,Expo,我已经使用React native expo创建了一个应用程序,其中我有两个屏幕-Splash和Login。因此,在启动屏幕出现3秒钟后,它进入登录屏幕。现在,在登录屏幕中,我只想执行一项任务-通过单击登录按钮,我想将登录屏幕切换回初始屏幕。 下面我提供了我的三个类的代码- App.js import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import store from './s

我已经使用React native expo创建了一个应用程序,其中我有两个屏幕-Splash和Login。因此,在启动屏幕出现3秒钟后,它进入登录屏幕。现在,在登录屏幕中,我只想执行一项任务-通过单击登录按钮,我想将登录屏幕切换回初始屏幕。 下面我提供了我的三个类的代码-

App.js

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

import store from './src/store';
import {Provider} from 'react-redux';
import Splash from './src/Splash';
import Login from './src/Login';

export default class App extends React.Component {

  constructor(props) {
    super(props);
    this.state ={currentScreen:'Splash'};
    console.log('Start doing some tasks for about 3 seconds')

    setTimeout( ()=> {
      console.log('Done some tasks for about 3 second')
      this.setState({currentScreen: 'Login'})
    } , 3000)

  }

  render() {

      const {currentScreen} = this.state;

      let mainScreen = currentScreen === 'Splash' ?
      <Splash/> : <Login/>

      return mainScreen

  }
}
import React, {Component} from 'react';
import { StyleSheet, Text, View, Image, TouchableWithoutFeedback,
        StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOpacity,
        KeyboardAvoidingView } from 'react-native';



 class Login extends Component {
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content"/>
        <KeyboardAvoidingView
          behavior = "padding"
          style={styles.container}
        >
        
        <TouchableWithoutFeedback
          style = {styles.container}
          onPress = {Keyboard.dismiss}
        >
        
        <View style = {styles.logoContainer}>

          <View style = {styles.logoContainer}>


            <Text style={styles.title}>
              Account Information
            </Text>
          </View>

          <View style={styles.infoContainer}>

            <TextInput
              style = {styles.input}
              placeholder = "Enter User name/Email"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              keyboardType = 'email-address'
              returnKeyType = 'next'
              autoCorrect= {false}
              onSubmitEditing = {() => this.refs.txtPassword.focus()}
            />

          <TextInput
              style = {styles.input}
              placeholder = "Enter Password"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              returnKeyType = 'go'
              autoCorrect= {false}
              ref = {"textPassword"}
          />

          <TouchableOpacity style={styles.buttonContainer}>

            <Text style={styles.buttonText}>SIGN IN</Text>

          </TouchableOpacity>

          </View>

          </View>

        </TouchableWithoutFeedback>
        
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

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



 class Splash extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;
import React from "react";
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from "./Splash";
import Login from "./Login";

const AppNavigator = createStackNavigator({
  SplashScreen: {
    screen: SplashScreen
  },
  Login: {
    screen: Login
  }
});

export default createAppContainer(AppNavigator);

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

class Splash extends Component {
  constructor(props) {
    super(props);

    setTimeout(() => {
      props.navigation.navigate("Login");
    }, 3000);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  View,
  Image,
  TouchableWithoutFeedback,
  StatusBar,
  TextInput,
  SafeAreaView,
  Keyboard,
  TouchableOpacity,
  KeyboardAvoidingView
} from "react-native";

class Login extends Component {
  render() {
    const { navigation } = this.props;

    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content" />
        <KeyboardAvoidingView behavior="padding" style={styles.container}>
          <TouchableWithoutFeedback
            style={styles.container}
            onPress={Keyboard.dismiss}
          >
            <View style={styles.logoContainer}>
              <View style={styles.logoContainer}>
                <Text style={styles.title}>Account Information</Text>
              </View>

              <View style={styles.infoContainer}>
                <TextInput
                  style={styles.input}
                  placeholder="Enter User name/Email"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  keyboardType="email-address"
                  returnKeyType="next"
                  autoCorrect={false}
                  onSubmitEditing={() => this.refs.txtPassword.focus()}
                />

                <TextInput
                  style={styles.input}
                  placeholder="Enter Password"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  returnKeyType="go"
                  autoCorrect={false}
                  ref={"textPassword"}
                />

                <TouchableOpacity style={styles.buttonContainer} onPress={() => navigation.navigate("SplashScreen")}>
                  <Text style={styles.buttonText}>SIGN IN</Text>
                </TouchableOpacity>
              </View>
            </View>
          </TouchableWithoutFeedback>
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

export default Login;

从“React”导入React;
从“react native”导入{样式表、文本、视图};
从“./src/store”导入存储;
从'react redux'导入{Provider};
从“/src/Splash”导入飞溅;
从“./src/Login”导入登录名;
导出默认类App扩展React.Component{
建造师(道具){
超级(道具);
this.state={currentScreen:'Splash'};
log('开始执行一些任务大约3秒钟')
设置超时(()=>{
log('完成一些任务大约3秒钟')
this.setState({currentScreen:'Login'})
} , 3000)
}
render(){
const{currentScreen}=this.state;
让mainScreen=currentScreen==='Splash'?
: 
返回主屏幕
}
}
Login.js

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

import store from './src/store';
import {Provider} from 'react-redux';
import Splash from './src/Splash';
import Login from './src/Login';

export default class App extends React.Component {

  constructor(props) {
    super(props);
    this.state ={currentScreen:'Splash'};
    console.log('Start doing some tasks for about 3 seconds')

    setTimeout( ()=> {
      console.log('Done some tasks for about 3 second')
      this.setState({currentScreen: 'Login'})
    } , 3000)

  }

  render() {

      const {currentScreen} = this.state;

      let mainScreen = currentScreen === 'Splash' ?
      <Splash/> : <Login/>

      return mainScreen

  }
}
import React, {Component} from 'react';
import { StyleSheet, Text, View, Image, TouchableWithoutFeedback,
        StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOpacity,
        KeyboardAvoidingView } from 'react-native';



 class Login extends Component {
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content"/>
        <KeyboardAvoidingView
          behavior = "padding"
          style={styles.container}
        >
        
        <TouchableWithoutFeedback
          style = {styles.container}
          onPress = {Keyboard.dismiss}
        >
        
        <View style = {styles.logoContainer}>

          <View style = {styles.logoContainer}>


            <Text style={styles.title}>
              Account Information
            </Text>
          </View>

          <View style={styles.infoContainer}>

            <TextInput
              style = {styles.input}
              placeholder = "Enter User name/Email"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              keyboardType = 'email-address'
              returnKeyType = 'next'
              autoCorrect= {false}
              onSubmitEditing = {() => this.refs.txtPassword.focus()}
            />

          <TextInput
              style = {styles.input}
              placeholder = "Enter Password"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              returnKeyType = 'go'
              autoCorrect= {false}
              ref = {"textPassword"}
          />

          <TouchableOpacity style={styles.buttonContainer}>

            <Text style={styles.buttonText}>SIGN IN</Text>

          </TouchableOpacity>

          </View>

          </View>

        </TouchableWithoutFeedback>
        
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

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



 class Splash extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;
import React from "react";
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from "./Splash";
import Login from "./Login";

const AppNavigator = createStackNavigator({
  SplashScreen: {
    screen: SplashScreen
  },
  Login: {
    screen: Login
  }
});

export default createAppContainer(AppNavigator);

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

class Splash extends Component {
  constructor(props) {
    super(props);

    setTimeout(() => {
      props.navigation.navigate("Login");
    }, 3000);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  View,
  Image,
  TouchableWithoutFeedback,
  StatusBar,
  TextInput,
  SafeAreaView,
  Keyboard,
  TouchableOpacity,
  KeyboardAvoidingView
} from "react-native";

class Login extends Component {
  render() {
    const { navigation } = this.props;

    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content" />
        <KeyboardAvoidingView behavior="padding" style={styles.container}>
          <TouchableWithoutFeedback
            style={styles.container}
            onPress={Keyboard.dismiss}
          >
            <View style={styles.logoContainer}>
              <View style={styles.logoContainer}>
                <Text style={styles.title}>Account Information</Text>
              </View>

              <View style={styles.infoContainer}>
                <TextInput
                  style={styles.input}
                  placeholder="Enter User name/Email"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  keyboardType="email-address"
                  returnKeyType="next"
                  autoCorrect={false}
                  onSubmitEditing={() => this.refs.txtPassword.focus()}
                />

                <TextInput
                  style={styles.input}
                  placeholder="Enter Password"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  returnKeyType="go"
                  autoCorrect={false}
                  ref={"textPassword"}
                />

                <TouchableOpacity style={styles.buttonContainer} onPress={() => navigation.navigate("SplashScreen")}>
                  <Text style={styles.buttonText}>SIGN IN</Text>
                </TouchableOpacity>
              </View>
            </View>
          </TouchableWithoutFeedback>
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

export default Login;

import React,{Component}来自'React';
导入{样式表、文本、视图、图像、可触摸,无需反馈,
状态栏、文本输入、安全区域视图、键盘、可触摸不透明度、,
键盘avoidingview}来自“react native”;
类登录扩展组件{
render(){
返回(
帐户信息
this.refs.txtPassword.focus()}
/>
登录
);
}
}
导出默认登录;
Splash.js

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

import store from './src/store';
import {Provider} from 'react-redux';
import Splash from './src/Splash';
import Login from './src/Login';

export default class App extends React.Component {

  constructor(props) {
    super(props);
    this.state ={currentScreen:'Splash'};
    console.log('Start doing some tasks for about 3 seconds')

    setTimeout( ()=> {
      console.log('Done some tasks for about 3 second')
      this.setState({currentScreen: 'Login'})
    } , 3000)

  }

  render() {

      const {currentScreen} = this.state;

      let mainScreen = currentScreen === 'Splash' ?
      <Splash/> : <Login/>

      return mainScreen

  }
}
import React, {Component} from 'react';
import { StyleSheet, Text, View, Image, TouchableWithoutFeedback,
        StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOpacity,
        KeyboardAvoidingView } from 'react-native';



 class Login extends Component {
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content"/>
        <KeyboardAvoidingView
          behavior = "padding"
          style={styles.container}
        >
        
        <TouchableWithoutFeedback
          style = {styles.container}
          onPress = {Keyboard.dismiss}
        >
        
        <View style = {styles.logoContainer}>

          <View style = {styles.logoContainer}>


            <Text style={styles.title}>
              Account Information
            </Text>
          </View>

          <View style={styles.infoContainer}>

            <TextInput
              style = {styles.input}
              placeholder = "Enter User name/Email"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              keyboardType = 'email-address'
              returnKeyType = 'next'
              autoCorrect= {false}
              onSubmitEditing = {() => this.refs.txtPassword.focus()}
            />

          <TextInput
              style = {styles.input}
              placeholder = "Enter Password"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              returnKeyType = 'go'
              autoCorrect= {false}
              ref = {"textPassword"}
          />

          <TouchableOpacity style={styles.buttonContainer}>

            <Text style={styles.buttonText}>SIGN IN</Text>

          </TouchableOpacity>

          </View>

          </View>

        </TouchableWithoutFeedback>
        
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

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



 class Splash extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;
import React from "react";
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from "./Splash";
import Login from "./Login";

const AppNavigator = createStackNavigator({
  SplashScreen: {
    screen: SplashScreen
  },
  Login: {
    screen: Login
  }
});

export default createAppContainer(AppNavigator);

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

class Splash extends Component {
  constructor(props) {
    super(props);

    setTimeout(() => {
      props.navigation.navigate("Login");
    }, 3000);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  View,
  Image,
  TouchableWithoutFeedback,
  StatusBar,
  TextInput,
  SafeAreaView,
  Keyboard,
  TouchableOpacity,
  KeyboardAvoidingView
} from "react-native";

class Login extends Component {
  render() {
    const { navigation } = this.props;

    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content" />
        <KeyboardAvoidingView behavior="padding" style={styles.container}>
          <TouchableWithoutFeedback
            style={styles.container}
            onPress={Keyboard.dismiss}
          >
            <View style={styles.logoContainer}>
              <View style={styles.logoContainer}>
                <Text style={styles.title}>Account Information</Text>
              </View>

              <View style={styles.infoContainer}>
                <TextInput
                  style={styles.input}
                  placeholder="Enter User name/Email"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  keyboardType="email-address"
                  returnKeyType="next"
                  autoCorrect={false}
                  onSubmitEditing={() => this.refs.txtPassword.focus()}
                />

                <TextInput
                  style={styles.input}
                  placeholder="Enter Password"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  returnKeyType="go"
                  autoCorrect={false}
                  ref={"textPassword"}
                />

                <TouchableOpacity style={styles.buttonContainer} onPress={() => navigation.navigate("SplashScreen")}>
                  <Text style={styles.buttonText}>SIGN IN</Text>
                </TouchableOpacity>
              </View>
            </View>
          </TouchableWithoutFeedback>
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

export default Login;

import React,{Component}来自'React';
从“react native”导入{样式表、文本、视图};
类Splash扩展组件{
render(){
返回(
你好,水花
);
}
}
导出默认飞溅;
然后我使用下面的命令安装了react导航-

npm安装--保存反应导航

然后是世博会的报告-


但他们都没有按照计划工作。所以,我只需要一个简单的解决方案,通过按登录按钮从登录屏幕转到启动屏幕。如果有人能帮我,那就太好了。

更改App.js的代码。您已经安装了react导航。 App.js:


您可以使用
react导航
从启动屏幕导航到登录和返回

我对你的代码做了一些更改

App.js

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

import store from './src/store';
import {Provider} from 'react-redux';
import Splash from './src/Splash';
import Login from './src/Login';

export default class App extends React.Component {

  constructor(props) {
    super(props);
    this.state ={currentScreen:'Splash'};
    console.log('Start doing some tasks for about 3 seconds')

    setTimeout( ()=> {
      console.log('Done some tasks for about 3 second')
      this.setState({currentScreen: 'Login'})
    } , 3000)

  }

  render() {

      const {currentScreen} = this.state;

      let mainScreen = currentScreen === 'Splash' ?
      <Splash/> : <Login/>

      return mainScreen

  }
}
import React, {Component} from 'react';
import { StyleSheet, Text, View, Image, TouchableWithoutFeedback,
        StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOpacity,
        KeyboardAvoidingView } from 'react-native';



 class Login extends Component {
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content"/>
        <KeyboardAvoidingView
          behavior = "padding"
          style={styles.container}
        >
        
        <TouchableWithoutFeedback
          style = {styles.container}
          onPress = {Keyboard.dismiss}
        >
        
        <View style = {styles.logoContainer}>

          <View style = {styles.logoContainer}>


            <Text style={styles.title}>
              Account Information
            </Text>
          </View>

          <View style={styles.infoContainer}>

            <TextInput
              style = {styles.input}
              placeholder = "Enter User name/Email"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              keyboardType = 'email-address'
              returnKeyType = 'next'
              autoCorrect= {false}
              onSubmitEditing = {() => this.refs.txtPassword.focus()}
            />

          <TextInput
              style = {styles.input}
              placeholder = "Enter Password"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              returnKeyType = 'go'
              autoCorrect= {false}
              ref = {"textPassword"}
          />

          <TouchableOpacity style={styles.buttonContainer}>

            <Text style={styles.buttonText}>SIGN IN</Text>

          </TouchableOpacity>

          </View>

          </View>

        </TouchableWithoutFeedback>
        
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

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



 class Splash extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;
import React from "react";
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from "./Splash";
import Login from "./Login";

const AppNavigator = createStackNavigator({
  SplashScreen: {
    screen: SplashScreen
  },
  Login: {
    screen: Login
  }
});

export default createAppContainer(AppNavigator);

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

class Splash extends Component {
  constructor(props) {
    super(props);

    setTimeout(() => {
      props.navigation.navigate("Login");
    }, 3000);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  View,
  Image,
  TouchableWithoutFeedback,
  StatusBar,
  TextInput,
  SafeAreaView,
  Keyboard,
  TouchableOpacity,
  KeyboardAvoidingView
} from "react-native";

class Login extends Component {
  render() {
    const { navigation } = this.props;

    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content" />
        <KeyboardAvoidingView behavior="padding" style={styles.container}>
          <TouchableWithoutFeedback
            style={styles.container}
            onPress={Keyboard.dismiss}
          >
            <View style={styles.logoContainer}>
              <View style={styles.logoContainer}>
                <Text style={styles.title}>Account Information</Text>
              </View>

              <View style={styles.infoContainer}>
                <TextInput
                  style={styles.input}
                  placeholder="Enter User name/Email"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  keyboardType="email-address"
                  returnKeyType="next"
                  autoCorrect={false}
                  onSubmitEditing={() => this.refs.txtPassword.focus()}
                />

                <TextInput
                  style={styles.input}
                  placeholder="Enter Password"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  returnKeyType="go"
                  autoCorrect={false}
                  ref={"textPassword"}
                />

                <TouchableOpacity style={styles.buttonContainer} onPress={() => navigation.navigate("SplashScreen")}>
                  <Text style={styles.buttonText}>SIGN IN</Text>
                </TouchableOpacity>
              </View>
            </View>
          </TouchableWithoutFeedback>
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

export default Login;

Splash.js

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

import store from './src/store';
import {Provider} from 'react-redux';
import Splash from './src/Splash';
import Login from './src/Login';

export default class App extends React.Component {

  constructor(props) {
    super(props);
    this.state ={currentScreen:'Splash'};
    console.log('Start doing some tasks for about 3 seconds')

    setTimeout( ()=> {
      console.log('Done some tasks for about 3 second')
      this.setState({currentScreen: 'Login'})
    } , 3000)

  }

  render() {

      const {currentScreen} = this.state;

      let mainScreen = currentScreen === 'Splash' ?
      <Splash/> : <Login/>

      return mainScreen

  }
}
import React, {Component} from 'react';
import { StyleSheet, Text, View, Image, TouchableWithoutFeedback,
        StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOpacity,
        KeyboardAvoidingView } from 'react-native';



 class Login extends Component {
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content"/>
        <KeyboardAvoidingView
          behavior = "padding"
          style={styles.container}
        >
        
        <TouchableWithoutFeedback
          style = {styles.container}
          onPress = {Keyboard.dismiss}
        >
        
        <View style = {styles.logoContainer}>

          <View style = {styles.logoContainer}>


            <Text style={styles.title}>
              Account Information
            </Text>
          </View>

          <View style={styles.infoContainer}>

            <TextInput
              style = {styles.input}
              placeholder = "Enter User name/Email"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              keyboardType = 'email-address'
              returnKeyType = 'next'
              autoCorrect= {false}
              onSubmitEditing = {() => this.refs.txtPassword.focus()}
            />

          <TextInput
              style = {styles.input}
              placeholder = "Enter Password"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              returnKeyType = 'go'
              autoCorrect= {false}
              ref = {"textPassword"}
          />

          <TouchableOpacity style={styles.buttonContainer}>

            <Text style={styles.buttonText}>SIGN IN</Text>

          </TouchableOpacity>

          </View>

          </View>

        </TouchableWithoutFeedback>
        
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

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



 class Splash extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;
import React from "react";
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from "./Splash";
import Login from "./Login";

const AppNavigator = createStackNavigator({
  SplashScreen: {
    screen: SplashScreen
  },
  Login: {
    screen: Login
  }
});

export default createAppContainer(AppNavigator);

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

class Splash extends Component {
  constructor(props) {
    super(props);

    setTimeout(() => {
      props.navigation.navigate("Login");
    }, 3000);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  View,
  Image,
  TouchableWithoutFeedback,
  StatusBar,
  TextInput,
  SafeAreaView,
  Keyboard,
  TouchableOpacity,
  KeyboardAvoidingView
} from "react-native";

class Login extends Component {
  render() {
    const { navigation } = this.props;

    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content" />
        <KeyboardAvoidingView behavior="padding" style={styles.container}>
          <TouchableWithoutFeedback
            style={styles.container}
            onPress={Keyboard.dismiss}
          >
            <View style={styles.logoContainer}>
              <View style={styles.logoContainer}>
                <Text style={styles.title}>Account Information</Text>
              </View>

              <View style={styles.infoContainer}>
                <TextInput
                  style={styles.input}
                  placeholder="Enter User name/Email"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  keyboardType="email-address"
                  returnKeyType="next"
                  autoCorrect={false}
                  onSubmitEditing={() => this.refs.txtPassword.focus()}
                />

                <TextInput
                  style={styles.input}
                  placeholder="Enter Password"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  returnKeyType="go"
                  autoCorrect={false}
                  ref={"textPassword"}
                />

                <TouchableOpacity style={styles.buttonContainer} onPress={() => navigation.navigate("SplashScreen")}>
                  <Text style={styles.buttonText}>SIGN IN</Text>
                </TouchableOpacity>
              </View>
            </View>
          </TouchableWithoutFeedback>
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

export default Login;

import React,{Component}来自“React”;
从“react native”导入{样式表、文本、视图};
类Splash扩展组件{
建造师(道具){
超级(道具);
设置超时(()=>{
道具。导航。导航(“登录”);
}, 3000);
}
render(){
返回(
你好,水花
);
}
}
导出默认飞溅;
Login.js

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

import store from './src/store';
import {Provider} from 'react-redux';
import Splash from './src/Splash';
import Login from './src/Login';

export default class App extends React.Component {

  constructor(props) {
    super(props);
    this.state ={currentScreen:'Splash'};
    console.log('Start doing some tasks for about 3 seconds')

    setTimeout( ()=> {
      console.log('Done some tasks for about 3 second')
      this.setState({currentScreen: 'Login'})
    } , 3000)

  }

  render() {

      const {currentScreen} = this.state;

      let mainScreen = currentScreen === 'Splash' ?
      <Splash/> : <Login/>

      return mainScreen

  }
}
import React, {Component} from 'react';
import { StyleSheet, Text, View, Image, TouchableWithoutFeedback,
        StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOpacity,
        KeyboardAvoidingView } from 'react-native';



 class Login extends Component {
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content"/>
        <KeyboardAvoidingView
          behavior = "padding"
          style={styles.container}
        >
        
        <TouchableWithoutFeedback
          style = {styles.container}
          onPress = {Keyboard.dismiss}
        >
        
        <View style = {styles.logoContainer}>

          <View style = {styles.logoContainer}>


            <Text style={styles.title}>
              Account Information
            </Text>
          </View>

          <View style={styles.infoContainer}>

            <TextInput
              style = {styles.input}
              placeholder = "Enter User name/Email"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              keyboardType = 'email-address'
              returnKeyType = 'next'
              autoCorrect= {false}
              onSubmitEditing = {() => this.refs.txtPassword.focus()}
            />

          <TextInput
              style = {styles.input}
              placeholder = "Enter Password"
              placeholderTextColor = 'rgba(255,255,255,0.8)'
              returnKeyType = 'go'
              autoCorrect= {false}
              ref = {"textPassword"}
          />

          <TouchableOpacity style={styles.buttonContainer}>

            <Text style={styles.buttonText}>SIGN IN</Text>

          </TouchableOpacity>

          </View>

          </View>

        </TouchableWithoutFeedback>
        
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

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



 class Splash extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;
import React from "react";
import { createStackNavigator, createAppContainer } from "react-navigation";
import SplashScreen from "./Splash";
import Login from "./Login";

const AppNavigator = createStackNavigator({
  SplashScreen: {
    screen: SplashScreen
  },
  Login: {
    screen: Login
  }
});

export default createAppContainer(AppNavigator);

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

class Splash extends Component {
  constructor(props) {
    super(props);

    setTimeout(() => {
      props.navigation.navigate("Login");
    }, 3000);
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.title}>Hello Splash</Text>
      </View>
    );
  }
}

export default Splash;

import React, { Component } from "react";
import {
  StyleSheet,
  Text,
  View,
  Image,
  TouchableWithoutFeedback,
  StatusBar,
  TextInput,
  SafeAreaView,
  Keyboard,
  TouchableOpacity,
  KeyboardAvoidingView
} from "react-native";

class Login extends Component {
  render() {
    const { navigation } = this.props;

    return (
      <SafeAreaView style={styles.container}>
        <StatusBar barStyle="light-content" />
        <KeyboardAvoidingView behavior="padding" style={styles.container}>
          <TouchableWithoutFeedback
            style={styles.container}
            onPress={Keyboard.dismiss}
          >
            <View style={styles.logoContainer}>
              <View style={styles.logoContainer}>
                <Text style={styles.title}>Account Information</Text>
              </View>

              <View style={styles.infoContainer}>
                <TextInput
                  style={styles.input}
                  placeholder="Enter User name/Email"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  keyboardType="email-address"
                  returnKeyType="next"
                  autoCorrect={false}
                  onSubmitEditing={() => this.refs.txtPassword.focus()}
                />

                <TextInput
                  style={styles.input}
                  placeholder="Enter Password"
                  placeholderTextColor="rgba(255,255,255,0.8)"
                  returnKeyType="go"
                  autoCorrect={false}
                  ref={"textPassword"}
                />

                <TouchableOpacity style={styles.buttonContainer} onPress={() => navigation.navigate("SplashScreen")}>
                  <Text style={styles.buttonText}>SIGN IN</Text>
                </TouchableOpacity>
              </View>
            </View>
          </TouchableWithoutFeedback>
        </KeyboardAvoidingView>
      </SafeAreaView>
    );
  }
}

export default Login;

import React,{Component}来自“React”;
进口{
样式表,
文本,
看法
形象,,
可触摸且无反馈,
状态栏,
文本输入,
安全区域视图,
键盘
可触摸不透明度,
键盘回避视图
}从“反应本族语”;
类登录扩展组件{
render(){
const{navigation}=this.props;
返回(
帐户信息
this.refs.txtPassword.focus()}
/>
导航。导航(“SplashScreen”)}>
登录
);
}
}
导出默认登录;
我还建议阅读
react导航
的文档。这里给出的例子很简单


请添加一些有关此代码的功能以及如何解决问题的详细信息,它会使答案更有用在遵循您的说明后,它会显示以下错误:不变冲突:此导航器缺少导航道具。在react-navigation 3中,您必须直接设置应用程序容器。我正在使用另一个库“react navigation helper”。请安装,然后它将工作。npm insall--保存导航帮助更多详细信息:非常感谢您的评论。但是你可以看到我在不同的js文件中分离了我的类,并且我只能从一个js文件中导出一个默认值。那么,是否可以通过在不同的js文件(App.js、Login.js、Splash.js)中分离类来实现这一点呢?是的,只要使用相同的代码并将它们放在不同的js文件中就行了。我和你说的一模一样。但是现在出现了一个问题,我可以在我的应用程序中看到一个工具栏,在登录屏幕上,它的工具栏上有一个左箭头按钮。点击后,我可以进入启动屏幕。但有趣的是,按登录按钮不起作用。