SlideShare a Scribd company logo
1 of 32
Download to read offline
REACT NAVIGATION
MODULAR NAVIGATION
MODULAR NAVIGATION WITH REACT NAVIGATION
ROADMAP
▸ 1- Overview
▸ 2- Navigation Boilerplate
▸ 3- Nested Navigation
▸ 4- Go Back to Navigation Root
▸ 5- EXTRA - Status Bar Height Adjustment
OVERVIEW
REACT NAVIGATION
REACT NAVIGATION OVERVIEW
FEATURES
▸ Navigators
▸ Nested Navigators
▸ Redux Integration
▸ Web Integration
▸ Screen Tracking with Google Analytics
▸ Routers
REACT NAVIGATION OVERVIEW
PREREQUISITES
▸ React Native - Native Code
react-native init ProjectName
▸ React Native - Expo
create-react-native-app ProjectName
REACT NAVIGATION OVERVIEW
INTRODUCTION
▸ React Navigation is the result of a collaboration between
developers from Facebook, Expo and the React community at
large: it replaces and improves upon several navigation libraries
in the ecosystem, including Ex-Navigation, React Native's
Navigator and NavigationExperimental components.
▸ Release in late January 2017.
▸ Officially recommended navigation library for React Native in
September 2017.
▸ Expo has expressed that React Navigation v1.0 is priority.
REACT NAVIGATION OVERVIEW
DEV COMMUNITY BENCHMARKING
REACT NAVIGATION OVERVIEW
NAVIGATION LAB SCREEN FLOW
REACT NAVIGATION OVERVIEW
NAVIGATION LAB PROTOTYPE
BOILERPLATE
NAVIGATION
NAVIGATION BOILERPLATE
INSTALL PACKAGES
npm install react-native-elements —-save
npm install react-navigation —-save
"dependencies": {
"react-native-elements": "^0.17.0",
"react-navigation": "^1.0.0-beta.15"
}
NAVIGATION BOILERPLATE
FOLDERS AND FILES STRUCTURE
▸ Main
▸ Config
app navigation files
▸ Screens
app screen files
▸ Auth
▸ Config
auth navigation files
▸ Screens
auth screen files
▸ Modules
▸ Module
▸ Config
module navigation files
▸ Screens
module screen files
NAVIGATION BOILERPLATE
MAIN NAVIGATION BOILERPLATE
const MainTabNavigator = TabNavigator({
Welcome: { screen: WelcomeScreen },
Auth: { screen: ({ navigation }) => (
<AuthStackNavigation
navigation={{ root: navigation, ...navigation }}
/>
)},
Home: { screen: ({ navigation }) => (
<HomeTabNavigation
navigation={{ root: navigation, ...navigation }}
/>
)}
}, {
animationEnabled: false,
lazyLoad: true,
swipeEnabled: false,
navigationOptions: {
tabBarVisible: false
}
});
NAVIGATION BOILERPLATE
HOME NAVIGATION BOILERPLATE
const HomeTabNavigator = TabNavigator({
Home: { screen: ({ navigation }) => (
<HomeDrawerNavigation
navigation={{
root: this.props.navigation.root, ...navigation }}
/>
), navigationOptions: homeTabNavigationOptions },
Contacts: {
screen: ContactsStackNavigation,
navigationOptions: contactsTabNavigationOptions
},
Settings: {
screen: SettingsStackNavigation,
navigationOptions: settingsTabNavigationOptions
},
...
});
NAVIGATION BOILERPLATE
DRAWER NAVIGATION BOILERPLATE
const HomeDrawerNavigator = DrawerNavigator({
Home: { screen: ({ navigation }) => (
<HomeStackNavigation
navigation={{ root: this.props.navigation.root, ...navigation }}
/>
), navigationOptions: ({ navigation }) => ({
drawerLabel: 'Home',
drawerIcon: <Icon name='ios-home' type='ionicon' />
})},
Store: { screen: ({ navigation }) => (
<StoreStackNavigation
navigation={{ root: this.props.navigation.root, ...navigation }}
/>
), navigationOptions: ({ navigation }) => ({
drawerLabel: 'Store',
drawerIcon: <Icon name='ios-pricetags' type='ionicon' />
})},
...
});
NAVIGATION BOILERPLATE
MODULE NAVIGATION BOILERPLATE
const StoreStackNavigator = StackNavigator({
Store: {
screen: HomeScreen,
navigationOptions: {
title: 'Store',
headerLeft: (
<Icon
name='ios-arrow-back'
type='ionicon'
size={36}
style={{ marginLeft: 20 }}
onPress={() => this.props.navigation.goBack()}
/>
),
headerRight: <Icon name='ios-pricetags' type='ionicon'
style={{ marginRight: 20 }} />
},
},
Order: { screen: OrderScreen },
Pay: { screen: PayScreen }
});
NAVIGATION BOILERPLATE
SCREEN BOILERPLATE
export default
class ContactsScreen extends React.Component {
static navigationOptions = ({ navigation }) => ({
title: 'Contacts',
headerRight:
<Icon
name='ios-contacts'
type='ionicon'
style={{ marginRight: 20 }}
/>
});
render() {
return(
<View />
)
}
}
NAVIGATION
NESTED
NESTED NAVIGATION
NAVIGATION HOME SCREEN STRUCTURE
HomeDrawerNavigatorMainTabNavigator
HomeTabNavigator HomeStackNavigator
HomeScreen
NESTED NAVIGATION
NAVIGATION TREE STRUCTURE
1-TabNavigator (Main)
WelcomeScreen
1.1-StackNavigator (Auth)
LoginScreen
RecoveryScreen
RegisterScreen
1.2-TabNavigator (Home)
1.2.1-DrawerNavigator (Home)
1.2.1.1-StackNavigator (Home)
HomeScreen
1.2.1.2-StackNavigator (Store)
HomeScreen
OrderScreen
PayScreen
1.2.1.3-StackNavigator (Service)
HomeScreen
RequestScreen
1.2.2-StackNavigator (Contacts)
ContactsScreen
1.2.3-StackNavigator (Settings)
SettingsScreen
1.2.4-StackNavigator (Search)
SearchScreen
NESTED NAVIGATION
CUSTOM ROOT NAVIGATION PROPS
export default class MainTabNavigation extends React.Component {
render() {
const MainTabNavigator = TabNavigator({
...
Main: {
screen: ({ navigation }) => (
<HomeTabNavigation
navigation={{
root: navigation,
...navigation
}}
/>
)
}
}
...
NESTED NAVIGATION
TAB NAVIGATION OPTIONS
const homeTabNavigationOptions = ({ navigation }) => ({
tabBarLabel: 'Home',
tabBarIcon: ({ focused }) => (
<Icon
name={focused ? 'ios-home' : 'ios-home-outline'}
type='ionicon'
/>
)
});
const TabkNavigator = TabNavigator({
Home: {
screen: ({ navigation }) => (
<HomeDrawerNavigation
navigation={{ root: this.props.navigation.root, …navigation }}
/>
),
navigationOptions: homeTabNavigationOptions
}
}
NESTED NAVIGATION
DRAWER NAVIGATION OPTIONS
const HomeDrawerNavigator = DrawerNavigator({
Home: {
screen: ({ navigation }) => (
<HomeStackNavigation
navigation={{
root: this.props.navigation.root,
...navigation
}}
/>
),
navigationOptions: ({ navigation }) => ({
drawerLabel: 'Home',
drawerIcon: <Icon name='ios-home' type='ionicon' />
})
},
NESTED NAVIGATION
STACK NAVIGATION OPTIONS
const HomeStackNavigator = StackNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
title: 'Home',
headerLeft: (
<Icon
name='ios-menu'
type='ionicon'
size={36}
style={{ marginLeft: 20 }}
onPress={() =>
this.props.navigation.navigate('DrawerOpen')}
/>
),
headerRight:
<Icon name='ios-home' type='ionicon'
style={{ marginRight: 20 }} />
...
NAVIGATION
ROOT
GO BACK
GO BACK TO NAVIGATION ROOT
NAVIGATION ACTIONS
▸ Navigate - Navigate to another route.
▸ Reset - Replace current state with a new state.
▸ Back - Go back to previous state.
▸ Set Params - Set Params for given route.
▸ Init - Used to initialize first if state is undefined.
import { NavigationActions } from ‘react-navigation’;
this.props.navigation.dispatch(
NavigationActions.reset({ params... })
);
GO BACK TO NAVIGATION ROOT
GO TO HOME AFTER LOG ON
<Button
raised
title='Login'
onPress={() =>
this.props.navigation.root
.navigate(‘Main’)
}
/>
GO BACK TO NAVIGATION ROOT
GO TO LOGIN AFTER LOG OFF
contentComponent: props => (
<ScrollView
...
<Button
title='Logout'
onPress={() => {
this.props.navigation.root
.dispatch(
NavigationActions.reset({
index: 0,
actions: []
})
);
this.props.navigation.root
.navigate(‘Auth');
}}
/>
...
</ScrollView>
)
GO BACK TO NAVIGATION ROOT
GO TO WELCOME AFTER YOU LEAVE
contentComponent: props => (
<ScrollView
...
<Button
title='Logout'
onPress={() => {
this.props.navigation.root
.dispatch(
NavigationActions.reset({
index: 0,
actions: []
})
);
this.props.navigation.root
.navigate(‘Welcome’);
}}
/>
...
</ScrollView>
)
MODULAR NAVIGATION WITH REACT NAVIGATION
EXTRA - ANDROID STATUS BAR HEIGHT ADJUSTMENT
import { Platform } from 'react-native';
import Expo from 'expo';
export default class HomeTabNavigation
extends React.Component {
render() {
const HomeTabNavigator = TabNavigator({
...
}, {
...
tabBarOptions: {
labelStyle: {
fontSize: 10
},
showIcon: true,
tabStyle: {
marginTop: Platform.OS === 'ios' ? 0
: Expo.Constants.statusBarHeight
}
}
});
return (
<HomeTabNavigator />
);
}
}
THANK YOU!
William Santos
@WilliamSantosRJ
william-santos-bwti/react-navigation-lab
Modular Navigation with React Navigation
React Rio Talk
QUESTIONS?
MODULAR NAVIGATION WITH REACT NAVIGATION

More Related Content

Similar to Modular Navigation with React Navigation

Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Android JetPack: easy navigation with the new Navigation Controller
Android JetPack: easy navigation with the new Navigation ControllerAndroid JetPack: easy navigation with the new Navigation Controller
Android JetPack: easy navigation with the new Navigation ControllerLeonardo Pirro
 
Writing java script for Csharp's Blazor
Writing java script for Csharp's BlazorWriting java script for Csharp's Blazor
Writing java script for Csharp's BlazorEd Charbeneau
 
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...GreeceJS
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)jeresig
 
Infinum Android Talks #13 - Design Support Library by Ivan Markusi
Infinum Android Talks #13 - Design Support Library by Ivan MarkusiInfinum Android Talks #13 - Design Support Library by Ivan Markusi
Infinum Android Talks #13 - Design Support Library by Ivan MarkusiInfinum
 
Academy PRO: React native - navigation
Academy PRO: React native - navigationAcademy PRO: React native - navigation
Academy PRO: React native - navigationBinary Studio
 
React Native: Introduction
React Native: IntroductionReact Native: Introduction
React Native: IntroductionInnerFood
 
2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...
2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...
2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...GIS in the Rockies
 
Layar Events in New York and San Francisco
Layar Events in New York and San FranciscoLayar Events in New York and San Francisco
Layar Events in New York and San FranciscoMarc René Gardeya
 
User experience and interactions design
User experience and interactions design User experience and interactions design
User experience and interactions design Rakesh Jha
 
Sharepoint 2013 - un slider JSSOR sur bib Images
Sharepoint 2013 - un slider JSSOR sur bib ImagesSharepoint 2013 - un slider JSSOR sur bib Images
Sharepoint 2013 - un slider JSSOR sur bib ImagesEmmanuel Sotter
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJSFestUA
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSbuttyx
 

Similar to Modular Navigation with React Navigation (20)

Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Android JetPack: easy navigation with the new Navigation Controller
Android JetPack: easy navigation with the new Navigation ControllerAndroid JetPack: easy navigation with the new Navigation Controller
Android JetPack: easy navigation with the new Navigation Controller
 
Writing java script for Csharp's Blazor
Writing java script for Csharp's BlazorWriting java script for Csharp's Blazor
Writing java script for Csharp's Blazor
 
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)
 
Infinum Android Talks #13 - Design Support Library by Ivan Markusi
Infinum Android Talks #13 - Design Support Library by Ivan MarkusiInfinum Android Talks #13 - Design Support Library by Ivan Markusi
Infinum Android Talks #13 - Design Support Library by Ivan Markusi
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
Academy PRO: React native - navigation
Academy PRO: React native - navigationAcademy PRO: React native - navigation
Academy PRO: React native - navigation
 
React Native: Introduction
React Native: IntroductionReact Native: Introduction
React Native: Introduction
 
Android 3
Android 3Android 3
Android 3
 
2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...
2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...
2013 URISA Track, Kickstarter for JavaScript Web and Mobile GIS Development b...
 
Layar Events in New York and San Francisco
Layar Events in New York and San FranciscoLayar Events in New York and San Francisco
Layar Events in New York and San Francisco
 
User experience and interactions design
User experience and interactions design User experience and interactions design
User experience and interactions design
 
Sharepoint 2013 - un slider JSSOR sur bib Images
Sharepoint 2013 - un slider JSSOR sur bib ImagesSharepoint 2013 - un slider JSSOR sur bib Images
Sharepoint 2013 - un slider JSSOR sur bib Images
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
JS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-NativeJS Fest 2018. Илья Иванов. Введение в React-Native
JS Fest 2018. Илья Иванов. Введение в React-Native
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
React native tour
React native tourReact native tour
React native tour
 
Voyager: The Widget Router
Voyager: The Widget RouterVoyager: The Widget Router
Voyager: The Widget Router
 

Recently uploaded

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Modular Navigation with React Navigation

  • 2. MODULAR NAVIGATION WITH REACT NAVIGATION ROADMAP ▸ 1- Overview ▸ 2- Navigation Boilerplate ▸ 3- Nested Navigation ▸ 4- Go Back to Navigation Root ▸ 5- EXTRA - Status Bar Height Adjustment
  • 4. REACT NAVIGATION OVERVIEW FEATURES ▸ Navigators ▸ Nested Navigators ▸ Redux Integration ▸ Web Integration ▸ Screen Tracking with Google Analytics ▸ Routers
  • 5. REACT NAVIGATION OVERVIEW PREREQUISITES ▸ React Native - Native Code react-native init ProjectName ▸ React Native - Expo create-react-native-app ProjectName
  • 6. REACT NAVIGATION OVERVIEW INTRODUCTION ▸ React Navigation is the result of a collaboration between developers from Facebook, Expo and the React community at large: it replaces and improves upon several navigation libraries in the ecosystem, including Ex-Navigation, React Native's Navigator and NavigationExperimental components. ▸ Release in late January 2017. ▸ Officially recommended navigation library for React Native in September 2017. ▸ Expo has expressed that React Navigation v1.0 is priority.
  • 7. REACT NAVIGATION OVERVIEW DEV COMMUNITY BENCHMARKING
  • 11. NAVIGATION BOILERPLATE INSTALL PACKAGES npm install react-native-elements —-save npm install react-navigation —-save "dependencies": { "react-native-elements": "^0.17.0", "react-navigation": "^1.0.0-beta.15" }
  • 12. NAVIGATION BOILERPLATE FOLDERS AND FILES STRUCTURE ▸ Main ▸ Config app navigation files ▸ Screens app screen files ▸ Auth ▸ Config auth navigation files ▸ Screens auth screen files ▸ Modules ▸ Module ▸ Config module navigation files ▸ Screens module screen files
  • 13. NAVIGATION BOILERPLATE MAIN NAVIGATION BOILERPLATE const MainTabNavigator = TabNavigator({ Welcome: { screen: WelcomeScreen }, Auth: { screen: ({ navigation }) => ( <AuthStackNavigation navigation={{ root: navigation, ...navigation }} /> )}, Home: { screen: ({ navigation }) => ( <HomeTabNavigation navigation={{ root: navigation, ...navigation }} /> )} }, { animationEnabled: false, lazyLoad: true, swipeEnabled: false, navigationOptions: { tabBarVisible: false } });
  • 14. NAVIGATION BOILERPLATE HOME NAVIGATION BOILERPLATE const HomeTabNavigator = TabNavigator({ Home: { screen: ({ navigation }) => ( <HomeDrawerNavigation navigation={{ root: this.props.navigation.root, ...navigation }} /> ), navigationOptions: homeTabNavigationOptions }, Contacts: { screen: ContactsStackNavigation, navigationOptions: contactsTabNavigationOptions }, Settings: { screen: SettingsStackNavigation, navigationOptions: settingsTabNavigationOptions }, ... });
  • 15. NAVIGATION BOILERPLATE DRAWER NAVIGATION BOILERPLATE const HomeDrawerNavigator = DrawerNavigator({ Home: { screen: ({ navigation }) => ( <HomeStackNavigation navigation={{ root: this.props.navigation.root, ...navigation }} /> ), navigationOptions: ({ navigation }) => ({ drawerLabel: 'Home', drawerIcon: <Icon name='ios-home' type='ionicon' /> })}, Store: { screen: ({ navigation }) => ( <StoreStackNavigation navigation={{ root: this.props.navigation.root, ...navigation }} /> ), navigationOptions: ({ navigation }) => ({ drawerLabel: 'Store', drawerIcon: <Icon name='ios-pricetags' type='ionicon' /> })}, ... });
  • 16. NAVIGATION BOILERPLATE MODULE NAVIGATION BOILERPLATE const StoreStackNavigator = StackNavigator({ Store: { screen: HomeScreen, navigationOptions: { title: 'Store', headerLeft: ( <Icon name='ios-arrow-back' type='ionicon' size={36} style={{ marginLeft: 20 }} onPress={() => this.props.navigation.goBack()} /> ), headerRight: <Icon name='ios-pricetags' type='ionicon' style={{ marginRight: 20 }} /> }, }, Order: { screen: OrderScreen }, Pay: { screen: PayScreen } });
  • 17. NAVIGATION BOILERPLATE SCREEN BOILERPLATE export default class ContactsScreen extends React.Component { static navigationOptions = ({ navigation }) => ({ title: 'Contacts', headerRight: <Icon name='ios-contacts' type='ionicon' style={{ marginRight: 20 }} /> }); render() { return( <View /> ) } }
  • 19. NESTED NAVIGATION NAVIGATION HOME SCREEN STRUCTURE HomeDrawerNavigatorMainTabNavigator HomeTabNavigator HomeStackNavigator HomeScreen
  • 20. NESTED NAVIGATION NAVIGATION TREE STRUCTURE 1-TabNavigator (Main) WelcomeScreen 1.1-StackNavigator (Auth) LoginScreen RecoveryScreen RegisterScreen 1.2-TabNavigator (Home) 1.2.1-DrawerNavigator (Home) 1.2.1.1-StackNavigator (Home) HomeScreen 1.2.1.2-StackNavigator (Store) HomeScreen OrderScreen PayScreen 1.2.1.3-StackNavigator (Service) HomeScreen RequestScreen 1.2.2-StackNavigator (Contacts) ContactsScreen 1.2.3-StackNavigator (Settings) SettingsScreen 1.2.4-StackNavigator (Search) SearchScreen
  • 21. NESTED NAVIGATION CUSTOM ROOT NAVIGATION PROPS export default class MainTabNavigation extends React.Component { render() { const MainTabNavigator = TabNavigator({ ... Main: { screen: ({ navigation }) => ( <HomeTabNavigation navigation={{ root: navigation, ...navigation }} /> ) } } ...
  • 22. NESTED NAVIGATION TAB NAVIGATION OPTIONS const homeTabNavigationOptions = ({ navigation }) => ({ tabBarLabel: 'Home', tabBarIcon: ({ focused }) => ( <Icon name={focused ? 'ios-home' : 'ios-home-outline'} type='ionicon' /> ) }); const TabkNavigator = TabNavigator({ Home: { screen: ({ navigation }) => ( <HomeDrawerNavigation navigation={{ root: this.props.navigation.root, …navigation }} /> ), navigationOptions: homeTabNavigationOptions } }
  • 23. NESTED NAVIGATION DRAWER NAVIGATION OPTIONS const HomeDrawerNavigator = DrawerNavigator({ Home: { screen: ({ navigation }) => ( <HomeStackNavigation navigation={{ root: this.props.navigation.root, ...navigation }} /> ), navigationOptions: ({ navigation }) => ({ drawerLabel: 'Home', drawerIcon: <Icon name='ios-home' type='ionicon' /> }) },
  • 24. NESTED NAVIGATION STACK NAVIGATION OPTIONS const HomeStackNavigator = StackNavigator({ Home: { screen: HomeScreen, navigationOptions: { title: 'Home', headerLeft: ( <Icon name='ios-menu' type='ionicon' size={36} style={{ marginLeft: 20 }} onPress={() => this.props.navigation.navigate('DrawerOpen')} /> ), headerRight: <Icon name='ios-home' type='ionicon' style={{ marginRight: 20 }} /> ...
  • 26. GO BACK TO NAVIGATION ROOT NAVIGATION ACTIONS ▸ Navigate - Navigate to another route. ▸ Reset - Replace current state with a new state. ▸ Back - Go back to previous state. ▸ Set Params - Set Params for given route. ▸ Init - Used to initialize first if state is undefined. import { NavigationActions } from ‘react-navigation’; this.props.navigation.dispatch( NavigationActions.reset({ params... }) );
  • 27. GO BACK TO NAVIGATION ROOT GO TO HOME AFTER LOG ON <Button raised title='Login' onPress={() => this.props.navigation.root .navigate(‘Main’) } />
  • 28. GO BACK TO NAVIGATION ROOT GO TO LOGIN AFTER LOG OFF contentComponent: props => ( <ScrollView ... <Button title='Logout' onPress={() => { this.props.navigation.root .dispatch( NavigationActions.reset({ index: 0, actions: [] }) ); this.props.navigation.root .navigate(‘Auth'); }} /> ... </ScrollView> )
  • 29. GO BACK TO NAVIGATION ROOT GO TO WELCOME AFTER YOU LEAVE contentComponent: props => ( <ScrollView ... <Button title='Logout' onPress={() => { this.props.navigation.root .dispatch( NavigationActions.reset({ index: 0, actions: [] }) ); this.props.navigation.root .navigate(‘Welcome’); }} /> ... </ScrollView> )
  • 30. MODULAR NAVIGATION WITH REACT NAVIGATION EXTRA - ANDROID STATUS BAR HEIGHT ADJUSTMENT import { Platform } from 'react-native'; import Expo from 'expo'; export default class HomeTabNavigation extends React.Component { render() { const HomeTabNavigator = TabNavigator({ ... }, { ... tabBarOptions: { labelStyle: { fontSize: 10 }, showIcon: true, tabStyle: { marginTop: Platform.OS === 'ios' ? 0 : Expo.Constants.statusBarHeight } } }); return ( <HomeTabNavigator /> ); } }