Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Creating a Screen with React Native

Tiempo de lectura: 2 minutos

Reading Time: 2 minutes

Screens in React Native function as standalone objects constructed with various components. In this example, I will show you how to create a Screen.

First, create a screens folder where we will place the screens. Inside this folder, create a .js file called Login.js.

Inside the Login.js file, we will have the following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import React from "react";
import { Text } from "react-native";
//Button component
const Login = () => {
return (
<Text>"Login Screen"</Text>
)
};
export default Login;
import React from "react"; import { Text } from "react-native"; //Button component const Login = () => { return ( <Text>"Login Screen"</Text> ) }; export default Login;
import React from "react";
import { Text } from "react-native";

//Button component
const Login = () => {

    return (
            <Text>"Login Screen"</Text>   
    )
};

export default Login;

As you can see, it is an exact copy of App.js. This represents a screen.

To use it in another screen, for example, to load it within App.js, we need to add the following to our App.js file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import React from "react";
import { View } from "react-native";
//Import screens
import Login from './screens/Login';
//Create a component named APP
const App = () => {
return (
<View >
<Login />
</View>)
};
export default App;
import React from "react"; import { View } from "react-native"; //Import screens import Login from './screens/Login'; //Create a component named APP const App = () => { return ( <View > <Login /> </View>) }; export default App;
import React from "react";
import { View } from "react-native";

//Import screens
import Login from './screens/Login';

//Create a component named APP
const App = () => {

    return (
        <View >
            <Login />
        </View>)
};

export default App;

As you can see, the first thing we did was to import the screen we created:

import Login from './screens/Login';
import Login from './screens/Login';

Once imported, we can use it within the render of the const App by adding it as follows:

<Login />
<Login />

And with this, our screen is loaded within App.js.

This is important because each screen will have its own design and styles within the screen object itself.

0

Leave a Comment