SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler offline
Compose Navigation
Navigate between screens easily with Jetpack Compose 🚀
22.02.2022
Set-up
Dependencies and additional steps 🚧
Basic navigation
Navigating between screens and passing arguments
Passing complex data
Add your favorite library for serialization
Navigation testing
Add following dependency
Note: If youʼre using Hilt you might need more dependencies, but this wonʼt be covered in this meetup 🙈
Navigation animation
Animating your screen transitions with Accompanist Navigation Animation
Note: Learn more about Navigation Animation: https://google.github.io/accompanist/navigation-animation/
Navigation basics
Creating NavHost and destinations 🚩
Create NavHost
And pass NavController with start destination
Note: To create an instance of NavController, use rememberNavController() function
Start
destination
And your Composable to the NavGraphBuilder
You need to pass the route name - you will use it later to navigate to this screen
Add route
Passing primitive types
Itʼs recommended to pass only essential data 🙌
This is the recommended way 🚨
It doesnʼt break SSOT principle
Note: To learn more, please visit this link Retrieving complex data when navigating
What types can we pass?
We can pass 11 available types without any additional set-up
NavType Type Description
NavType.BoolArrayType NavType<BooleanArray?> NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file.
NavType.BoolType NavType<Boolean> NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file.
NavType.FloatArrayType NavType<FloatArray?> NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file.
NavType.FloatType NavType<Float> NavType for storing float values, corresponding with the "float" type in a Navigation XML file.
NavType.IntArrayType NavType<IntArray?> NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file.
NavType.IntType NavType<Int> NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file.
NavType.LongArrayType NavType<LongArray?> NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file.
NavType.LongType NavType<Long> NavType for storing long values, corresponding with the "long" type in a Navigation XML file.
NavType.ReferenceType NavType<Int> NavType for storing integer values representing resource ids, corresponding with the "reference" type
in a Navigation XML file.
NavType.StringArrayType NavType<Array<String>?> NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file.
NavType.StringType NavType<String?> NavType for storing String values, corresponding with the "string" type in a Navigation XML file.
Create new destination
With out-of-the-box arguments
Note: This is the recommended way to pass data
Add route and
arguments separated
by /
Provide a list of
NamedNavArguments
Passing simple data
Simply using template expression
Note: This is the recommended way to pass data
Getting simple data from NavBackStackEntry
From arguments parameter
Note: This is the recommended way to pass data
Get argument
from
NavBackStackE
ntry
Passing complex data
If you still want to pass your Parcelables 💭
Create custom NavType
By extending NavType
Note: You can use your favorite library for serialization, Kotlin Serialization, Moshi, etc.
Create new destination
With your custom NavType
Note: This goes against the SSOT principle and Google recommendations, as well as adds more complexity to navigation.
Add route and
arguments separated
by /
Provide a list of
NamedNavArguments
Passing complex data
In 3 steps - encode our Parcelable into Json string, encode to UTF-8 scheme and pass to NavController
Note: Since navigation is using NavDeepLinkRequest under the hood, we need to make sure we use Uri.encode(...)
Why do we need Uri.encode(...)?! 😱
If you forget to encode your JSON string, you will get an exception…
Note: Uri.encode(...) encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme. Leaves letters ("A-Z", "a-z"),
numbers ("0-9"), and unreserved characters ("_-!.~'()*") intact. Encodes all other characters.
Get your Parcelable
Similar to primitive types you can get from NavBackStackEntry
Note: This goes against the SSOT principle and Google recommendations, as well as adds more complexity to navigation.
Get Parcelable
Organizing navigation code
No-one likes endless NavHosts 😰
Create extension functions
Declare your composable destination, inject your ViewModels and get arguments in a separate file
Note: This is especially useful when you process multiple arguments 😊
Deeplinks
Set-up deeplinks to your destinations 🌎
Declare intent filter
In your AndroidManifest.xml
Intent filter for your
deeplink
Pass the list of deeplinks
To your composable.
Add a list of NavDeepLinks
Note: Thatʼs it! You donʼt need additional logic to get the argument, it will work exactly the same as regular arguments!
Your deeplinks are ready! 👏
Time to verify if they are working
Testing your navigation
Making sure it works correctly 👋
Set-up your test
Under androidTest directory (e.g. NavigationTest.kt)
Perform some actions with ComposeTestRule
And assert NavBackStackEntry destination
Animate screen transitions
Adding extra touch to your navigation in 4 steps 🎶
Step 1. Replace your NavController
To AnimatedNavController
Replace
with
Step 2. Replace NavHost
With AnimatedNavHost
Replace
with
Step 3. Replace composable import
To the one provided by Accompanist library
Replace
with
Note: If you forget this, you will not see any screen in your navigation 😐
Step 4 (Option 1). Add transitions to all NavHost
The solution below will add default transitions for all destinations
Step 4 (Option 2). Add transitions to composables
If you need different transitions for your destinations, you can pass them to composable(...) function
UPCOMING MEETUP
Check out our event page
Stay tuned for whatʼs coming next!

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Reactive state management with Jetpack Components
Reactive state management with Jetpack ComponentsReactive state management with Jetpack Components
Reactive state management with Jetpack Components
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Constructor ppt
Constructor pptConstructor ppt
Constructor ppt
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Expressjs
ExpressjsExpressjs
Expressjs
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Using hilt in a modularized project
Using hilt in a modularized projectUsing hilt in a modularized project
Using hilt in a modularized project
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
JavaScript Execution Context
JavaScript Execution ContextJavaScript Execution Context
JavaScript Execution Context
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
Generics C#
Generics C#Generics C#
Generics C#
 
