SlideShare a Scribd company logo
1 of 33
Download to read offline
# DAY 3
Compose
Camp
Jetpack
Compose
First
Lets
take
a Recap
of
Day 2
Kotlin is an expressive, statically
typed language for development
on Android. Introduced in 2010
by JetBrains - the team behind
IntelliJ - it is a free, open-
source, and has been used by
over 5.8 million developers
around the world.
Definition
What is
Kotlin?
Shorter and Simpler
Coding
Compatibility with Java
It Comes With a
Smarter and Safer
Compiler
Benefits of Kotlin
We learnt Kotlin
in Day 2
Today, Lets learn
Jetpack Compose
Jetpack Compose is Android's
modern toolkit for building native UI.
It simplifies and accelerates UI
development on Android. Quickly
bring your app to life with less code,
powerful tools, and intuitive Kotlin
APIs .
Features of Jetpack Compose
Fully Compatible with
Java
1
2
3
Fully built using Kotlin
Faster and easier Ul
development
Less code for UI
4
5
6
Compatible with Android
View
Powerful
Intuitive
Why should we choose
Jetpack Compose
View system
• You design UI in XML layout files
• Bind XML layout in Activity class
• Tight - coupling
• Maintenance overhead
MainActivity
.kt
activity_main
.xml
Jetpack Compose!
• Single language
• UI and operations in same place
• Loosely coupling
• Scope for reusable UI components
• Declarative UI
Screen A Screen B
MAIN ACTIVITY
Let's Compose...
android {
buildFeatures {
compose true
}
complaseOptions {
kotlinCompilerExtensionVersion compose_version
}
}
dependencies {
implementation " androidx.compose.ui : ui : $ compose_version "
implementation " androidx.compose.material : material : $ compose_version "
implementation " androidx.compose.ui : ui - tooling - preview : $ compose_version "
implementation ' androidx.activity : activity - compose : 1.3.1 '
debug Implementation " androidx.compose.ui : ui - tooling : $ compose_version "
}
Add Dependency
class MainActivity : Component Activity ( ) {
override fun onCreate ( savedInstanceState : Bundle ? ) {
super.onCreate ( savedInstanceState )
setContent {
// Start composing ...
}
}
}
Composing
• Composable functions should be annotated with @Composable
@Composable
fun MyComposable ( ) {
}
Let's learn some
composables
@Composable
fun Greeting ( name : String ) {
Text ( text = " Hello $ name ! " )
}
Text Hello GDSC-MET
@Composable
fun Compose Demo ( ) {
Button ( onClick = { /*Do Something */ } ) {
Text ( " Click Me " )
}
}
Button
Click me!
Image
@Composable
fun ComposeDemo ( ) {
Image (
painter=painterResource
(R.drawable.android_logo ) ,
contentDescription = " Android logo "
)
}
Basic Layouts...
Without Layout
@Composable
fun Layout Demo ( ) {
Text ( " A " )
Text ( " B " )
Text ( " C " )
}
A
B
C
OVERLAPING
EACHOTHER
(A,B,C)
Column
@Composable
fun Layout Demo ( ) {
Column{
Text ( " A " )
Text ( " B " )
Text ( " C " )
}
}
C
B
A
Row
@Composable
fun Layout Demo ( ) {
Row{
Text ( " A " )
Text ( " B " )
Text ( " C " )
}
}
C
B
A
Now,
Let's see What
MODIFIERS
are...
Modifiers
@Composable
fun Layout Demo ( ) {
Box (
Modifier.background ( Color . Green )
) {
Text (
text = " Hello " ,
modifier = Modifier
.padding ( 8.dp )
.background ( Color . Blue )
)
}
}
Decorate or add the behaviour to Compose Ul
elements.Example:background,padding,etc.
Eg :
Hello
STATE
an important concept of
Jetpack Compoe
•Compose is declarative and as such the only way
to update it is by calling the same composable
with new arguments.
•These arguments are representations of the Ul
state.Any time a state is updated a recomposition
takes place.
State
• Composable functions can store a single object in memory by using the
remember composable .
• A value computed by remember is stored in the Composition during initial
composition, and the stored value is returned during recomposition.remember
can be used to store both mutable and immutable objects .
State Of Compose
• mutableStateOf creates an observable MutableState < T > , which is
an observable type integrated with the compose runtime .
interface MutableState < T > : State < T > {
override var value : T
}
• Any changes to value recomposes Composable function which reads
value .
•Recomposition is the process of calling your
composable functions again when inputs change.
•When Compose recomposes based on new
inputs, it only calls the functions or lambdas that
might have changed , and skips the rest .
Recomposition in Compose
Column {
var textValue by remember { mutableStateOf ( " " ) }
TextField (
value = textValue ,
onValueChange={newValue →
textValue = newValue
}
)
Text ( " You typed : $ textValue " )
}
Example:
Column {
var textValue by remember { mutableStateOf ( " " ) }
TextField (
value = textValue ,
onValueChange={newValue →
textValue = newValue
}
)
Text ( " You typed : $ textValue " )
}
Example:
You typed: Hello Met
Hello Met
Now,
Let's move to
Android Studio

