SlideShare a Scribd company logo
Modern app development with
Jetpack Compose
Md Shamsul Arafin Mahtab
Software Engineer (Android), Therap Services
Why Adopt Compose
● Less Code
● Declarative API
● Faster Development
● Powerful
“For the same Button class it [the code] was 10x
of magnitude smaller.” (Twitter)
“Significant reduction for any screen built with a
RecyclerView.” (Monzo)
“Reading the code for complicated components
is easier.” (Square)
Why Adopt Compose
● Less Code
● Declarative API
● Faster Development
● Powerful
“Theming layer is vastly more intuitive and
legible.” (Twitter)
“UI components that were stateless, easy to use
and maintain, and intuitive to
implement/extend/customize.” (Twitter)
Why Adopt Compose
● Less Code
● Declarative API
● Faster Development
● Powerful
“We didn’t have to think about things like light
and dark mode.” (Cuvva)
“Previews in Android Studio have been a big
time saver.” (Square)
Why Adopt Compose
● Less Code
● Declarative API
● Faster Development
● Powerful
“Animations are so easy to add.” (Monzo)
“Accessibility apis have been improved.”
(Square)
What’s wrong with
Traditional Android View System?
Traditional Android View System
Updating UI
(button.setBackground(Red))
Traditional Android View System
Result after update
Traditional Android View System
Again updating UI
(root.removeChild(View))
Traditional Android View System
These methods change the internal state of the widget.
The declarative programming paradigm
● All Composable functions must have
@Composable annotation; this
annotation informs the Compose
compiler that this function is intended to
convert data into UI.
● The function doesn't return anything.
● This function is fast, idempotent, and
free of side-effects.
A compose function
The declarative widgets
1. Widgets are relatively stateless
2. They do not expose any setter or getter functions
3. Widget are not exposed as objects
4. Composables are responsible for transforming the current application state into a UI
every time the observable data updates
A compose app example
Scaffold
Currencies
Timeline
Column
CurrencyPicker
Spacer
Spacer
Spacer
Box
CurrencyPicker
Icon
TextField
Dropdown
TopAppBar
BottomBar
Navigation Converter
TextField
Dropdown
Base
Current
1
USD
Recomposition
Scaffold
Currencies
Timeline
CurrencyPicker
Spacer
Spacer
Spacer
Box Icon
TextField
Dropdown
TopAppBar
BottomBar
Dropdown
Base
Current
1
USD
85.513
BDT
Navigation Converter Column
CurrencyPicker
TextField
Things to be aware of
Things to be aware of
1. Composable functions can execute in any order
2. Composable functions can run in parallel
3. Recomposition skips as much as possible
4. Recomposition is optimistic
5. Composable functions might run quite frequently
State and Composition
State and composition
Initial State Value State Value Changes
Compose UI
Initial Composition Recomposition
Use of remember and rememberSaveable
1. remember composables stores single objects in memory by composable functions,
retain state across recomposition.
2. rememberSaveable same as remember, except retain states across configuration
changes.
Other supported types of State
1. LiveData
2. Flow
3. RxJava2
These observable types are converted to State<T> before reading it to Compose.
is a pattern of moving state to a composable's
caller to make a composable stateless.
State Hoisting
➔ value: T: the current value to display
➔ onValueChange: (T) -> Unit: an event
that requests the value to change, where
T is the proposed new value
Managing State in Compose
State Management Example
State Management
Depending on the complexity of the composable, these are the alternatives to consider:
● Composables for simple UI element state management.
● State holders for complex UI element state management. They own UI elements' state and UI
logic.
● Architecture Components ViewModels as a special type of state holder in charge of providing
access to the business logic and the screen or UI state.
Use of Key
Recomposition (new
item added to top)
Calling a composable multiple times with key will help
to identify each composition distinct.
Use of Stable
Annotating the type with @Stable to allow Compose to favor smart recompositions if Compose
is not able to infer the stability of a type.
Modifiers
to decorate or augment a composable.
● Change the composable's size, layout, behavior, and appearance
● Add information, like accessibility labels
● Process user input
● Add high-level interactions, like making an element clickable, scrollable, draggable, or zoomable
Lifecycle of composables
Effects
Effects and Side-effects in Compose
1. A side-effect is a change to the state
of the app that happens outside the
scope of a composable function.
2. An effect is a composable function
that doesn't emit UI and causes side
effects to run when a composition
completes.
Effect {
Side Effect
}
Called from a controlled environment
that is aware of the lifecycle of the
composable.
LaunchedEffect
To call suspend functions safely from inside a composable,
LaunchedEffect composable to use.
Example: Showing error message on a Snackbar if a UI state
contains an error.
rememberCoroutineScope
To launch a coroutine outside of a composable, but
scoped so that it will be automatically canceled
once it leaves the composition.
Example: Showing a Snackbar when the user taps.
DisposableEffect
Effects that need to cleaned up after keys change or
the composables leaves the composition.
@Composable
fun HomeScreen(key: Key) {
DisposableEffect(key) {
val observer = Observer { }
addObserver(observer)
onDispose {
removeObserver(observer)
}
}
}
rememberUpdatedState
Capture a value in the effect
that, while recomposition,
the effect will not restart.
Example: Splash Screen.
SideEffect
To share Compose state
with objects not managed
by compose, SideEffect
composable to use.
produceState
Convert non-Compose state
into Compose state.
Example: Loading network
image and convert it to
State object.
@Composable
fun loadNetworkImage(
url: String,
imageRepository: ImageRepository
): State<Result<Image>> {
return
produceState<Result<Image>> {
//TODO }
}
Phases
Phases of Android View System
Composition Layout Drawing
Measurement Placement
Compose Architecture Layering
Runtime UI Foundation Material
Compose is created from a number of modules which are assembled together to form a complete
stack
Each layer is built upon the lower levels, combining functionality to create higher level components.
Use of CompositionLocal
● CompositionLocal is a tool for passing
data down through the Composition
implicitly.
● It is what the Material theme uses under
the hood.
● MaterialTheme is an object that provides
three CompositionLocal instances--
colors, typography and shapes
Thank You

More Related Content

What's hot

React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
Ramon Ribeiro Rabello
 
Jetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on AndroidJetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on Android
Nelson Glauber Leal
 
React & Redux
React & ReduxReact & Redux
React & Redux
Federico Bond
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
Ignacio Martín
 
React state
React  stateReact  state
React state
Ducat
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
MicroPyramid .
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
Vedran Blaženka
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack Tutorial
Simplilearn
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
Ignacio Martín
 
Android Jetpack
Android Jetpack Android Jetpack
Android Jetpack
Tudor Sirbu
 
React and redux
React and reduxReact and redux
React and redux
Mystic Coders, LLC
 
React Hooks
React HooksReact Hooks
React Hooks
Erez Cohen
 
ReactJS
ReactJSReactJS
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
JassGroup TICS
 
Intro to React
Intro to ReactIntro to React
Intro to React
Eric Westfall
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSX
Micah Wood
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Hoang Long
 
React hooks
React hooksReact hooks
React hooks
Ramy ElBasyouni
 

What's hot (20)

React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Jetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on AndroidJetpack Compose a new way to implement UI on Android
Jetpack Compose a new way to implement UI on Android
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
React state
React  stateReact  state
React state
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
React state managmenet with Redux
React state managmenet with ReduxReact state managmenet with Redux
React state managmenet with Redux
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack Tutorial
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Android Jetpack
Android Jetpack Android Jetpack
Android Jetpack
 
React and redux
React and reduxReact and redux
React and redux
 
React Hooks
React HooksReact Hooks
React Hooks
 
ReactJS
ReactJSReactJS
ReactJS
 
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSX
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
React hooks
React hooksReact hooks
React hooks
 

Similar to Modern app development with Jetpack Compose.pptx

Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
DicodingEvent
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
Hussain Behestee
 
Compose Camp by GDSC NSUT
Compose Camp by GDSC NSUTCompose Camp by GDSC NSUT
Compose Camp by GDSC NSUT
MOHITCHAURASIYA6
 
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple AnimationsMobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
AndiNurkholis1
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooks
Katy Slemon
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
binDebug WorkSpace
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
StephieJohn
 
"The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ..."The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ...
Fwdays
 
Ng talk
Ng talkNg talk
Introduction to State Restoration in Flutter
Introduction to State Restoration in FlutterIntroduction to State Restoration in Flutter
Introduction to State Restoration in Flutter
Dave Chao
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
Coding Academy
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
Memento Pattern Implementation
Memento Pattern ImplementationMemento Pattern Implementation
Memento Pattern Implementation
Steve Widom
 
Compose Camp - Session3.pptx
Compose Camp - Session3.pptxCompose Camp - Session3.pptx
Compose Camp - Session3.pptx
GDSCAtharvaCollegeOf
 
Automation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in HyderabadAutomation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in Hyderabad
Durga Prasad
 
Automation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabadAutomation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabad
Durga Prasad
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
Amin Ashtiani
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
Netcetera
 
React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of react
Imran Sayed
 
Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)
Gorkem Ercan
 

