SlideShare a Scribd company logo
1 of 50
This work is licensed under the Apache 2.0 License
SETTING UP
THE TENT
Letā€™s start the Camp
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
ā— Creating composable activity
ā— Row and column sizing
ā— Modifiers
ā— Image cards
ā— Styling text
ā— State Management
ā— Buttons, Textfields and Snackbars
ā— Lists
Overview
This work is licensed under the Apache 2.0 License
Creating Composable Activity
Traditionally, each screen (or navigation unit) in
the application would be either an activity or a
fragment, each with its own lifecycle bindings ,
but with Jetpack Compose and the Compose
Navigation library, inbuilt templates are
available.
This work is licensed under the Apache 2.0 License
Creating Composable Activity
This work is licensed under the Apache 2.0 License
Annotations
in
EMPTY COMPOSABLE
ACTIVITY
This work is licensed under the Apache 2.0 License
@Preview
@Composable
This annotation is used to
show preview of a composable
function in the Android Studio
preview.
showBackground(=true)
parameter in the code snippet
in the previous slide will make
@Composable use a default
background.
setContent()
This method is
called and
composable
functions are
passed to create a
compose based
screen.
@Composable
These functions let
you define your appā€™s
UI programmatically
by describing how it
should look and
providing data
dependencies,rather
than focusing on the
process of UIā€™s
construction.
Letā€™s discuss some annotations
Rows and Columns
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
c
Column is like a
linear layout with
vertical orientation
and shows each
child below the
previous children.
COLUMN LAYOUT
This work is licensed under the Apache 2.0 License
c
Without use of Column With use of Column
This work is licensed under the Apache 2.0 License
c
ROW LAYOUT
Row is like a linear
layout with a
horizontal orientation
and shows each child
next to the previous
children.
This work is licensed under the Apache 2.0 License
Without use of Rows With use of Rows
This work is licensed under the Apache 2.0 License
For Column For Row
This work is licensed under the Apache 2.0 License
c
This work is licensed under the Apache 2.0 License
c
This work is licensed under the Apache 2.0 License
c
This work is licensed under the Apache 2.0 License
c
Modifiers
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
Modifiers are standard kotlin objects which can be
used to modify certain aspects of a Composable.
To set them , a Composable needs to accept a
modifier as a parameter. We can use common
attribute or appearance like background, padding,
clip, border etc.
What are Modifiers ?
This work is licensed under the Apache 2.0 License
Modifiers let you do these sorts of things:
ā— 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.
This work is licensed under the Apache 2.0 License
c
width() requiredWidth()
It abides size modifiers before it or
max parent dimensions.
It doesnā€™t take layout Constraints
into account and forces it.
This work is licensed under the Apache 2.0 License
How it looks in the emulator
:
This work is licensed under the Apache 2.0 License
offset()
It can be represented as a point in
cartesian space at a specified
distance from a separately-
maintained origin or as a vector that
can be applied to coordinates.
Spacer()
Spacer component is used to display an
empty space. Width and (or) height can be
set for Spacer using Modifier object. This
function accepts Modifier object as
parameter, through which we may set the
Spacerā€™s width or (and) height.
This work is licensed under the Apache 2.0 License
Modify element to add border with
appearance specified with a width, a
color and a shape and clip it. It is
simply annotated with border().
Border
Used to provide extra white space
according to the requirement
around the specific view. It is simply
annotated with padding().
Padding
This work is licensed under the Apache 2.0 License
Image card
This work is licensed under the Apache 2.0 License
Box
A widget that is used to positioned elements one over
another.it will position its children relative to its edges.
The stack is used to draw the children which will overlap
in the order that they are specified. It is annotated with
Box().
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
A card is a container that can
be used as a parent view for
declaring multiple UI elements
inside it. It has an elevation
property that applies a shadow
effect around it. In jetpack
compose, it is equivalent for
Cardview in android.
Card
This work is licensed under the Apache 2.0 License
Adding an image element
This work is licensed under the Apache 2.0 License
This work is licensed under the Apache 2.0 License
Text Styling
This work is licensed under the Apache 2.0 License
Text is a central piece of any UI, and Jetpack
Compose makes it easier to display or write text.
Compose leverages composition of its building blocks,
meaning you donā€™t need to overwrite properties and
methods or extend big classes to have a specific
composable design and logic working the way you
want.
What is text styling ?
This work is licensed under the Apache 2.0 License
Sample code:
This work is licensed under the Apache 2.0 License
The text
design
changed
This work is licensed under the Apache 2.0 License
State
Management
This work is licensed under the Apache 2.0 License
What is State Management ?
ā— State in an app is any value that can change over time.
ā— Any time a state is updated , a recomposition takes place
ā— Composable functions can use the ā€œrememberā€ API to store an object in
memory.
This work is licensed under the Apache 2.0 License
Recomposition is when Jetpack Compose re-executes the
composables that may have changed in response to state
changes, and then updates the Composition to reflect any
changes.
What is Recomposition ?
This work is licensed under the Apache 2.0 License
ā— remember {mutableStateOf()} stores the state
value.
ā— ā€œrememberā€ and ā€œmutableStateOfā€ are completely
independent concepts.
ā— ā€œrememberā€ keeps a value (any value) consistent across
recompositions. ā€œmutableStateOfā€ returns a
MutableState.
What is meant by ā€œrememberā€ keyword ?
This work is licensed under the Apache 2.0 License
Understanding the
code snippet
This work is licensed under the Apache 2.0 License
On click
On click
On click
This work is licensed under the Apache 2.0 License
Buttons, Textfields
and Snackbars
This work is licensed under the Apache 2.0 License
Buttons
In Jetpack Compose buttons, you need to give two arguments for buttons. The first
argument as onClick callback and another one is your button text element. You can
add a Text-Composable or any other Composable as child elements of the Button.
This work is licensed under the Apache 2.0 License
Textfield without icon Textfield with icon
Textfield
s
TextField is a user interface control that is used to allow the user to enter the text.
This widget is used to get the data from the user as numbers or text.
This work is licensed under the Apache 2.0 License
Snackbar is a lightweight widget and they are used to show messages at the
bottom of the application. It was introduced with the Material Design library as
a replacement for a Toast.
An example of snackbar :
Snackbars
This work is licensed under the Apache 2.0 License
LISTS
This work is licensed under the Apache 2.0 License
It is a common requirement when designing user
interface layouts to present information in either
scrollable list or grid configurations. For basic list
requirements,the Row and Column components can
be re-purposed to provide vertical and horizontal
lists of child composable.
What are Lists ?
This work is licensed under the Apache 2.0 License
By using column
This work is licensed under the Apache 2.0 License
By using LazyColumn
This work is licensed under the Apache 2.0 License
LazyColumn Column
Vs
ā— No impact on performance
ā— No need to declare
scrollState
ā— Favourable to use when
there are more number of
elements
ā— Impact on performance
ā— Requires explicit declaration
of scrollState
ā— Efficient to use when there are
less number of elements
This work is licensed under the Apache 2.0 License
THANK YOU
Have fun encouraging your community in becoming
Android Developers!
VOILA HAPPY CAMPING !!!

