Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of Navigation between views in React Native Android?

After check the React Native documentation, I still don't understand the best way to create views and navigate between different components.

I don't want to use any external components like:

https://github.com/Kureev/react-native-navbar/

https://github.com/23c/react-native-transparent-bar

https://github.com/superdami/react-native-custom-navigation

I don't need a Navigation bar, i just want to set views and slide left, right o pop a view, nothing more.

I know is something basic, but I can't find any helpful example.

Please, anyone can help me? Any functional example in https://rnplay.org/?

Thank you.

like image 639
Eusthace Avatar asked Oct 03 '15 03:10

Eusthace


People also ask

How does navigation work in React Native?

How navigation works in react native. Working with navigation. Passing data from one screen to another while navigating. 1. To start off with first let's create a project. To create a project first run, 2. Then we will choose a template from the following, we will select, blank as an option. 3. Then we will setup the name and slug,

What is React-Native-stack navigator?

Native stack navigator that uses native navigation primitives for navigation using react-native-screens New backends for Material top tab navigator based on react- native-viewpager and ScrollView What is React Native Navigation? React Native Navigation is a popular alternative to React Navigation.

How to navigate on the home screen in ReactJS?

You can click on BACK TO HOME to navigate on the home screen or by clicking on the back icon at the left top. We built an app with two screens i.e home and about. We have used the React navigation library. We learnt about this.props.navigation which is used to inherit props from the navigation object.

What have I learned in react navigation 5 so far?

You’ve learned how to create very simple navigation with the React Navigation 5 library. You’ve also learned how to move from one screen to another one. From here, you’re pretty good to go. If you’d like to explore more features in modern React Native, take a look at the following articles:


Video Answer


1 Answers

UPDATE 04/2018 :

Things have change since my first answer, and today two massive libraries are relevant for navigation : react-navigation and react-native-navigation.

I will wrote an example for react-navigation which is an easy to use library and full JS maintain by serious people from the community.

First install the library :

yarn add react-navigation 

or

npm install --save react-navigation 

Then in your app entry point (index.js) :

import Config from './config';  import { AppRegistry } from 'react-native'; import { StackNavigator } from 'react-navigation';  export const AppNavigator = StackNavigator(Config.navigation); AppRegistry.registerComponent('appName', () => AppNavigator); 

You can see that we pass an object to the StackNavigator, it's all ours screens configuration, here is an example of configuration :

import HomeScreen from "./HomeScreen"; import SettingsScreen from "./SettingsScreen";  const Config = {       navigation: {           Home: {             screen: HomeScreen           },           Settings: {             screen: SettingsScreen,           }        }     } 

Now the app know each screen we got. We can simply tell the "navigate" function to go to our Setting Screen. Let's watch our Home Screen :

class HomeScene extends Component {        constructor(props) {           super(props);       }        render () {         return (         <View>             <Button               title="Go to Settings"               onPress={() => this.props.navigation.navigate('Settings')}             />         </View>          );       }     } 

As you can see, the navigation will hydrate the props. And from here you can make what you want.

Go to the library documentation to see all you can do : change the header type, the title, navigation type, ...

PREVIOUS ANSWER :

Watch this example: https://github.com/h87kg/NavigatorDemo

It's useful and a well written Navigator example, better than the one above you just wrote, I think.

Mainly watch the relationship between LoginPage.js and MainPage.js

like image 55
rob-art Avatar answered Oct 11 '22 04:10

rob-art