-1

I want to navigate to another screen (i.e 'Details') when I hit the login button. This is my working main code: (could be checked on Snack Expo)

import React, { Component } from 'react';
import { Container, Header, Left, Body, Right, Button, Title, Text, Form, Item, Input, Label} from 'native-base';
import { StackNavigator } from 'react-navigation';
import { DrawerNavigator } from "react-navigation";

export default class Login extends Component {
  constructor(props) {
    super(props);

    this.state = {
      username: '',
      password: '',
    };
  }
  render() {
    return (
      <Container>
      <Text >Instaride</Text>
      <Form>
            <Item floatingLabel>
              <Label onChangeText={(text) => this.setState({username: text})}>Username</Label>
              <Input 
              value={this.state.username}
          onChangeText={username => this.setState({ username })}
          placeholder={'Username'}
          />
            </Item>
            <Item floatingLabel last>
              <Label >Password</Label>
              <Input 
              value={this.state.password}
          onChangeText={password => this.setState({ password })}
          placeholder={'Password'}
          secureTextEntry={true}
          />
            </Item>
          </Form>
          <Left>
            <Button >
              <Text>Login</Text>
            </Button>
            <Text >Forgot Password?</Text>
          </Left>
          <Right>
            <Button hasText transparent>
              <Text>Sign Up Here</Text>
            </Button>
          </Right>
      </Container>
    );
  }
}
class DetailsScreen extends React.Component {
  render() {
    return (
        <Text>Details Screen</Text>
    );
  }
}

class RegisterationScreen extends React.Component {
  render() {
    return (

        <Text>sign up time</Text>
    );
  }
}

However, I get an error when I add this:

const HomeScreenRouter = DrawerNavigator(
  {
    Home: { screen: Login },
    Chat: { screen: DetailsScreen },
    Profile: { screen: RegisterationScreen }
  }
)

I can not really figure out a way to combine all of these:

onPress={() => this.props.navigation.navigate("Details")}

Also, what exactly should I be exporting at the end of the code?

x89
  • 2,798
  • 5
  • 46
  • 110

1 Answers1

1

You should do something like this to work...

import React, { Component } from 'react';
import { Container, Header, Left, Body, Right, Button, Title, Text, Form, Item, Input, Label} from 'native-base';
import { StackNavigator } from 'react-navigation';
import { DrawerNavigator } from "react-navigation";
import { createAppContainer } from 'react-navigation';

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

    this.state = {
      username: '',
      password: '',
    };
  }
  render() {
    return (
      <Container>
      <Text >Instaride</Text>
      <Form>
            <Item floatingLabel>
              <Label onChangeText={(text) => this.setState({username: text})}>Username</Label>
              <Input 
              value={this.state.username}
          onChangeText={username => this.setState({ username })}
          placeholder={'Username'}
          />
            </Item>
            <Item floatingLabel last>
              <Label >Password</Label>
              <Input 
              value={this.state.password}
          onChangeText={password => this.setState({ password })}
          placeholder={'Password'}
          secureTextEntry={true}
          />
            </Item>
          </Form>
          <Left>
            <Button >
              <Text>Login</Text>
            </Button>
            <Text >Forgot Password?</Text>
          </Left>
          <Right>
            <Button hasText transparent>
              <Text>Sign Up Here</Text>
            </Button>
          </Right>
      </Container>
    );
  }
}
class DetailsScreen extends React.Component {
  render() {
    return (
        <Text>Details Screen</Text>
    );
  }
}

class RegisterationScreen extends React.Component {
  render() {
    return (

        <Text>sign up time</Text>
    );
  }
}

const HomeScreenRouter = createStackNavigator(
  {
    Details: { screen: Details },       
  }
)

export default createAppContainer(HomeScreenRouter);
Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43