SlideShare a Scribd company logo
1 of 37
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

Similar to Modern app development with Jetpack Compose.pptx

Introduction to State Restoration in Flutter
Introduction to State Restoration in FlutterIntroduction to State Restoration in Flutter
Introduction to State Restoration in FlutterDave Chao
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of SignalsCoding Academy
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesWalking Tree Technologies
 
Memento Pattern Implementation
Memento Pattern ImplementationMemento Pattern Implementation
Memento Pattern ImplementationSteve Widom
 
Automation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in HyderabadAutomation testing by Durgasoft in Hyderabad
Automation testing by Durgasoft in HyderabadDurga Prasad
 
Automation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabadAutomation testing material by Durgasoft,hyderabad
Automation testing material by Durgasoft,hyderabadDurga Prasad
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to ReduxAmin Ashtiani
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with ReactNetcetera
 
React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of reactImran 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
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...Paul Jensen
 
High Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScriptHigh Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScriptLeonardo Borges
 
Unit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdfUnit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdfKaty Slemon
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practicesfloydophone
 
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...Codemotion
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System RequirementsLaura Arrigo
 

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

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
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
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)
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
High Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScriptHigh Performance web apps in Om, React and ClojureScript
High Performance web apps in Om, React and ClojureScript
 
Unit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdfUnit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdf
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
Redux essentials
Redux essentialsRedux essentials
Redux essentials
 
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
React Native - Unleash the power of React in your device - Eduard Tomàs - Cod...
 
Functional Requirements Of System Requirements
Functional Requirements Of System RequirementsFunctional Requirements Of System Requirements
Functional Requirements Of System Requirements
 

Recently uploaded

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Recently uploaded (20)

Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

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