Skip to main content
Version: 1.0.115

Moving between screens

How to move and pass params between screens

react-native-nano uses famous navigation package react-navigation to handle navigation and pass data between screens. You can access the navigation instance from any action method.

For example, Lets say you want to move from ScreenA to ScreenB with some parameters, you can do like below.

ScreenA:

In below code, whenever the button is pressed, it will redirect to ScreenB with parameter name .

const buttonPress = {
component: NANO.BUTTON,
value: 'CLICK ME TO MOVE TO SCREEN B',
onPress: ({ moduleParams }) => {
moduleParams["navigation"].navigate("ScreenB", { "name": "value" })
}
};

const screen = {
name: 'ScreenA',
screen: {
h1: [buttonPress]
}
};

ScreenB:

Once the ScreenB is mounted, we can get parameters using route instance in onStart method which gets called when screen is mounted.

Read more about Screen life cycle events here.

const text2 = {
component: NANO.TEXT,
value: "I AM IN SCREEN B",
};

const screen = {
name: 'ScreenB',
screen: {
h1: [text],
},
onStart: ({moduleParams}) => {
console.log( moduleParams["route"].params["name"])
}
};

You can use all the navigation methods like push, navigate, goBack and popToTop. Check the documentation here react-navigation