Proper way to navigate back and forward my list items in React Native
I am quite new to React Native and now I am kind of building my mobile app (previously implemented using jQuery and PhoneGap) from the beginning and I need an advice how to achieve the following:
On my main dashboard I have a list of mail boxes (React FlatList)
1. MailBox1
2. Mailbox2
3. Mailbox3
Then, after a specific mailbox was clicked I want to list all of the items inside of it (on a new screen/component/page):
1. MailBox1_Item1
2. MailBox1_Item2
Each of the mail items has its own details. After a mail item was clicked I want to be able to display its details on a new screen/component/page.
MailBox1_Item1 was created on 10/10/18
MailBox1_Item1 was created by SomeUser
etc.
The specific thing here is that I want to be able to navigate back when I am on the screens for details and mail items.
My app so far is using a tab navigator from here:
import React, { Component } from 'react';
import { StyleSheet, Text, View } from "react-native";
import { createBottomTabNavigator } from "react-navigation"
import Icon from 'react-native-vector-icons/Ionicons'
import HomeTab from './HomeTab'
import SettingsTab from './SettingsTab'
export default createBottomTabNavigator({
Home:{
screen: HomeTab,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon:({tintColor})=>(
<Icon name="ios-home" color={tintColor} size={24}/>
)
}
},
Settings:{
screen: SettingsTab,
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon:({tintColor})=>(
<Icon name="ios-settings" color={tintColor} size={24}/>
)
}
}
},
{
//router config
initialRoutName: 'Home',
order: ['Home', 'Settings'],
//navigation for complete tab navigator
navigationOptions:{
tabBarVisible:true
},
tabBarOptions:{
activeTintColor:'red',
inactiveTintColor:'grey'
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
and my dashboard is on the 'Home' tab.
react-native react-router react-navigation react-native-flatlist
add a comment |
I am quite new to React Native and now I am kind of building my mobile app (previously implemented using jQuery and PhoneGap) from the beginning and I need an advice how to achieve the following:
On my main dashboard I have a list of mail boxes (React FlatList)
1. MailBox1
2. Mailbox2
3. Mailbox3
Then, after a specific mailbox was clicked I want to list all of the items inside of it (on a new screen/component/page):
1. MailBox1_Item1
2. MailBox1_Item2
Each of the mail items has its own details. After a mail item was clicked I want to be able to display its details on a new screen/component/page.
MailBox1_Item1 was created on 10/10/18
MailBox1_Item1 was created by SomeUser
etc.
The specific thing here is that I want to be able to navigate back when I am on the screens for details and mail items.
My app so far is using a tab navigator from here:
import React, { Component } from 'react';
import { StyleSheet, Text, View } from "react-native";
import { createBottomTabNavigator } from "react-navigation"
import Icon from 'react-native-vector-icons/Ionicons'
import HomeTab from './HomeTab'
import SettingsTab from './SettingsTab'
export default createBottomTabNavigator({
Home:{
screen: HomeTab,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon:({tintColor})=>(
<Icon name="ios-home" color={tintColor} size={24}/>
)
}
},
Settings:{
screen: SettingsTab,
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon:({tintColor})=>(
<Icon name="ios-settings" color={tintColor} size={24}/>
)
}
}
},
{
//router config
initialRoutName: 'Home',
order: ['Home', 'Settings'],
//navigation for complete tab navigator
navigationOptions:{
tabBarVisible:true
},
tabBarOptions:{
activeTintColor:'red',
inactiveTintColor:'grey'
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
and my dashboard is on the 'Home' tab.
react-native react-router react-navigation react-native-flatlist
Check this link: stackoverflow.com/questions/53942539/…
– Reza
Dec 31 '18 at 10:55
add a comment |
I am quite new to React Native and now I am kind of building my mobile app (previously implemented using jQuery and PhoneGap) from the beginning and I need an advice how to achieve the following:
On my main dashboard I have a list of mail boxes (React FlatList)
1. MailBox1
2. Mailbox2
3. Mailbox3
Then, after a specific mailbox was clicked I want to list all of the items inside of it (on a new screen/component/page):
1. MailBox1_Item1
2. MailBox1_Item2
Each of the mail items has its own details. After a mail item was clicked I want to be able to display its details on a new screen/component/page.
MailBox1_Item1 was created on 10/10/18
MailBox1_Item1 was created by SomeUser
etc.
The specific thing here is that I want to be able to navigate back when I am on the screens for details and mail items.
My app so far is using a tab navigator from here:
import React, { Component } from 'react';
import { StyleSheet, Text, View } from "react-native";
import { createBottomTabNavigator } from "react-navigation"
import Icon from 'react-native-vector-icons/Ionicons'
import HomeTab from './HomeTab'
import SettingsTab from './SettingsTab'
export default createBottomTabNavigator({
Home:{
screen: HomeTab,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon:({tintColor})=>(
<Icon name="ios-home" color={tintColor} size={24}/>
)
}
},
Settings:{
screen: SettingsTab,
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon:({tintColor})=>(
<Icon name="ios-settings" color={tintColor} size={24}/>
)
}
}
},
{
//router config
initialRoutName: 'Home',
order: ['Home', 'Settings'],
//navigation for complete tab navigator
navigationOptions:{
tabBarVisible:true
},
tabBarOptions:{
activeTintColor:'red',
inactiveTintColor:'grey'
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
and my dashboard is on the 'Home' tab.
react-native react-router react-navigation react-native-flatlist
I am quite new to React Native and now I am kind of building my mobile app (previously implemented using jQuery and PhoneGap) from the beginning and I need an advice how to achieve the following:
On my main dashboard I have a list of mail boxes (React FlatList)
1. MailBox1
2. Mailbox2
3. Mailbox3
Then, after a specific mailbox was clicked I want to list all of the items inside of it (on a new screen/component/page):
1. MailBox1_Item1
2. MailBox1_Item2
Each of the mail items has its own details. After a mail item was clicked I want to be able to display its details on a new screen/component/page.
MailBox1_Item1 was created on 10/10/18
MailBox1_Item1 was created by SomeUser
etc.
The specific thing here is that I want to be able to navigate back when I am on the screens for details and mail items.
My app so far is using a tab navigator from here:
import React, { Component } from 'react';
import { StyleSheet, Text, View } from "react-native";
import { createBottomTabNavigator } from "react-navigation"
import Icon from 'react-native-vector-icons/Ionicons'
import HomeTab from './HomeTab'
import SettingsTab from './SettingsTab'
export default createBottomTabNavigator({
Home:{
screen: HomeTab,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon:({tintColor})=>(
<Icon name="ios-home" color={tintColor} size={24}/>
)
}
},
Settings:{
screen: SettingsTab,
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon:({tintColor})=>(
<Icon name="ios-settings" color={tintColor} size={24}/>
)
}
}
},
{
//router config
initialRoutName: 'Home',
order: ['Home', 'Settings'],
//navigation for complete tab navigator
navigationOptions:{
tabBarVisible:true
},
tabBarOptions:{
activeTintColor:'red',
inactiveTintColor:'grey'
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});
and my dashboard is on the 'Home' tab.
react-native react-router react-navigation react-native-flatlist
react-native react-router react-navigation react-native-flatlist
edited Jan 13 at 19:03
Omid Ebrahimi
54811134
54811134
asked Dec 31 '18 at 10:51
user2128702user2128702
5261831
5261831
Check this link: stackoverflow.com/questions/53942539/…
– Reza
Dec 31 '18 at 10:55
add a comment |
Check this link: stackoverflow.com/questions/53942539/…
– Reza
Dec 31 '18 at 10:55
Check this link: stackoverflow.com/questions/53942539/…
– Reza
Dec 31 '18 at 10:55
Check this link: stackoverflow.com/questions/53942539/…
– Reza
Dec 31 '18 at 10:55
add a comment |
1 Answer
1
active
oldest
votes
What you should do is, just use a StackNavigator for your Dashboard route of the Tab, and your Stack navigator should contain the following routes
MailList (Component to show mail list)
MailItemList (Component to show list of items associated with specific mail)
ItemDetail (Component to show detail for item)
The code should look like :
const dashboardStack = createStackNavigator({
MailListScreen: {screen: MailList},
MailItemListScreen: {screen: MailItemList},
ItemDetailScreen: {screen: ItemDetail},
});
with this in hand, you should use componentDidMount of each component to initiate your network operation to fetch required data to show it to the screen, and for the screens which depend on the previous like list item screen to fetch list of items for given mail, just pass the id of the mail to the next screen and use that id to initiate the network call to fetch the desired data.
You can pass the id (in general, data) from one route (screen component) to other using params like this:
this.props.navigation.navigate('MailItemListScreen', {id: 1});
The above line describes a navigation from current screen lets say from MailListScreen to MailItemListScreen and also carrying a payload of info as second parameter in the navigate.
I would recommend you read the react-navigation docs first.
Hope this helps. Happy Coding !
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986575%2fproper-way-to-navigate-back-and-forward-my-list-items-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
What you should do is, just use a StackNavigator for your Dashboard route of the Tab, and your Stack navigator should contain the following routes
MailList (Component to show mail list)
MailItemList (Component to show list of items associated with specific mail)
ItemDetail (Component to show detail for item)
The code should look like :
const dashboardStack = createStackNavigator({
MailListScreen: {screen: MailList},
MailItemListScreen: {screen: MailItemList},
ItemDetailScreen: {screen: ItemDetail},
});
with this in hand, you should use componentDidMount of each component to initiate your network operation to fetch required data to show it to the screen, and for the screens which depend on the previous like list item screen to fetch list of items for given mail, just pass the id of the mail to the next screen and use that id to initiate the network call to fetch the desired data.
You can pass the id (in general, data) from one route (screen component) to other using params like this:
this.props.navigation.navigate('MailItemListScreen', {id: 1});
The above line describes a navigation from current screen lets say from MailListScreen to MailItemListScreen and also carrying a payload of info as second parameter in the navigate.
I would recommend you read the react-navigation docs first.
Hope this helps. Happy Coding !
add a comment |
What you should do is, just use a StackNavigator for your Dashboard route of the Tab, and your Stack navigator should contain the following routes
MailList (Component to show mail list)
MailItemList (Component to show list of items associated with specific mail)
ItemDetail (Component to show detail for item)
The code should look like :
const dashboardStack = createStackNavigator({
MailListScreen: {screen: MailList},
MailItemListScreen: {screen: MailItemList},
ItemDetailScreen: {screen: ItemDetail},
});
with this in hand, you should use componentDidMount of each component to initiate your network operation to fetch required data to show it to the screen, and for the screens which depend on the previous like list item screen to fetch list of items for given mail, just pass the id of the mail to the next screen and use that id to initiate the network call to fetch the desired data.
You can pass the id (in general, data) from one route (screen component) to other using params like this:
this.props.navigation.navigate('MailItemListScreen', {id: 1});
The above line describes a navigation from current screen lets say from MailListScreen to MailItemListScreen and also carrying a payload of info as second parameter in the navigate.
I would recommend you read the react-navigation docs first.
Hope this helps. Happy Coding !
add a comment |
What you should do is, just use a StackNavigator for your Dashboard route of the Tab, and your Stack navigator should contain the following routes
MailList (Component to show mail list)
MailItemList (Component to show list of items associated with specific mail)
ItemDetail (Component to show detail for item)
The code should look like :
const dashboardStack = createStackNavigator({
MailListScreen: {screen: MailList},
MailItemListScreen: {screen: MailItemList},
ItemDetailScreen: {screen: ItemDetail},
});
with this in hand, you should use componentDidMount of each component to initiate your network operation to fetch required data to show it to the screen, and for the screens which depend on the previous like list item screen to fetch list of items for given mail, just pass the id of the mail to the next screen and use that id to initiate the network call to fetch the desired data.
You can pass the id (in general, data) from one route (screen component) to other using params like this:
this.props.navigation.navigate('MailItemListScreen', {id: 1});
The above line describes a navigation from current screen lets say from MailListScreen to MailItemListScreen and also carrying a payload of info as second parameter in the navigate.
I would recommend you read the react-navigation docs first.
Hope this helps. Happy Coding !
What you should do is, just use a StackNavigator for your Dashboard route of the Tab, and your Stack navigator should contain the following routes
MailList (Component to show mail list)
MailItemList (Component to show list of items associated with specific mail)
ItemDetail (Component to show detail for item)
The code should look like :
const dashboardStack = createStackNavigator({
MailListScreen: {screen: MailList},
MailItemListScreen: {screen: MailItemList},
ItemDetailScreen: {screen: ItemDetail},
});
with this in hand, you should use componentDidMount of each component to initiate your network operation to fetch required data to show it to the screen, and for the screens which depend on the previous like list item screen to fetch list of items for given mail, just pass the id of the mail to the next screen and use that id to initiate the network call to fetch the desired data.
You can pass the id (in general, data) from one route (screen component) to other using params like this:
this.props.navigation.navigate('MailItemListScreen', {id: 1});
The above line describes a navigation from current screen lets say from MailListScreen to MailItemListScreen and also carrying a payload of info as second parameter in the navigate.
I would recommend you read the react-navigation docs first.
Hope this helps. Happy Coding !
answered Dec 31 '18 at 12:05
Suraj MalviyaSuraj Malviya
855414
855414
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986575%2fproper-way-to-navigate-back-and-forward-my-list-items-in-react-native%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Check this link: stackoverflow.com/questions/53942539/…
– Reza
Dec 31 '18 at 10:55