More Related Content

Similar to Compose Camp Day 2.pptx

Compose Camp#2 - Kotlin Basics.pptx
Compose Camp#2 - Kotlin Basics.pptxCompose Camp#2 - Kotlin Basics.pptx
Compose Camp#2 - Kotlin Basics.pptxSumirVats
Ā 
Android Study Jams - Session 3
Android Study Jams - Session 3Android Study Jams - Session 3
Android Study Jams - Session 3SadhanaParameswaran
Ā 
Compose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptxCompose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptxAmruthasriAmaravati
Ā 
Session-1 edited.pptx
Session-1 edited.pptxSession-1 edited.pptx
Session-1 edited.pptxscienceTech11
Ā 
Android Study Jam Prior Prog S-3
Android Study Jam Prior Prog S-3Android Study Jam Prior Prog S-3
Android Study Jam Prior Prog S-3DSCIGDTUW
Ā 
Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2DSCIGDTUW
Ā 
final ride with compose.pptx
final ride with compose.pptxfinal ride with compose.pptx
final ride with compose.pptxAnkurAgarwal151093
Ā 
Diving deep in compose.pdf
Diving deep in compose.pdfDiving deep in compose.pdf
Diving deep in compose.pdfAnkurAgarwal151093
Ā 
Compose Camp S1.pptx
Compose Camp S1.pptxCompose Camp S1.pptx
Compose Camp S1.pptxGDSCSIT
Ā 
Compose Camp by GDSC NSUT
Compose Camp by GDSC NSUTCompose Camp by GDSC NSUT
Compose Camp by GDSC NSUTMOHITCHAURASIYA6
Ā 
Compose camp 4.pptx
Compose camp 4.pptxCompose camp 4.pptx
Compose camp 4.pptxbcedsc
Ā 
Android Study Jam 2021 Session 4 slides
Android Study Jam 2021 Session 4 slidesAndroid Study Jam 2021 Session 4 slides
Android Study Jam 2021 Session 4 slidesBoston Android
Ā 
Compose_camp_Day_1.pptx
Compose_camp_Day_1.pptxCompose_camp_Day_1.pptx
Compose_camp_Day_1.pptxGanpatParmar1
Ā 
Android Study Jam 2
Android Study Jam 2Android Study Jam 2
Android Study Jam 2DSC GVP
Ā 