Callback Function
Callback FunctionCallback Function
Callback Function
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 

Semelhante a Seven Peaks Speaks - Compose Navigation

Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Andreas Dewes
 
Spray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSpray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSandeep Purohit
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxMalla Reddy University
 
Umbraco OktoberFest 2014
Umbraco OktoberFest 2014Umbraco OktoberFest 2014
Umbraco OktoberFest 2014Jeavon Leopold
 
Spark Summit EU talk by Ross Lawley
Spark Summit EU talk by Ross LawleySpark Summit EU talk by Ross Lawley
Spark Summit EU talk by Ross LawleySpark Summit
 
How To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own DatasourceHow To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own DatasourceMongoDB
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchAndrew Lowe
 
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsApache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsViswanath Gangavaram
 
iOS best practices
iOS best practicesiOS best practices
iOS best practicesMaxim Vialyx
 
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsBig Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsGuido Schmutz
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The EnterpriseDaniel Egan
 
MongoDB Aggregation MongoSF May 2011
MongoDB Aggregation MongoSF May 2011MongoDB Aggregation MongoSF May 2011
MongoDB Aggregation MongoSF May 2011Chris Westin
 

Semelhante a Seven Peaks Speaks - Compose Navigation (20)

Unit 3
Unit 3Unit 3
Unit 3
 
Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...Code is not text! How graph technologies can help us to understand our code b...
Code is not text! How graph technologies can help us to understand our code b...
 
js.pptx
js.pptxjs.pptx
js.pptx
 
Spray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSpray - Build RESTfull services in scala
Spray - Build RESTfull services in scala
 
Spray
SpraySpray
Spray
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Express node js
Express node jsExpress node js
Express node js
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
Umbraco OktoberFest 2014
Umbraco OktoberFest 2014Umbraco OktoberFest 2014
Umbraco OktoberFest 2014
 
Spark Summit EU talk by Ross Lawley
Spark Summit EU talk by Ross LawleySpark Summit EU talk by Ross Lawley
Spark Summit EU talk by Ross Lawley
 
How To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own DatasourceHow To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own Datasource
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
 
Scala at Netflix
Scala at NetflixScala at Netflix
Scala at Netflix
 
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labsApache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
Apache pig power_tools_by_viswanath_gangavaram_r&d_dsg_i_labs
 
iOS best practices
iOS best practicesiOS best practices
iOS best practices
 
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-FormatsBig Data, Data Lake, Fast Data - Dataserialiation-Formats
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
 
Python
PythonPython
Python
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
MongoDB Aggregation MongoSF May 2011
MongoDB Aggregation MongoSF May 2011MongoDB Aggregation MongoSF May 2011
MongoDB Aggregation MongoSF May 2011
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 

Mais de Seven Peaks Speaks

Seven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks
 
Seven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks
 
How to Get Better Performance Out of Your App
How to Get Better Performance Out of Your AppHow to Get Better Performance Out of Your App
How to Get Better Performance Out of Your AppSeven Peaks Speaks
 