Similar to Modern app development with Jetpack Compose.pptx (20)

Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq PermanaJetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
Jetpack Compose untuk UI Masa Depan Bagian 2 - Sidiq Permana
 
iOS app dev Training - Session1
iOS app dev Training - Session1iOS app dev Training - Session1
iOS app dev Training - Session1
 
Compose Camp by GDSC NSUT
Compose Camp by GDSC NSUTCompose Camp by GDSC NSUT
Compose Camp by GDSC NSUT
 
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple AnimationsMobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
Mobile Programming - 7 Side Effects, Effect Handlers, and Simple Animations
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooks
 
Functional programming in TypeScript
Functional programming in TypeScriptFunctional programming in TypeScript
Functional programming in TypeScript
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
"The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ..."The Story of Declarative React at Grammarly: From two-way data binding with ...
"The Story of Declarative React at Grammarly: From two-way data binding with ...
 
Ng talk
Ng talkNg talk
Ng talk
 
Introduction to State Restoration in Flutter
Introduction to State Restoration in FlutterIntroduction to State Restoration in Flutter
Introduction to State Restoration in Flutter
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
 
Memento Pattern Implementation
Memento Pattern ImplementationMemento Pattern Implementation
Memento Pattern Implementation
 
Compose Camp - Session3.pptx
Compose Camp - Session3.pptxCompose Camp - Session3.pptx
Compose Camp - Session3.pptx
 