More Related Content

Similar to Compose Camp Day 3 PPT.pptx.pdf

eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan s.r.o.
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack TutorialSimplilearn
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptxGDSCVJTI
 
Javascript ES6
Javascript ES6Javascript ES6
Javascript ES6Huy Doan
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeRamon Ribeiro Rabello
 
Jetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no AndroidJetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no AndroidNelson Glauber Leal
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Journey to JavaScript (from C#)
Journey to JavaScript (from C#)Journey to JavaScript (from C#)
Journey to JavaScript (from C#)Ed Charbeneau
 
MVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possibleMVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possibleQuickBird Studios GmbH
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyManageIQ
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and BeyondComicSansMS
 
Modern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxModern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxMd Shamsul Arafin Mahtab
 

Similar to Compose Camp Day 3 PPT.pptx.pdf (20)

eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack Tutorial
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptx
 
Javascript ES6
Javascript ES6Javascript ES6
Javascript ES6
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
ASP.NET Basics
ASP.NET Basics ASP.NET Basics
ASP.NET Basics
 
Compose Camp - Session3.pptx
Compose Camp - Session3.pptxCompose Camp - Session3.pptx
Compose Camp - Session3.pptx
 
Declarative UIs with Jetpack Compose
Declarative UIs with Jetpack ComposeDeclarative UIs with Jetpack Compose
Declarative UIs with Jetpack Compose
 
Simple React Todo List
Simple React Todo ListSimple React Todo List
Simple React Todo List
 
Compose camp 2.pptx
Compose camp 2.pptxCompose camp 2.pptx
Compose camp 2.pptx
 
Jetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no AndroidJetpack Compose a nova forma de implementar UI no Android
Jetpack Compose a nova forma de implementar UI no Android
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Journey to JavaScript (from C#)
Journey to JavaScript (from C#)Journey to JavaScript (from C#)
Journey to JavaScript (from C#)
 
MVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possibleMVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possible
 
React native
React nativeReact native
React native
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
 
Cordovilla
CordovillaCordovilla
Cordovilla
 
Tml for Objective C
Tml for Objective CTml for Objective C
Tml for Objective C
 
Cpp17 and Beyond
Cpp17 and BeyondCpp17 and Beyond
Cpp17 and Beyond
 
Modern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptxModern app development with Jetpack Compose.pptx
Modern app development with Jetpack Compose.pptx
 

Recently uploaded

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
 
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
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
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
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
(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
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
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
 
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
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
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
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 

Recently uploaded (20)

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
 
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...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
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
 
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
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk 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...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
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
 
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
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
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
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 

Compose Camp Day 3 PPT.pptx.pdf

  • 3. Kotlin is an expressive, statically typed language for development on Android. Introduced in 2010 by JetBrains - the team behind IntelliJ - it is a free, open- source, and has been used by over 5.8 million developers around the world. Definition What is Kotlin? Shorter and Simpler Coding Compatibility with Java It Comes With a Smarter and Safer Compiler Benefits of Kotlin
  • 6. Jetpack Compose is Android's modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs .
  • 7.
  • 8.
  • 9.
  • 10. Features of Jetpack Compose Fully Compatible with Java 1 2 3 Fully built using Kotlin Faster and easier Ul development Less code for UI 4 5 6 Compatible with Android View Powerful Intuitive
  • 11. Why should we choose Jetpack Compose
  • 12. View system • You design UI in XML layout files • Bind XML layout in Activity class • Tight - coupling • Maintenance overhead MainActivity .kt activity_main .xml
  • 13. Jetpack Compose! • Single language • UI and operations in same place • Loosely coupling • Scope for reusable UI components • Declarative UI Screen A Screen B MAIN ACTIVITY
  • 15. android { buildFeatures { compose true } complaseOptions { kotlinCompilerExtensionVersion compose_version } } dependencies { implementation " androidx.compose.ui : ui : $ compose_version " implementation " androidx.compose.material : material : $ compose_version " implementation " androidx.compose.ui : ui - tooling - preview : $ compose_version " implementation ' androidx.activity : activity - compose : 1.3.1 ' debug Implementation " androidx.compose.ui : ui - tooling : $ compose_version " } Add Dependency
  • 16. class MainActivity : Component Activity ( ) { override fun onCreate ( savedInstanceState : Bundle ? ) { super.onCreate ( savedInstanceState ) setContent { // Start composing ... } } } Composing • Composable functions should be annotated with @Composable @Composable fun MyComposable ( ) { }
  • 18. @Composable fun Greeting ( name : String ) { Text ( text = " Hello $ name ! " ) } Text Hello GDSC-MET
  • 19. @Composable fun Compose Demo ( ) { Button ( onClick = { /*Do Something */ } ) { Text ( " Click Me " ) } } Button Click me!
  • 20. Image @Composable fun ComposeDemo ( ) { Image ( painter=painterResource (R.drawable.android_logo ) , contentDescription = " Android logo " ) }
  • 22. Without Layout @Composable fun Layout Demo ( ) { Text ( " A " ) Text ( " B " ) Text ( " C " ) } A B C OVERLAPING EACHOTHER (A,B,C)
  • 23. Column @Composable fun Layout Demo ( ) { Column{ Text ( " A " ) Text ( " B " ) Text ( " C " ) } } C B A
  • 24. Row @Composable fun Layout Demo ( ) { Row{ Text ( " A " ) Text ( " B " ) Text ( " C " ) } } C B A
  • 26. Modifiers @Composable fun Layout Demo ( ) { Box ( Modifier.background ( Color . Green ) ) { Text ( text = " Hello " , modifier = Modifier .padding ( 8.dp ) .background ( Color . Blue ) ) } } Decorate or add the behaviour to Compose Ul elements.Example:background,padding,etc. Eg : Hello
  • 27. STATE an important concept of Jetpack Compoe
  • 28. •Compose is declarative and as such the only way to update it is by calling the same composable with new arguments. •These arguments are representations of the Ul state.Any time a state is updated a recomposition takes place. State
  • 29. • Composable functions can store a single object in memory by using the remember composable . • A value computed by remember is stored in the Composition during initial composition, and the stored value is returned during recomposition.remember can be used to store both mutable and immutable objects . State Of Compose • mutableStateOf creates an observable MutableState < T > , which is an observable type integrated with the compose runtime . interface MutableState < T > : State < T > { override var value : T } • Any changes to value recomposes Composable function which reads value .
  • 30. •Recomposition is the process of calling your composable functions again when inputs change. •When Compose recomposes based on new inputs, it only calls the functions or lambdas that might have changed , and skips the rest . Recomposition in Compose
  • 31. Column { var textValue by remember { mutableStateOf ( " " ) } TextField ( value = textValue , onValueChange={newValue → textValue = newValue } ) Text ( " You typed : $ textValue " ) } Example:
  • 32. Column { var textValue by remember { mutableStateOf ( " " ) } TextField ( value = textValue , onValueChange={newValue → textValue = newValue } ) Text ( " You typed : $ textValue " ) } Example: You typed: Hello Met Hello Met