Secure Development of Azure Function
Secure Development of Azure FunctionSecure Development of Azure Function
Secure Development of Azure FunctionSeven Peaks Speaks
 
Develop Security & Compliances in Azure
Develop Security & Compliances in AzureDevelop Security & Compliances in Azure
Develop Security & Compliances in AzureSeven Peaks Speaks
 
Background Processing With Work Manager
Background Processing With Work ManagerBackground Processing With Work Manager
Background Processing With Work ManagerSeven Peaks Speaks
 
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Seven Peaks Speaks
 
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Seven Peaks Speaks
 
Delivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing PyramidDelivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing PyramidSeven Peaks Speaks
 
Getting hooked on performance and clean code
Getting hooked on performance and clean codeGetting hooked on performance and clean code
Getting hooked on performance and clean codeSeven Peaks Speaks
 
Establishing secure Biometric authentication in Android
Establishing secure Biometric authentication in AndroidEstablishing secure Biometric authentication in Android
Establishing secure Biometric authentication in AndroidSeven Peaks Speaks
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationSeven Peaks Speaks
 
Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Seven Peaks Speaks
 

Mais de Seven Peaks Speaks (20)

BKK Web: Working with SEO
BKK Web: Working with SEOBKK Web: Working with SEO
BKK Web: Working with SEO
 
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
 
Seven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose Animation
 
How to Get Better Performance Out of Your App
How to Get Better Performance Out of Your AppHow to Get Better Performance Out of Your App
How to Get Better Performance Out of Your App
 
RxSubject And Operators
RxSubject And OperatorsRxSubject And Operators
RxSubject And Operators
 
Concurrency in Swift
Concurrency in SwiftConcurrency in Swift
Concurrency in Swift
 
DevSecOps on Azure
DevSecOps on AzureDevSecOps on Azure
DevSecOps on Azure
 
Secure Development of Azure Function
Secure Development of Azure FunctionSecure Development of Azure Function
Secure Development of Azure Function
 
Develop Security & Compliances in Azure
Develop Security & Compliances in AzureDevelop Security & Compliances in Azure
Develop Security & Compliances in Azure
 
Effective Lists Management
Effective Lists ManagementEffective Lists Management
Effective Lists Management
 
Layout Preview Tooling
Layout Preview ToolingLayout Preview Tooling
Layout Preview Tooling
 
Background Processing With Work Manager
Background Processing With Work ManagerBackground Processing With Work Manager
Background Processing With Work Manager
 
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Graph ql vs rest api - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
Structuring node.js projects - Seven Peaks Software (Node.JS Meetup 18 nov 2021)
 
Delivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing PyramidDelivering react app with confidence: Testing Pyramid
Delivering react app with confidence: Testing Pyramid
 
React context
React context  React context
React context
 
Getting hooked on performance and clean code
Getting hooked on performance and clean codeGetting hooked on performance and clean code
Getting hooked on performance and clean code
 
Establishing secure Biometric authentication in Android
Establishing secure Biometric authentication in AndroidEstablishing secure Biometric authentication in Android
Establishing secure Biometric authentication in Android
 
