简体   繁体   English

反应本机导航不按按钮切换屏幕

[英]React Native Navigation Not Switching Screens On Button Press

I am trying to go from one screen to the next in my react-native application but nothing is happening when the button is selected.我正在尝试在react-native应用程序中从一个屏幕到另一个屏幕到go,但是选择按钮时什么也不会发生。 I am using a Stack Navigation and from all other research I have done it seems as though my pages are setup correctly please let me know if you see any problems.我正在使用堆栈导航,从我所做的所有其他研究来看,我的页面似乎设置正确,如果您发现任何问题,请告诉我。

Root Stack根堆栈

 import React from 'react' import {createSwitchNavigator} from 'react-navigation' import AuthNavigator from './stacks/AuthNavigator' /** * This document handles manging the switch navigatiors for the supplied stacks * This means that each navigator mentioned in this file contains other navigators in their files */ const RootStack = createSwitchNavigator( { Auth: AuthNavigator }, { initialRouteName: 'Auth' } ) export default RootStack

AuthNavigator.JS AuthNavigator.JS

 import React from 'react' import {createStackNavigator} from 'react-navigation-stack' import LoginSignUpView from '../../../src/page/account/LoginSignUpView' import SignUpView from '../../../src/page/account/SignUpView' const AuthNavigator = createStackNavigator( { "LoginSignUpView": LoginSignUpView, "SignUpView": SignUpView, }, { initialRouteName: "LoginSignUpView" } );

LoginSignupView (With Button Not Working) LoginSignupView(按钮不起作用)

 import React, {Component} from 'react' import {View, ScrollView, Text, Image} from 'react-native' import LaunchOptions from '../../components/applaunch/LaunchOptions' import LaunchButtonStyle from '/Users/Documents/Mobile Applications/src/styles/Launch/LaunchButtonsStyle.styles.js' import LaunchButton from '../../components/applaunch/LaunchButton' import ImageStylesStyles from '../../styles/common/ImageStyles.styles' /** * This page allows a user to have the option to login or sign up to the application * This page is the main controller of the Login/SignUp View... All components should be placed here. * User will look at this view */ class LoginSignUpView extends Component { // NEED TO CHANGE NAVIGATION BAR COLOR -- CHECKOUT HOW BOOKIT IS DOING THIS static navigationOptions = { title: 'The Plug ', headerStyle: {backgroundColor: 'black'}, headerTitleStyle: {color: 'white', fontFamily: 'Impact', fontSize: 30}, }; render(){ return( <ScrollView style= {{backgroundColor: 'black'}}> <View> <Image source = {require('../../Images/FontSearch.png')} style = {ImageStylesStyles.logoDefaultStyle} /> <LaunchOptions text={'Create Account'} //-----------------------BUTTON NOT WORKING HERE VVVVV onPress={() => this.props.navigation.navigate("SignUpView")} buttonStyle={LaunchButtonStyle.largeRoundBtn} textStyle={LaunchButtonStyle.textStyle} /> </View> <View style={{ borderBottomColor: 'white', borderBottomWidth: 1,marginTop: 40 }} /> <View> <LaunchButton text={"Already have an account? Login"} onPress={"props.OnPress"} textStyle={LaunchButtonStyle.smallLgnSignupBtnTextStyle} /> </View> </ScrollView> ) } } export default LoginSignUpView

LaunchOptions:启动选项:

 import React from 'react' import {View, Text, ScrollView} from 'react-native' import launchTextStyle from '/Users/Documents/Mobile Applications/ThePlugNetwork/src/styles/loginSignUpTextStyle.styles.js' import Button from '/Users/Documents/Mobile Applications/src/components/common/Button.js' /** * Application Launch View for user to select to login or signup * * @param {*} props */ const LaunchOptions = (props) => { return( <ScrollView> <View> <Text style={launchTextStyle.bigTextTop}>Stay</Text> <Text style={launchTextStyle.bigText}>Connected</Text> <Text style={launchTextStyle.mediumText}>With The Latest</Text> <Text style={launchTextStyle.smallText}>Government Updates</Text> </View> <View> <Button onPress={props.OnPress} buttonStyle={props.buttonStyle} textStyle={props.textStyle} > {props.text} </Button> </View> </ScrollView> ) } export default LaunchOptions

I found an error in your code.我在你的代码中发现了一个错误。 You are passing "onPress" function to LaunchOptions component as a prop but you are calling "props.OnPress" instead you should call "props.onPress"您正在将“onPress” function 作为道具传递给 LaunchOptions 组件,但您正在调用“props.OnPress”而不是您应该调用“props.onPress”

Suggestion: you should declare a constructor in the LoginSignupView screen like this建议:您应该像这样在 LoginSignupView 屏幕中声明一个构造函数

constructor(props){
   super(props)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过按下按钮切换屏幕反应原生 - Screen switching by press on button react native 使用 React Native Navigation 在屏幕之间切换并导入 JS - Switching Between Screens with React Native Navigation and importing JS 在 React Native 导航屏幕之间切换时,PanGesture 动画不起作用 - PanGesture animation does not work when switching between react native navigation screens 反应导航在按钮按下时不起作用 - React navigation not working on button press React Native Navigation 将所有屏幕包裹在一个视图中 - React Native Navigation Wrap All Screens in a View 屏幕之间的本机导航 - react-native navigation between screens 导航器组件是在本机应用程序中切换屏幕的唯一方法吗? - Is the Navigator component the only way of switching screens in a react-native app? React Native:设置 React Navigation 的屏幕标题 - React Native: Set React Navigation's Screens Headers 在 React Native 中使用 Context 和 React Navigation 处理嵌套屏幕上的更新 - Handling updates on nested screens using Context and React Navigation in React Native 在React-Native中使用按钮按下从抽屉导航屏幕到抽屉导航屏幕的方法是什么? - What is the way to go from Drawer Navigation Screen to a Screen out of Drawer navigation using button press in React-Native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM