Ошибка типа: undefined не является объектом (оценивается как «navigation.state.params.currentRoutine»)? - PullRequest
0 голосов
/ 08 апреля 2020

По какой-то причине я продолжаю получать эту ошибку "Ошибка типа: undefined не является объектом (оценивается как" navigation.state.params.currentRoutine ') ". this.props.navigation.navigate ('ParentRoutines') Когда я пытаюсь перейти к ParentRoutine, он говорит об этой ошибке, у меня также есть страница входа в систему с именем login, и при переходе к ней не возникает никаких ошибок. На родительском экране содержится файл ParentRoutines. Я не уверен, есть ли другой способ перехода к нему.

import React, { Component } from 'react';
//import { View, Alert } from 'react-native'

import {
  Alert,
  Button,
  View,
  ImageBackground,
  Image,
  TextInput,
  Dimensions,
  StyleSheet,

} from 'react-native';

const { width: WIDTH } = Dimensions.get('window')
const userInfo ={username: 'admin', password: '1234'}
export default class ParentPassword extends Component 
{ static navigationOptions = ({ navigation }) => ({
    title: `Parent Authentication`,
    headerTitleStyle: { textAlign: 'center', alignSelf: 'center' },
    headerStyle: {
    backgroundColor: 'white',
    },
});
constructor(props) {
    super(props)
    this.state = {
        username: '',
        password: '',
    };
}


  render() {
    return (

      <View>

        {/* Container for username and password form */}
        <View style={styles.loginContainer}>

          {/* Username form */}
          <View style={styles.userLoginForm}>
            <TextInput
              style={{ flex: 1 }}
              placeholder="Username"
              onChangeText={(username)=>this.setState({username})}
              value={this.state.username}
              autoCapitalize="none"
              placeholderTextColor="black"
              underlineColorAndroid="transparent"
            />
          </View>

          {/* Password form */}
          <View style={styles.userLoginForm}>
            <TextInput
              style={{ flex: 1 }}
              placeholder="Password"
              onChangeText={(password)=>this.setState({password})}
              value={this.state.password}
              placeholderTextColor="black"
            // underlineColorAndroid="transparent"
            />
          </View>

          <View style={styles.loginButton}>

            <View style={styles.buttonContainer}>
            <Button
                title="Join"
                onPress={this._login}
              />
            </View>

          </View>
        </View>


      </View>
    );
  }
  
    _login = async() =>{
        if(userInfo.username === this.state.username && userInfo.password === this.state.password){
   
    this.props.navigation.navigate('ParentRoutines')
          
        }else{
            alert('Username or password is incorrect.');
        }
        
    }
}


const styles = StyleSheet.create({
  userLoginForm: {
    width: WIDTH - 300,
    height: 45,
    borderRadius: 15,
    borderStyle: 'solid',
    borderColor: '#d6d7da',
    borderWidth: 2,
    fontSize: 10,
    marginBottom: 20,
    color: 'black',
    marginBottom: 5,
    overflow: 'hidden',
    flexDirection: 'row',
    alignSelf: 'center',
  },
  placeholder: {
    color: 'black'
  },
  logo: {
    alignContent: 'center'
  },
  buttonContainer: {
  },
  loginButton: {
    marginTop: 20,
    width: 50,
    alignSelf: 'center'
  },
  loginContainer: {
    marginBottom: 40,
    marginTop: 20,
  },
  loginIcons: {
    padding: 12,
    margin: 5,
    height: 20,
    width: 20,
    opacity: .2,
    alignItems: 'center',
  },
  backgroundContainer: {
    flex: 1,
    width: null,
    height: null,
    justifyContent: 'center',
    alignItems: 'center',
  },
  input: {
    width: WIDTH - 110,
    height: 35,
    borderRadius: 5,
    fontSize: 10,
    paddingLeft: 45,
    borderWidth: 0.5,
    color: 'black',
    backgroundColor: 'white',
    borderStyle: 'solid',
    borderColor: '#d6d7da',
    borderWidth: 4,
    marginBottom: 6,
    overflow: 'hidden',
  },
  logoContainer: {
    marginTop: 100,
    alignItems: 'center'
  },
  forgotPassword: {
    fontSize: 16,
    letterSpacing: .3,
    lineHeight: 38,
    alignSelf: 'center',
    color: 'blue',
  },
  generalText: {
    paddingTop: 30,
    fontSize: 16,
    lineHeight: 38,
    textAlign: 'center',
    color: 'black',
  },
  createAccount: {
    fontSize: 16,
    lineHeight: 38,
    textAlign: 'center',
    color: '#223a7a',
    textDecorationLine: 'underline',
  },
});

Нажмите здесь, чтобы увидеть ошибку на эмуляторе iPad

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...