SlideShare a Scribd company logo
1 of 46
Download to read offline
JETPACK COMPOSE
- By Aayushma Agrawal, Android Developer
Github code: here
Hi JETPACK Compose
Bye Bye XML!!!!
Contents
Building a practical app using JC
And learning how to render our fav.
Views(Textview, Edittext, Imageview, Button)
and View Groups(Linear Layout) using JC.
WHAT WILL WE BUILDING
TODAY? >>>>>>>
RECYCLERVIEW USING JC
ACTION ITEM?
OPEN ANDROID STUDIO NOW
AND FILE >> NEW PROJECT >>
EMPTY COMPOSE ACTIVITY
YES THIS!!!!!!!!!!
Done? Click on Next>>>>>
YES THIS!!!!!!!!!!
Any fancy name of your
choice!! And FINISH!!
3
Android Studio Building…
2
Still Building…
1
Meanwhile it is building…let’s talk!
Main activity
Major differences
1. Activity extending Component
Activity
2. Previous:-
setContentView(R.layout.xml_file_name)
TO
setContent {
// some alien stuffs
}
Let’s talk textview FIRST
Rendering TEXT IN TEXTVIEW (called TEXT in jc)
Using XML:-
<TextView android:layout_width=“”
………
android:text = “Hello”
Now
Text(text ="Hello ")
TEXT SIZE, MAXLINES, COLOR
Using XML:-
<TextView android:layout_width=“”
………
android:text = “Hello”
android:textColor = “”
android:maxLines =“2”
Now
Text(text = "Hello $name!",
fontSize = 18.sp,
color = Color.Magenta,
maxLines = 1)
PLAY AROUND AND EXPLORE BY YOURSELF
● How to create style and add it to Text
● How to NOT add hardcoded text and pick from strings.xml?
(Hint:- stringResource attribute)
● Applying click on Textview using TextButton
But did you think?
Where all to write this Text ??
Ofcourse, there are no layout files now, so we have to write
in Kotlin file, but how?
Of course It’s Kotlin file, so inside functions!
To Observe:
Greeting is a
function(but
starts that with
a capital
letter, this is
naming
convention in JC
Annotated with
@Composable
What is @Composable ?
Whichever function has @Composable with them, compiler
knows, this has to be drawn/rendered on the screen!!
Any composable function can be called only from other
composable functions.
Name of composable function is chosen as ‘Noun’ rather than
verb or adjectives.
IMAGEVIEW
Time to move to our next old fav. view!
THINKING OF IMAGEVIEW...
General operations with Imageview are:-
1. Loading image from resources
2. Loading image from URL (We will explore using Coil lib. here)
3. Setting aspect ratio of image (playaround and explore this)
IMAGEVIEW (IMAGE HERE) CONTINUES…
1. Loading image from resources
Use painterResource and
pass it the id of
drawable you want to
load.
Imageview is called
Image in JC
IMAGEVIEW (IMAGE HERE) CONTINUES…
2. Loading image from URL
In JC, we have to use third party library such as Coil or
Landscapist.
Steps:
● Add Coil dependency
implementation "io.coil-kt:coil-compose:2.2.2"
● Add Internet permission in Manifest
<uses-permission android:name="android.permission.INTERNET"/>
● Load Image from URL
IMAGEVIEW (IMAGE HERE) CONTINUES…
● Load Image from URL
AsyncImage(modifier = Modifier.size(width = 50.dp,
height = 50.dp),
model = “https://i.ibb.co/TPMpD3f/argentina.png”,
contentDescription = "Image")
The above code shows
loading an Image from URL
using AsyncImage where
width and height of Image
is 50dp.
button
Upcoming Button in JC >>>>>>>
Button in jc
Loaded using class Button
Rendering Button with text and click functionality
The below image shows using predefined Button class with
text as “Vote” and on click will render a Toast message.
WHAT ARE VIEWS WITHOUT
VIEWGROUPS?
VIEWGROUPS IN JC
UPCOMING >>>
VIEWGROUPS IN JC
● ROW
● COLUMN
● BOX (Out of Scope in current slide)
ROW
ROW = Linear Layout with Horizontal Direction
Supports gravity, weight etc.
COLUMNS
COLUMN = Linear Layout with Vertical Direction
Supports gravity, weight etc.
Imgsource: from https://www.codemag.com/Article/2105061/A-Practical-Introduction-to-Jetpack-Compose-Android-Apps
To design above layout in
XML using Linear Layout we
would have taken one
parent Linear Layout with
horizontal orientation and
inside it would be
Imageview and a child
LinearLayout with vertical
orientation and two
Textviews
Imgsource: from https://www.codemag.com/Article/2105061/A-Practical-Introduction-to-Jetpack-Compose-Android-Apps
Similarly , here we would
take 1 ROW having 2
columns.
1st Column with Image of
country and 2nd
column containing country
name and continent
CODE SNIPPETS
EXPLANATION OF CODE SNIPPET
L157 begins with defining a Row, defining observe to define
width and height(or other attributes like padding, aligning)
of view/viewgroups we use Modifiers
We have given the Row’s width as fillMaxWidth which means
match_parent and height by default is taken as wrap content
And Row has padding of 16dp.
Explanation of Code snippet continued..
Line 162 has Imageview like shown in the video to load flag
of the FIFA country using URL(which is dynamic)
Line 164 shows creating a Column with two textviews(Text
components) inside it and each Column has a padding of 16dp
and by default width and height as wrap_content.
RECYCLERVIEW
The most easy, useful and interesting part is >>>
LAZYCOLUMN
LazyColumn in JC = Recyclerview with vertical Scroll
direction
CODE SNIPPET
EXPLANATION OF CODE SNIPPET
L177 defines LazyColumn with width as fillMaxWidth (meaning
match_parent) and height as wrap content
L181 defines source of data which should be loaded into Recyclerview.
L182 defines content of each item within recyclerview which is rendered
by user defined method ImageWithTitleSubTitleComponent (Please check Github
for full source code)
Big Thanks!
Jetpack compose book by Alex Styl
https://medium.com/mobile-app-development-publication/loading-image-in-android-jetpack-compose-ma
de-easy-8cb593b26260
https://www.codemag.com/Article/2105061/A-Practical-Introduction-to-Jetpack-Compose-Android-Apps
Picture or Icon Credits to flaticon.com and FreePik
My personal experience with Jetpack
I would definitely recommend it to try because of its ease
to implement things in faster manner eg. Recyclerview,
Cardview with stroke/border etc.
Mostly about playing around and getting comfortable with
Modifiers to see its ease and magic!
GOOD LUCK!
Further scope
1. Understanding Recomposition
2. Exploring all View components like EditText, Button,
Spinner, Recyclerview etc.
3. Exploring Box, ConstraintLayout in JC
THANK YOU
Feel Free to Reach out for your Ques. @ Twitter/LinkedIn
Github project link here

More Related Content

What's hot

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
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxtakshilkunadia
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack TutorialSimplilearn
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourMatthew Clarke
 
Jetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIJetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIGilang Ramadhan
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017Hardik Trivedi
 
Understanding iOS from an Android perspective
Understanding iOS from an Android perspectiveUnderstanding iOS from an Android perspective
Understanding iOS from an Android perspectiveLauren Yew
 
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
 
Android Jetpack
Android Jetpack Android Jetpack
Android Jetpack Tudor Sirbu
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to ReactRob Quick
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Languageintelliyole
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftCommit University
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 
Reactjs workshop
Reactjs workshop Reactjs workshop
Reactjs workshop Ahmed rebai
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation MobileAcademy
 
Android resources
Android resourcesAndroid resources
Android resourcesma-polimi
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstMd. Aftab Uddin Kajal
 

What's hot (20)

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...
 
Kotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptxKotlin Basics & Introduction to Jetpack Compose.pptx
Kotlin Basics & Introduction to Jetpack Compose.pptx
 
Kotlin Jetpack Tutorial
Kotlin Jetpack TutorialKotlin Jetpack Tutorial
Kotlin Jetpack Tutorial
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning Tour
 
Jetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UIJetpack Compose - Android’s modern toolkit for building native UI
Jetpack Compose - Android’s modern toolkit for building native UI
 
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017Introduction to kotlin for android app development   gdg ahmedabad dev fest 2017
Introduction to kotlin for android app development gdg ahmedabad dev fest 2017
 
Understanding iOS from an Android perspective
Understanding iOS from an Android perspectiveUnderstanding iOS from an Android perspective
Understanding iOS from an Android perspective
 
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
 
Android Jetpack
Android Jetpack Android Jetpack
Android Jetpack
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
KMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and SwiftKMM survival guide: how to tackle struggles between Kotlin and Swift
KMM survival guide: how to tackle struggles between Kotlin and Swift
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Reactjs workshop
Reactjs workshop Reactjs workshop
Reactjs workshop
 
Angular
AngularAngular
Angular
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation
 
Android resources
Android resourcesAndroid resources
Android resources
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
 

Similar to Jetpack Compose beginner.pdf

Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360RapidValue
 
iOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsiOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsAsim Rais Siddiqui
 
Lecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptxLecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptxGevitaChinnaiah
 
[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In ActionHazem Saleh
 
Desenvolva um game para android ou iPhone
Desenvolva um game para android ou iPhoneDesenvolva um game para android ou iPhone
Desenvolva um game para android ou iPhoneTiago Oliveira
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react jsBOSC Tech Labs
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptxRishiGandhi19
 
Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework					Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework Shelly Megan
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
What's new in Android - Google I/O Extended Bangkok 2022
What's new in Android - Google I/O Extended Bangkok 2022What's new in Android - Google I/O Extended Bangkok 2022
What's new in Android - Google I/O Extended Bangkok 2022Somkiat Khitwongwattana
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basicrafaqathussainc077
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02Ankit Dubey
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React NativeEric Deng
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbitCarWash1
 
project_proposal_osrf
project_proposal_osrfproject_proposal_osrf
project_proposal_osrfom1234567890
 

Similar to Jetpack Compose beginner.pdf (20)

Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360
 
iOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsiOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI Components
 
Lecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptxLecture 2 Styling and Layout in React Native.pptx
Lecture 2 Styling and Layout in React Native.pptx
 
[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action[Devoxx Morocco 2015] Apache Cordova In Action
[Devoxx Morocco 2015] Apache Cordova In Action
 
Desenvolva um game para android ou iPhone
Desenvolva um game para android ou iPhoneDesenvolva um game para android ou iPhone
Desenvolva um game para android ou iPhone
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
How to create components in react js
How to create components in react jsHow to create components in react js
How to create components in react js
 
ReactJS.pptx
ReactJS.pptxReactJS.pptx
ReactJS.pptx
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx
 
-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx
 
Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework					Create Location Sharing apps using the Ionic framework
Create Location Sharing apps using the Ionic framework
 
Simple React Todo List
Simple React Todo ListSimple React Todo List
Simple React Todo List
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
What's new in Android - Google I/O Extended Bangkok 2022
What's new in Android - Google I/O Extended Bangkok 2022What's new in Android - Google I/O Extended Bangkok 2022
What's new in Android - Google I/O Extended Bangkok 2022
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
 
Ajp notes-chapter-02
Ajp notes-chapter-02Ajp notes-chapter-02
Ajp notes-chapter-02
 
Notes Unit4.pptx
Notes Unit4.pptxNotes Unit4.pptx
Notes Unit4.pptx
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
Volley lab btc_bbit
Volley lab btc_bbitVolley lab btc_bbit
Volley lab btc_bbit
 
project_proposal_osrf
project_proposal_osrfproject_proposal_osrf
project_proposal_osrf
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Jetpack Compose beginner.pdf

  • 1. JETPACK COMPOSE - By Aayushma Agrawal, Android Developer Github code: here
  • 3. Contents Building a practical app using JC And learning how to render our fav. Views(Textview, Edittext, Imageview, Button) and View Groups(Linear Layout) using JC.
  • 4. WHAT WILL WE BUILDING TODAY? >>>>>>>
  • 6. ACTION ITEM? OPEN ANDROID STUDIO NOW AND FILE >> NEW PROJECT >> EMPTY COMPOSE ACTIVITY
  • 8. YES THIS!!!!!!!!!! Any fancy name of your choice!! And FINISH!!
  • 11. 1 Meanwhile it is building…let’s talk!
  • 13. Major differences 1. Activity extending Component Activity 2. Previous:- setContentView(R.layout.xml_file_name) TO setContent { // some alien stuffs }
  • 15. Rendering TEXT IN TEXTVIEW (called TEXT in jc) Using XML:- <TextView android:layout_width=“” ……… android:text = “Hello” Now Text(text ="Hello ")
  • 16. TEXT SIZE, MAXLINES, COLOR Using XML:- <TextView android:layout_width=“” ……… android:text = “Hello” android:textColor = “” android:maxLines =“2” Now Text(text = "Hello $name!", fontSize = 18.sp, color = Color.Magenta, maxLines = 1)
  • 17. PLAY AROUND AND EXPLORE BY YOURSELF ● How to create style and add it to Text ● How to NOT add hardcoded text and pick from strings.xml? (Hint:- stringResource attribute) ● Applying click on Textview using TextButton
  • 18. But did you think? Where all to write this Text ?? Ofcourse, there are no layout files now, so we have to write in Kotlin file, but how?
  • 19. Of course It’s Kotlin file, so inside functions! To Observe: Greeting is a function(but starts that with a capital letter, this is naming convention in JC Annotated with @Composable
  • 20. What is @Composable ? Whichever function has @Composable with them, compiler knows, this has to be drawn/rendered on the screen!! Any composable function can be called only from other composable functions. Name of composable function is chosen as ‘Noun’ rather than verb or adjectives.
  • 21. IMAGEVIEW Time to move to our next old fav. view!
  • 22. THINKING OF IMAGEVIEW... General operations with Imageview are:- 1. Loading image from resources 2. Loading image from URL (We will explore using Coil lib. here) 3. Setting aspect ratio of image (playaround and explore this)
  • 23. IMAGEVIEW (IMAGE HERE) CONTINUES… 1. Loading image from resources Use painterResource and pass it the id of drawable you want to load. Imageview is called Image in JC
  • 24. IMAGEVIEW (IMAGE HERE) CONTINUES… 2. Loading image from URL In JC, we have to use third party library such as Coil or Landscapist. Steps: ● Add Coil dependency implementation "io.coil-kt:coil-compose:2.2.2" ● Add Internet permission in Manifest <uses-permission android:name="android.permission.INTERNET"/> ● Load Image from URL
  • 25. IMAGEVIEW (IMAGE HERE) CONTINUES… ● Load Image from URL AsyncImage(modifier = Modifier.size(width = 50.dp, height = 50.dp), model = “https://i.ibb.co/TPMpD3f/argentina.png”, contentDescription = "Image") The above code shows loading an Image from URL using AsyncImage where width and height of Image is 50dp.
  • 27. Button in jc Loaded using class Button
  • 28. Rendering Button with text and click functionality The below image shows using predefined Button class with text as “Vote” and on click will render a Toast message.
  • 29. WHAT ARE VIEWS WITHOUT VIEWGROUPS?
  • 31. VIEWGROUPS IN JC ● ROW ● COLUMN ● BOX (Out of Scope in current slide)
  • 32. ROW ROW = Linear Layout with Horizontal Direction Supports gravity, weight etc.
  • 33. COLUMNS COLUMN = Linear Layout with Vertical Direction Supports gravity, weight etc.
  • 34. Imgsource: from https://www.codemag.com/Article/2105061/A-Practical-Introduction-to-Jetpack-Compose-Android-Apps To design above layout in XML using Linear Layout we would have taken one parent Linear Layout with horizontal orientation and inside it would be Imageview and a child LinearLayout with vertical orientation and two Textviews
  • 35. Imgsource: from https://www.codemag.com/Article/2105061/A-Practical-Introduction-to-Jetpack-Compose-Android-Apps Similarly , here we would take 1 ROW having 2 columns. 1st Column with Image of country and 2nd column containing country name and continent
  • 37. EXPLANATION OF CODE SNIPPET L157 begins with defining a Row, defining observe to define width and height(or other attributes like padding, aligning) of view/viewgroups we use Modifiers We have given the Row’s width as fillMaxWidth which means match_parent and height by default is taken as wrap content And Row has padding of 16dp.
  • 38. Explanation of Code snippet continued.. Line 162 has Imageview like shown in the video to load flag of the FIFA country using URL(which is dynamic) Line 164 shows creating a Column with two textviews(Text components) inside it and each Column has a padding of 16dp and by default width and height as wrap_content.
  • 39. RECYCLERVIEW The most easy, useful and interesting part is >>>
  • 40. LAZYCOLUMN LazyColumn in JC = Recyclerview with vertical Scroll direction
  • 42. EXPLANATION OF CODE SNIPPET L177 defines LazyColumn with width as fillMaxWidth (meaning match_parent) and height as wrap content L181 defines source of data which should be loaded into Recyclerview. L182 defines content of each item within recyclerview which is rendered by user defined method ImageWithTitleSubTitleComponent (Please check Github for full source code)
  • 43. Big Thanks! Jetpack compose book by Alex Styl https://medium.com/mobile-app-development-publication/loading-image-in-android-jetpack-compose-ma de-easy-8cb593b26260 https://www.codemag.com/Article/2105061/A-Practical-Introduction-to-Jetpack-Compose-Android-Apps Picture or Icon Credits to flaticon.com and FreePik
  • 44. My personal experience with Jetpack I would definitely recommend it to try because of its ease to implement things in faster manner eg. Recyclerview, Cardview with stroke/border etc. Mostly about playing around and getting comfortable with Modifiers to see its ease and magic! GOOD LUCK!
  • 45. Further scope 1. Understanding Recomposition 2. Exploring all View components like EditText, Button, Spinner, Recyclerview etc. 3. Exploring Box, ConstraintLayout in JC
  • 46. THANK YOU Feel Free to Reach out for your Ques. @ Twitter/LinkedIn Github project link here