Similar to Compose Camp Day 2.pptx (20)

Compose Camp.pptx
Compose Camp.pptxCompose Camp.pptx
Compose Camp.pptx
Ā 
Compose Camp#2 - Kotlin Basics.pptx
Compose Camp#2 - Kotlin Basics.pptxCompose Camp#2 - Kotlin Basics.pptx
Compose Camp#2 - Kotlin Basics.pptx
Ā 
Session-1.pptx
Session-1.pptxSession-1.pptx
Session-1.pptx
Ā 
Android Study Jams - Session 3
Android Study Jams - Session 3Android Study Jams - Session 3
Android Study Jams - Session 3
Ā 
Compose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptxCompose Camp: Introduction to Kotlin.pptx
Compose Camp: Introduction to Kotlin.pptx
Ā 
Session-1 edited.pptx
Session-1 edited.pptxSession-1 edited.pptx
Session-1 edited.pptx
Ā 
Android Study Jam Prior Prog S-3
Android Study Jam Prior Prog S-3Android Study Jam Prior Prog S-3
Android Study Jam Prior Prog S-3
Ā 
Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2
Ā 
final ride with compose.pptx
final ride with compose.pptxfinal ride with compose.pptx
final ride with compose.pptx
Ā 
ComposeCamp.pdf
ComposeCamp.pdfComposeCamp.pdf
ComposeCamp.pdf
Ā 
Diving deep in compose.pdf
Diving deep in compose.pdfDiving deep in compose.pdf
Diving deep in compose.pdf
Ā 
Compose Camp S1.pptx
Compose Camp S1.pptxCompose Camp S1.pptx
Compose Camp S1.pptx
Ā 
Compose Camp by GDSC NSUT
Compose Camp by GDSC NSUTCompose Camp by GDSC NSUT
Compose Camp by GDSC NSUT
Ā 
Compose camp 4.pptx
Compose camp 4.pptxCompose camp 4.pptx
Compose camp 4.pptx
Ā 
Android Study Jam 2021 Session 4 slides
Android Study Jam 2021 Session 4 slidesAndroid Study Jam 2021 Session 4 slides
Android Study Jam 2021 Session 4 slides
Ā 
Compose_camp_Day_1.pptx
Compose_camp_Day_1.pptxCompose_camp_Day_1.pptx
Compose_camp_Day_1.pptx
Ā 
Android Study Jam 2
Android Study Jam 2Android Study Jam 2
Android Study Jam 2
Ā 
session4.pptx
session4.pptxsession4.pptx
session4.pptx
Ā 
session4.pptx
session4.pptxsession4.pptx
session4.pptx
Ā 
day1.docx
day1.docxday1.docx
day1.docx
Ā 