Utilizing kotlin flows in an android application
Utilizing kotlin flows in an android applicationUtilizing kotlin flows in an android application
Utilizing kotlin flows in an android application
 
Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”Continuously deploy a containerized app to “Azure App Service”
Continuously deploy a containerized app to “Azure App Service”
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Seven Peaks Speaks - Compose Navigation

  • 1. Compose Navigation Navigate between screens easily with Jetpack Compose 🚀 22.02.2022
  • 3. Basic navigation Navigating between screens and passing arguments
  • 4. Passing complex data Add your favorite library for serialization
  • 5. Navigation testing Add following dependency Note: If youʼre using Hilt you might need more dependencies, but this wonʼt be covered in this meetup 🙈
  • 6. Navigation animation Animating your screen transitions with Accompanist Navigation Animation Note: Learn more about Navigation Animation: https://google.github.io/accompanist/navigation-animation/
  • 7. Navigation basics Creating NavHost and destinations 🚩
  • 8. Create NavHost And pass NavController with start destination Note: To create an instance of NavController, use rememberNavController() function Start destination
  • 9. And your Composable to the NavGraphBuilder You need to pass the route name - you will use it later to navigate to this screen Add route
  • 10. Passing primitive types Itʼs recommended to pass only essential data 🙌
  • 11. This is the recommended way 🚨 It doesnʼt break SSOT principle Note: To learn more, please visit this link Retrieving complex data when navigating
  • 12. What types can we pass? We can pass 11 available types without any additional set-up NavType Type Description NavType.BoolArrayType NavType<BooleanArray?> NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file. NavType.BoolType NavType<Boolean> NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file. NavType.FloatArrayType NavType<FloatArray?> NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file. NavType.FloatType NavType<Float> NavType for storing float values, corresponding with the "float" type in a Navigation XML file. NavType.IntArrayType NavType<IntArray?> NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file. NavType.IntType NavType<Int> NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file. NavType.LongArrayType NavType<LongArray?> NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file. NavType.LongType NavType<Long> NavType for storing long values, corresponding with the "long" type in a Navigation XML file. NavType.ReferenceType NavType<Int> NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file. NavType.StringArrayType NavType<Array<String>?> NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file. NavType.StringType NavType<String?> NavType for storing String values, corresponding with the "string" type in a Navigation XML file.
  • 13. Create new destination With out-of-the-box arguments Note: This is the recommended way to pass data Add route and arguments separated by / Provide a list of NamedNavArguments
  • 14. Passing simple data Simply using template expression Note: This is the recommended way to pass data
  • 15. Getting simple data from NavBackStackEntry From arguments parameter Note: This is the recommended way to pass data Get argument from NavBackStackE ntry
  • 16. Passing complex data If you still want to pass your Parcelables 💭
  • 17. Create custom NavType By extending NavType Note: You can use your favorite library for serialization, Kotlin Serialization, Moshi, etc.
  • 18. Create new destination With your custom NavType Note: This goes against the SSOT principle and Google recommendations, as well as adds more complexity to navigation. Add route and arguments separated by / Provide a list of NamedNavArguments
  • 19. Passing complex data In 3 steps - encode our Parcelable into Json string, encode to UTF-8 scheme and pass to NavController Note: Since navigation is using NavDeepLinkRequest under the hood, we need to make sure we use Uri.encode(...)
  • 20. Why do we need Uri.encode(...)?! 😱 If you forget to encode your JSON string, you will get an exception… Note: Uri.encode(...) encodes characters in the given string as '%'-escaped octets using the UTF-8 scheme. Leaves letters ("A-Z", "a-z"), numbers ("0-9"), and unreserved characters ("_-!.~'()*") intact. Encodes all other characters.
  • 21. Get your Parcelable Similar to primitive types you can get from NavBackStackEntry Note: This goes against the SSOT principle and Google recommendations, as well as adds more complexity to navigation. Get Parcelable
  • 22. Organizing navigation code No-one likes endless NavHosts 😰
  • 23. Create extension functions Declare your composable destination, inject your ViewModels and get arguments in a separate file Note: This is especially useful when you process multiple arguments 😊
  • 24. Deeplinks Set-up deeplinks to your destinations 🌎
  • 25. Declare intent filter In your AndroidManifest.xml Intent filter for your deeplink
  • 26. Pass the list of deeplinks To your composable. Add a list of NavDeepLinks Note: Thatʼs it! You donʼt need additional logic to get the argument, it will work exactly the same as regular arguments!
  • 27. Your deeplinks are ready! 👏 Time to verify if they are working
  • 28. Testing your navigation Making sure it works correctly 👋
  • 29. Set-up your test Under androidTest directory (e.g. NavigationTest.kt)
  • 30. Perform some actions with ComposeTestRule And assert NavBackStackEntry destination
  • 31. Animate screen transitions Adding extra touch to your navigation in 4 steps 🎶
  • 32. Step 1. Replace your NavController To AnimatedNavController Replace with
  • 33. Step 2. Replace NavHost With AnimatedNavHost Replace with
  • 34. Step 3. Replace composable import To the one provided by Accompanist library Replace with Note: If you forget this, you will not see any screen in your navigation 😐
  • 35. Step 4 (Option 1). Add transitions to all NavHost The solution below will add default transitions for all destinations
  • 36. Step 4 (Option 2). Add transitions to composables If you need different transitions for your destinations, you can pass them to composable(...) function
  • 37. UPCOMING MEETUP Check out our event page Stay tuned for whatʼs coming next!