Automation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in HyderabadAutomation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in Hyderabad
 
Automation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabadAutomation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabad
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
 
React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of react
 
Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)
 

Recently uploaded

22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 

Recently uploaded (20)

22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 

Modern app development with Jetpack Compose.pptx

  • 1. Modern app development with Jetpack Compose Md Shamsul Arafin Mahtab Software Engineer (Android), Therap Services
  • 2. Why Adopt Compose ● Less Code ● Declarative API ● Faster Development ● Powerful “For the same Button class it [the code] was 10x of magnitude smaller.” (Twitter) “Significant reduction for any screen built with a RecyclerView.” (Monzo) “Reading the code for complicated components is easier.” (Square)
  • 3. Why Adopt Compose ● Less Code ● Declarative API ● Faster Development ● Powerful “Theming layer is vastly more intuitive and legible.” (Twitter) “UI components that were stateless, easy to use and maintain, and intuitive to implement/extend/customize.” (Twitter)
  • 4. Why Adopt Compose ● Less Code ● Declarative API ● Faster Development ● Powerful “We didn’t have to think about things like light and dark mode.” (Cuvva) “Previews in Android Studio have been a big time saver.” (Square)
  • 5. Why Adopt Compose ● Less Code ● Declarative API ● Faster Development ● Powerful “Animations are so easy to add.” (Monzo) “Accessibility apis have been improved.” (Square)
  • 6. What’s wrong with Traditional Android View System?
  • 7. Traditional Android View System Updating UI (button.setBackground(Red))
  • 8. Traditional Android View System Result after update
  • 9. Traditional Android View System Again updating UI (root.removeChild(View))
  • 10. Traditional Android View System These methods change the internal state of the widget.
  • 12. ● All Composable functions must have @Composable annotation; this annotation informs the Compose compiler that this function is intended to convert data into UI. ● The function doesn't return anything. ● This function is fast, idempotent, and free of side-effects. A compose function
  • 13. The declarative widgets 1. Widgets are relatively stateless 2. They do not expose any setter or getter functions 3. Widget are not exposed as objects 4. Composables are responsible for transforming the current application state into a UI every time the observable data updates
  • 14. A compose app example Scaffold Currencies Timeline Column CurrencyPicker Spacer Spacer Spacer Box CurrencyPicker Icon TextField Dropdown TopAppBar BottomBar Navigation Converter TextField Dropdown Base Current 1 USD
  • 16. Things to be aware of
  • 17. Things to be aware of 1. Composable functions can execute in any order 2. Composable functions can run in parallel 3. Recomposition skips as much as possible 4. Recomposition is optimistic 5. Composable functions might run quite frequently
  • 19. State and composition Initial State Value State Value Changes Compose UI Initial Composition Recomposition
  • 20. Use of remember and rememberSaveable 1. remember composables stores single objects in memory by composable functions, retain state across recomposition. 2. rememberSaveable same as remember, except retain states across configuration changes.
  • 21. Other supported types of State 1. LiveData 2. Flow 3. RxJava2 These observable types are converted to State<T> before reading it to Compose.
  • 22. is a pattern of moving state to a composable's caller to make a composable stateless. State Hoisting ➔ value: T: the current value to display ➔ onValueChange: (T) -> Unit: an event that requests the value to change, where T is the proposed new value
  • 23. Managing State in Compose
  • 25. State Management Depending on the complexity of the composable, these are the alternatives to consider: ● Composables for simple UI element state management. ● State holders for complex UI element state management. They own UI elements' state and UI logic. ● Architecture Components ViewModels as a special type of state holder in charge of providing access to the business logic and the screen or UI state.
  • 26. Use of Key Recomposition (new item added to top) Calling a composable multiple times with key will help to identify each composition distinct.
  • 27. Use of Stable Annotating the type with @Stable to allow Compose to favor smart recompositions if Compose is not able to infer the stability of a type.
  • 28. Modifiers to decorate or augment a composable. ● Change the composable's size, layout, behavior, and appearance ● Add information, like accessibility labels ● Process user input ● Add high-level interactions, like making an element clickable, scrollable, draggable, or zoomable
  • 31. Effects and Side-effects in Compose 1. A side-effect is a change to the state of the app that happens outside the scope of a composable function. 2. An effect is a composable function that doesn't emit UI and causes side effects to run when a composition completes. Effect { Side Effect } Called from a controlled environment that is aware of the lifecycle of the composable.
  • 32. LaunchedEffect To call suspend functions safely from inside a composable, LaunchedEffect composable to use. Example: Showing error message on a Snackbar if a UI state contains an error. rememberCoroutineScope To launch a coroutine outside of a composable, but scoped so that it will be automatically canceled once it leaves the composition. Example: Showing a Snackbar when the user taps. DisposableEffect Effects that need to cleaned up after keys change or the composables leaves the composition. @Composable fun HomeScreen(key: Key) { DisposableEffect(key) { val observer = Observer { } addObserver(observer) onDispose { removeObserver(observer) } } } rememberUpdatedState Capture a value in the effect that, while recomposition, the effect will not restart. Example: Splash Screen. SideEffect To share Compose state with objects not managed by compose, SideEffect composable to use. produceState Convert non-Compose state into Compose state. Example: Loading network image and convert it to State object. @Composable fun loadNetworkImage( url: String, imageRepository: ImageRepository ): State<Result<Image>> { return produceState<Result<Image>> { //TODO } }
  • 34. Phases of Android View System Composition Layout Drawing Measurement Placement
  • 35. Compose Architecture Layering Runtime UI Foundation Material Compose is created from a number of modules which are assembled together to form a complete stack Each layer is built upon the lower levels, combining functionality to create higher level components.
  • 36. Use of CompositionLocal ● CompositionLocal is a tool for passing data down through the Composition implicitly. ● It is what the Material theme uses under the hood. ● MaterialTheme is an object that provides three CompositionLocal instances-- colors, typography and shapes

Editor's Notes

  1. Manipulating views manually increases the chance of errors
  2. Picker event notifies the app logic. Then the logic provides data to the top-level composable functions. That functions uses the data to describe the UI by calling other composables. In an imperative UI model, to change a widget, you call a setter on the widget to change its internal state. In Compose, you call the composable function again with new data. Doing so causes the function to be recomposed--the widgets emitted by the function are redrawn, if necessary, with new data. The Compose framework can intelligently recompose only the components that changed.
  3. derivedStateOf: convert one or multiple state objects into another state snapshotFlow: convert Compose's State into Flows