Recently uploaded

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
Ā 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
Ā 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
Ā 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
Ā 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
Ā 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
Ā 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
Ā 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
Ā 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
Ā 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
Ā 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
Ā 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
Ā 
Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...
Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...
Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...Nguyen Thanh Tu Collection
Ā 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
Ā 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
Ā 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
Ā 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
Ā 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
Ā 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
Ā 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
Ā 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
Ā 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
Ā 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
Ā 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
Ā 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
Ā 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
Ā 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
Ā 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
Ā 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
Ā 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Ā 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Ā 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Ā 
Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...
Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...
Tį»”NG ƔN Tįŗ¬P THI VƀO Lį»šP 10 MƔN TIįŗ¾NG ANH NĂM Hį»ŒC 2023 - 2024 CƓ ĐƁP ƁN (NGį»® Ƃ...
Ā 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
Ā 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
Ā 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
Ā 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
Ā 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
Ā 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
Ā 

Compose Camp Day 2.pptx

  • 1. This work is licensed under the Apache 2.0 License SETTING UP THE TENT
  • 2. Letā€™s start the Camp This work is licensed under the Apache 2.0 License
  • 3. This work is licensed under the Apache 2.0 License ā— Creating composable activity ā— Row and column sizing ā— Modifiers ā— Image cards ā— Styling text ā— State Management ā— Buttons, Textfields and Snackbars ā— Lists Overview
  • 4. This work is licensed under the Apache 2.0 License Creating Composable Activity Traditionally, each screen (or navigation unit) in the application would be either an activity or a fragment, each with its own lifecycle bindings , but with Jetpack Compose and the Compose Navigation library, inbuilt templates are available.
  • 5. This work is licensed under the Apache 2.0 License Creating Composable Activity
  • 6. This work is licensed under the Apache 2.0 License Annotations in EMPTY COMPOSABLE ACTIVITY
  • 7. This work is licensed under the Apache 2.0 License @Preview @Composable This annotation is used to show preview of a composable function in the Android Studio preview. showBackground(=true) parameter in the code snippet in the previous slide will make @Composable use a default background. setContent() This method is called and composable functions are passed to create a compose based screen. @Composable These functions let you define your appā€™s UI programmatically by describing how it should look and providing data dependencies,rather than focusing on the process of UIā€™s construction. Letā€™s discuss some annotations
  • 8. Rows and Columns This work is licensed under the Apache 2.0 License
  • 9. This work is licensed under the Apache 2.0 License c Column is like a linear layout with vertical orientation and shows each child below the previous children. COLUMN LAYOUT
  • 10. This work is licensed under the Apache 2.0 License c Without use of Column With use of Column
  • 11. This work is licensed under the Apache 2.0 License c ROW LAYOUT Row is like a linear layout with a horizontal orientation and shows each child next to the previous children.
  • 12. This work is licensed under the Apache 2.0 License Without use of Rows With use of Rows
  • 13. This work is licensed under the Apache 2.0 License For Column For Row
  • 14. This work is licensed under the Apache 2.0 License c
  • 15. This work is licensed under the Apache 2.0 License c
  • 16. This work is licensed under the Apache 2.0 License c
  • 17. This work is licensed under the Apache 2.0 License c
  • 18. Modifiers This work is licensed under the Apache 2.0 License
  • 19. This work is licensed under the Apache 2.0 License Modifiers are standard kotlin objects which can be used to modify certain aspects of a Composable. To set them , a Composable needs to accept a modifier as a parameter. We can use common attribute or appearance like background, padding, clip, border etc. What are Modifiers ?
  • 20. This work is licensed under the Apache 2.0 License Modifiers let you do these sorts of things: ā— 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.
  • 21. This work is licensed under the Apache 2.0 License c width() requiredWidth() It abides size modifiers before it or max parent dimensions. It doesnā€™t take layout Constraints into account and forces it.
  • 22. This work is licensed under the Apache 2.0 License How it looks in the emulator :
  • 23. This work is licensed under the Apache 2.0 License offset() It can be represented as a point in cartesian space at a specified distance from a separately- maintained origin or as a vector that can be applied to coordinates. Spacer() Spacer component is used to display an empty space. Width and (or) height can be set for Spacer using Modifier object. This function accepts Modifier object as parameter, through which we may set the Spacerā€™s width or (and) height.
  • 24. This work is licensed under the Apache 2.0 License Modify element to add border with appearance specified with a width, a color and a shape and clip it. It is simply annotated with border(). Border Used to provide extra white space according to the requirement around the specific view. It is simply annotated with padding(). Padding
  • 25. This work is licensed under the Apache 2.0 License Image card
  • 26. This work is licensed under the Apache 2.0 License Box A widget that is used to positioned elements one over another.it will position its children relative to its edges. The stack is used to draw the children which will overlap in the order that they are specified. It is annotated with Box().
  • 27. This work is licensed under the Apache 2.0 License
  • 28. This work is licensed under the Apache 2.0 License A card is a container that can be used as a parent view for declaring multiple UI elements inside it. It has an elevation property that applies a shadow effect around it. In jetpack compose, it is equivalent for Cardview in android. Card
  • 29. This work is licensed under the Apache 2.0 License Adding an image element
  • 30. This work is licensed under the Apache 2.0 License
  • 31. This work is licensed under the Apache 2.0 License Text Styling
  • 32. This work is licensed under the Apache 2.0 License Text is a central piece of any UI, and Jetpack Compose makes it easier to display or write text. Compose leverages composition of its building blocks, meaning you donā€™t need to overwrite properties and methods or extend big classes to have a specific composable design and logic working the way you want. What is text styling ?
  • 33. This work is licensed under the Apache 2.0 License Sample code:
  • 34. This work is licensed under the Apache 2.0 License The text design changed
  • 35. This work is licensed under the Apache 2.0 License State Management
  • 36. This work is licensed under the Apache 2.0 License What is State Management ? ā— State in an app is any value that can change over time. ā— Any time a state is updated , a recomposition takes place ā— Composable functions can use the ā€œrememberā€ API to store an object in memory.
  • 37. This work is licensed under the Apache 2.0 License Recomposition is when Jetpack Compose re-executes the composables that may have changed in response to state changes, and then updates the Composition to reflect any changes. What is Recomposition ?
  • 38. This work is licensed under the Apache 2.0 License ā— remember {mutableStateOf()} stores the state value. ā— ā€œrememberā€ and ā€œmutableStateOfā€ are completely independent concepts. ā— ā€œrememberā€ keeps a value (any value) consistent across recompositions. ā€œmutableStateOfā€ returns a MutableState. What is meant by ā€œrememberā€ keyword ?
  • 39. This work is licensed under the Apache 2.0 License Understanding the code snippet
  • 40. This work is licensed under the Apache 2.0 License On click On click On click
  • 41. This work is licensed under the Apache 2.0 License Buttons, Textfields and Snackbars
  • 42. This work is licensed under the Apache 2.0 License Buttons In Jetpack Compose buttons, you need to give two arguments for buttons. The first argument as onClick callback and another one is your button text element. You can add a Text-Composable or any other Composable as child elements of the Button.
  • 43. This work is licensed under the Apache 2.0 License Textfield without icon Textfield with icon Textfield s TextField is a user interface control that is used to allow the user to enter the text. This widget is used to get the data from the user as numbers or text.
  • 44. This work is licensed under the Apache 2.0 License Snackbar is a lightweight widget and they are used to show messages at the bottom of the application. It was introduced with the Material Design library as a replacement for a Toast. An example of snackbar : Snackbars
  • 45. This work is licensed under the Apache 2.0 License LISTS
  • 46. This work is licensed under the Apache 2.0 License It is a common requirement when designing user interface layouts to present information in either scrollable list or grid configurations. For basic list requirements,the Row and Column components can be re-purposed to provide vertical and horizontal lists of child composable. What are Lists ?
  • 47. This work is licensed under the Apache 2.0 License By using column
  • 48. This work is licensed under the Apache 2.0 License By using LazyColumn
  • 49. This work is licensed under the Apache 2.0 License LazyColumn Column Vs ā— No impact on performance ā— No need to declare scrollState ā— Favourable to use when there are more number of elements ā— Impact on performance ā— Requires explicit declaration of scrollState ā— Efficient to use when there are less number of elements
  • 50. This work is licensed under the Apache 2.0 License THANK YOU Have fun encouraging your community in becoming Android Developers! VOILA HAPPY CAMPING !!!