1

I'm using React Native Navigation dependency as route. But I have problem in the following code which appears to do nothing.

I'm trying to create 2 screens, one is login, the other is register (later on I will add button to move between them, right now even the default screen doesn't work).

App.JS

import React from 'react';
import { View, StatusBar, Text } from 'react-native';
import Login from './login.js';

export default function App() {
  return (
    <View>
       <StatusBar barStyle="dark-content" hidden={false} backgroundColor="#ffffff" translucent={true}/>
       <Login/>
    </View>
  );
}

Login.JS

import React from 'react';
import Register from './register.js';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

function LoginScreen() {
  return (
    <View style={{ flex: 1, paddingTop: 100, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Home Screen</Text>
    </View>
  );
}


const Stack = createStackNavigator();

function Login() {
    return (
      <View style={styles.container}>
        <Text style={styles.logo}>My Title</Text>
        <Text style={styles.slogan}>Welcome</Text>
      

        <NavigationContainer>
          <Stack.Navigator initialRouteName="Login">
            <Stack.Screen name="Login" component={LoginScreen} />
            <Stack.Screen name="Register" component={Register} />
          </Stack.Navigator>
        </NavigationContainer>

      </View>
    );
  }

  export default Login;

By reading the docs that should work, but I can't understand what is wrong here.

I receive blank area in the stack screen area.

I have tried to replace Register component with function, didn't work either.

How can I display React Native Navigation stack screen correctly?

2
  • 1
    I dont see any error, I would try delete the initialRouteName or wrap App component with NavigationContainer Commented Jan 10, 2021 at 23:47
  • 1
    @EnzoPerez Thank you aswell, it's seems it only works on app.js file once it wrapping the entire file. Commented Jan 11, 2021 at 12:15

3 Answers 3

2

try to remove the parent view , use the like a parent view or use a fragment <> </> the some problem if we use safeareaView

Sign up to request clarification or add additional context in comments.

Comments

1

How about having the Navigation Container wrap the contents of App.js then you can leave the Stack navigator and screens in the Login component

Comments

0

The container around your navigation has a background-color, so remove all background-color around it and see again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.