Statistics
3
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-02-14

AuthorDenis Buketa

No description

Tags
No tags
Publish Year: 2021
Language: 英文
Pages: 362
File Format: PDF
File Size: 29.1 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Jetpack Compose by Tutorials Tino Balint & Denis Buketa Copyright ©2021 Razeware LLC. Notice of Rights All rights reserved. No part of this book or corresponding materials (such as text, images, or source code) may be reproduced or distributed by any means without prior written permission of the copyright owner. Notice of Liability This book and all corresponding materials (such as source code) are provided on an “as is” basis, without warranty of any kind, express of implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection with the software or the use of other dealing in the software. Trademarks All trademarks and registered trademarks appearing in this book are the property of their own respective owners. Jetpack Compose by Tutorials raywenderlich.com 2
Dedications “I would like to thank all the people who were with me while writing this book. To my family which encouraged me and was a shoulder to lean on during the long working hours. To my friends who kept shifting schedules in order to match with mine and were emotional support. To Marko and Ivana, who threw me a surprise party when the book was finished. Lastly, to my raywenderlich.com team. You were always positive, helped me grow and become a better author. All of you are the reason I was able to write my first book and become a book author.” — Tino Balint “To my family and friends. Thank you for supporting me and being patient as I worked on this book. I’ve told you “no” so many times when you called me to hang out, but you never made me feel guilty about it. Many thanks to the team at raywenderlich.com, my co-author, the editors and everyone involved in this book. You’ve been a great support and I’ve enjoyed working with you.” — Denis Buketa Jetpack Compose by Tutorials raywenderlich.com 3
About the Authors Denis Buketa is an author of this book. He’s an Android developer who always tries to learn new things and get out of his comfort zone. Besides programming, he’s a huge fan of audiobooks and podcasts. He also enjoys hanging out with friends and watching any kind of sport while having a cold beer. Tino Balint is another author of this book. He’s an Android developer with a passion for learning and growth. Likes all geeky things like reading and watching sci-fi and fantasy, playing video and board games. Besides indoor activities, he also likes working out, being in nature, scuba diving, trekking and other outdoorsy action. About the Editors Antonio Roa-Valverde is a tech editor of this book. He’s a software engineer specialized in Android development. He has a background in Computer Science and R&D, which explains his interest in innovation and shaping new products with potential impact on people. He’s also a co-organizer of the GDG Innsbruck and GDG Munich. He can be found close to the mountains, either hiking, riding the mountain-bike or catching some curvy roads by motorcycle. Dean Djermanović is another tech editor of this book. He’s an experienced Android developer from Croatia working at the Five agency where he worked on many interesting apps like the Rosetta Stone app for learning languages which has over 10 million downloads. Previously, he’s been a part of two other mobile development agencies in Croatia where he worked on many smaller custom mobile solutions for various industries. He’s also a part- time Android lecturer at the Algebra University College in Zagreb. Very passionate about Android, software development, and technology in general. Always trying to learn more, exchange knowledge with others, and improve in every aspect of life. In his free time, Dean likes to work out at the gym, ride a bike, read a good book or watch a good movie. Jetpack Compose by Tutorials raywenderlich.com 4
Sandra Grauschopf is the editor of this book. She is a freelance writer, editor, and content strategist as well as the Editing Team Lead at raywenderlich.com. She loves to untangle tortured sentences and to travel the world with a trusty book in her hand. Filip Babić is the final pass editor for this book. He’s an Android developer & Video Instructor with a huge passion for learning and teaching. He’s also a public speaker at conferences, mentor to many people in his spare time and a content creator producing written content on his personal blog and on the raywenderlich.com website and video content for his IT-related podcast. He’s also a Google Developer Expert for Android & Kotlin. When he’s not talking about coding, writing about coding or coding in general, he plays D&D, Magic The Gathering, video games and does rock climbing. About the Artist Vicki Wenderlich is the designer and artist of the cover of this book. She is Ray’s wife and business partner. She is a digital artist who creates illustrations, game art and a lot of other art or design work for the tutorials and books on raywenderlich.com. When she’s not making art, she loves hiking, a good glass of wine and attempting to create the perfect cheese plate. Jetpack Compose by Tutorials raywenderlich.com 5
Table of Contents: Overview Book License 13............................................................................................. Before You Begin 14................................................................ What You Need 15........................................................................................ Book Source Code & Forums 16............................................................. Introduction 17.............................................................................................. Section I: Getting Started with Jetpack Compose 21... Chapter 1: Developing UI in Android 22................................. Chapter 2: Learning Jetpack Compose Fundamentals 52 Chapter 3: Building Layout Groups in Compose 87............ Chapter 4: Building Lists with Jetpack Compose 109........ Section II: Composing User Interfaces 130...................... Chapter 5: Combining Composables 131............................... Chapter 6: Using Compose Modifiers 157.............................. Chapter 7: Managing State in Compose 183......................... Chapter 8: Applying Material Design to Compose 209..... Section III: Building Complex Apps with Jetpack Compose 255............................................................................. Chapter 9: Using ConstraintSets in Composables 256...... Chapter 10: Building Complex UI in Jetpack Compose 283...................................................................................... Chapter 11: Reacting to Compose Lifecycle 305................. Jetpack Compose by Tutorials raywenderlich.com 6
Chapter 12: Animating Properties Using Compose 322... Chapter 13: Adding View Compatibility 344......................... Conclusion 361.............................................................................................. Jetpack Compose by Tutorials raywenderlich.com 7
Table of Contents: Extended Book License 13. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Before You Begin 14. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . What You Need 15. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Book Source Code & Forums 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction 17. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to read this book 18. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section I: Getting Started with Jetpack Compose 21. . Chapter 1: Developing UI in Android 22. . . . . . . . . . . . . . . . . . . . . . . . Unwrapping the Android UI toolkit 23. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction to Jetpack Compose 39. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jetpack Compose’s tech stack 48. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 50. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 51. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 2: Learning Jetpack Compose Fundamentals 52. . . . . . . Composable functions 53. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Basic composable functions 55. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Text 57. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Previewing changes 62. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TextField 64. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Buttons 69. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Progress Bars 78. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . AlertDialog 81. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 85. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 86. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3: Building Layout Groups in Compose 87. . . . . . . . . . . . . Using basic layouts in Jetpack Compose 88. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jetpack Compose by Tutorials raywenderlich.com 8
Linear layouts 89. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Boxes 94. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Scaffold 100. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 107. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 108. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 4: Building Lists with Jetpack Compose 109. . . . . . . . . . . Using vertical scrolling modifiers 110. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using horizontal scrolling modifiers 113. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lists in Compose 115. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Grids in Compose 122. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 129. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 129. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Section II: Composing User Interfaces 130. . . . . . . . . . . . Chapter 5: Combining Composables 131. . . . . . . . . . . . . . . . . . . . . . . Application features 132. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Project overview 133. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Thinking in Compose 136. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bottom-up approach 137. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the Note composable 138. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Building the app drawer composable 142. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Putting all the pieces together 154. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 156. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 156. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 6: Using Compose Modifiers 157. . . . . . . . . . . . . . . . . . . . . . Modifiers 158. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chaining modifiers 160. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Rounding out the NoteColor 163. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding NoteColor to Note 167. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding a background to Note 168. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Centering Text & Checkbox composables 170. . . . . . . . . . . . . . . . . . . . . . . . . . . Jetpack Compose by Tutorials raywenderlich.com 9
Centering NoteColor 171. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Taking advantage of the modifier parameter 172. . . . . . . . . . . . . . . . . . . . . . . . Styling title and content 174. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding the Color composable 176. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 182. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 182. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 7: Managing State in Compose 183. . . . . . . . . . . . . . . . . . . . Understanding state 184. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Handling state with Android UI Toolkit 185. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Handling state with unidirectional data flow 186. . . . . . . . . . . . . . . . . . . . . . . . Compose & ViewModel 188. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the Notes screen 190. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the app bar 193. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stateless composables 196. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Extracting a stateless composable 205. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 208. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 8: Applying Material Design to Compose 209. . . . . . . . . Opening the Notes screen 210. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Resurrecting the app drawer 213. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding the FAB 219. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding an entry point 221. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding the top bar 224. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Opening the Save Note screen in Editing mode 231. . . . . . . . . . . . . . . . . . . . . Creating a content composable 233. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wrapping up the Save Note screen 239. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Material Design composables in the Notes screen 248. . . . . . . . . . . Theming in Compose 251. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 254. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 254. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jetpack Compose by Tutorials raywenderlich.com 10
Section III: Building Complex Apps with Jetpack Compose 255. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 9: Using ConstraintSets in Composables 256. . . . . . . . . Understanding ConstraintLayout 257. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ConstraintLayout in Jetpack Compose 258. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implementing the app drawer layout 260. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the app drawer header 263. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implementing the app drawer’s body 271. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Advanced features of ConstraintLayout 275. . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 282. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 10: Building Complex UI in Jetpack Compose 283. . . . Building the home screen 284. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Building the Subreddits screen 295. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 304. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 11: Reacting to Compose Lifecycle 305. . . . . . . . . . . . . . . Events in Compose 306. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implementing the community chooser 308. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Implementing the back button handler 313. . . . . . . . . . . . . . . . . . . . . . . . . . . . . Effects in Compose 315. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Migrate effects 319. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 321. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 321. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 12: Animating Properties Using Compose 322. . . . . . . . Building JoinButton 323. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding JoinButton to Post 326. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Animating the JoinButton background 328. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using transitions to animate JoinButton 330. . . . . . . . . . . . . . . . . . . . . . . . . . . . Animating composable content 335. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Adding experimental annotations 341. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 343. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jetpack Compose by Tutorials raywenderlich.com 11
Chapter 13: Adding View Compatibility 344. . . . . . . . . . . . . . . . . . . Introducing the Chat screen and the Trending view 345. . . . . . . . . . . . . . . . Using composables with the View framework 347. . . . . . . . . . . . . . . . . . . . . . Using View with Jetpack Compose 351. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Key points 360. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Where to go from here? 360. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Conclusion 361. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jetpack Compose by Tutorials raywenderlich.com 12
LBook License By purchasing Jetpack Compose by Tutorials, you have the following license: • You are allowed to use and/or modify the source code in Jetpack Compose by Tutorials in as many apps as you want, with no attribution required. • You are allowed to use and/or modify all art, images and designs that are included in Jetpack Compose by Tutorials in as many apps as you want, but must include this attribution line somewhere inside your app: “Artwork/images/designs: from Jetpack Compose by Tutorials, available at www.raywenderlich.com”. • The source code included in Jetpack Compose by Tutorials is for your personal use only. You are NOT allowed to distribute or sell the source code in Jetpack Compose by Tutorials without prior authorization. • This book is for your personal use only. You are NOT allowed to sell this book without prior authorization, or distribute it to friends, coworkers or students; they would need to purchase their own copies. All materials provided with this book are provided on an “as is” basis, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software. All trademarks and registered trademarks appearing in this guide are the properties of their respective owners. raywenderlich.com 13
Before You Begin This section tells you a few things you need to know before you get started, such as what hardware and software you’ll need, where to find the project files for this book, and more. raywenderlich.com 14
iWhat You Need To follow along with this book, you’ll need the following: • Kotlin 1.4: Since Jetpack Compose relies on a special Kotlin compiler, you need Kotlin 1.4 both to write the code and for the compiler to process special Jetpack Compose annotations. • Android Studio Canary: Jetpack Compose is still in its infancy, in an alpha version, and you need to use bleeding edge versions of Android Studio to use it. Currently, that’s an Android Studio Canary build — currently the Arctic Fox release. • Android 5.1+: The minimumSdkVersion for the projects targets API 21, so you need a device or an emulator running API 21 or higher. • Jetpack Compose Beta04 or greater: This is the Jetpack Compose version you’ll use in the book, and it represents one of the latest versions out there. But because Jetpack Compose is updated every few weeks, there might be a newer version available by the time you read this. We suggest following the book and using the projects with the version we used. You can always explore newer versions of the toolkit, but you might have to apply different migrations to the code. After all, things change frequently in beta versions! raywenderlich.com 15
iiBook Source Code & Forums Where to download the materials for this book The materials for this book can be cloned or downloaded from the GitHub book materials repository: • https://github.com/raywenderlich/jet-materials/tree/editions/1.1 Forums We’ve also set up an official forum for the book at forums.raywenderlich.com. This is a great place to ask questions about the book or to submit any errors you may find. raywenderlich.com 16
iiiIntroduction If you’ve been an Android developer even for a few months, you probably thought that the UI toolkit you use every day is not that easy to grasp. Over the years, as Android developed and grew as a platform, the tools for building user interfaces became more powerful and the design system became more beautiful. Sadly, with all those changes and with newer versions of Android, the process of building interfaces became more complex. Additionally, it became increasingly harder to write code that supports all Android versions, as many new APIs and features aren’t fully backwards compatible. That means that building components from the standard toolkit doesn’t guarantee that those components will work on older versions of the operating system. Moreover, as you start learning Android development, the first thing you notice is the overwhelming number of different programming and markup languages you need to learn. Not only do you find Android apps written in Kotlin or Java, but you also have to learn Groovy for your build scripts and XML for your UI development. This further increases the complexity of learning Android development, and it makes it harder to follow the code. You have to read through multiple different files, just to learn how a single feature of the project works. If only there was a tool that uses Kotlin, has a clear syntax and lets you develop UI without much sweat… raywenderlich.com 17
Well, look no more! Jetpack Compose is the one UI toolkit to rule them all. It’s a fresh look at building user interfaces, providing: • A Kotlin-powered API. • Declarative ways to build the UI so it reacts to state changes. • A powerful and composable set of components that you can combine, style and animate. In this book, you’ll learn how to build a powerful app using Jetpack Compose, how to style your apps using Material Design, special animations and state transitions, how to use modifiers and much more! This book will serve you as a central point that holds all the information you need to dive deep into Jetpack Compose, then apply it to your personal and production level projects. How to read this book The book is aimed at Android developers who aren’t familiar with Jetpack Compose and developers who know a little about the toolkit, but haven’t had the chance to use it. If you’re completely new to Jetpack Compose, we recommend reading it one chapter at a time, in the order of sections and chapters shown in the table of contents. If you’re familiar with the fundamentals of Jetpack Compose, you can skip to “Section II: Composing User Interfaces” instead. There, you’ll continue learning about custom UI components, state management and best practices for styling your UI. If you’re already using Jetpack Compose in your projects but want to know about more complex topics and interoperability with legacy UI toolkits, jump to “Section III: Building Complex Apps With Jetpack Compose”. You’ll build complex use cases on a real-world project and learn about animations and the Compose lifecycle. At whatever level of knowledge you are, it’s useful to check out the book structure and its contents. This book is split into three main sections. Jetpack Compose by Tutorials Introduction raywenderlich.com 18
Section I: Getting Started With Jetpack Compose Android UI Toolkit is over 10 years old now! Over the years, it has received numerous updates in terms of functionality, types of UI elements it provides and optimizations. But because of the way the UI team initially developed the toolkit, it also grew in complexity and the amount of code for even the simplest of components. Finally, in 2020, a miracle happened: Jetpack Compose. The new UI toolkit was announced and started being seriously developed by Google. Jetpack Compose is a new and fresh toolkit, built completely in Kotlin, that offers a clean and declarative way to develop custom components and beautiful interfaces. In this section, you’ll learn all about: • The fundamental components Jetpack Compose provides. • How to build common user interface components such as containers, navigation controls and lists. In these four chapters, you’ll dive deep into the API and learn so much about this wonderful new UI toolkit. Section II: Composing User Interfaces When working on apps and user interfaces, it’s not only important to know what each piece of the interface should be, but also how all these pieces come together to build a beautiful and fully-functional design that’ll wow your users. Now that you’ve amassed quite a lot of knowledge about the basics of Jetpack Compose and its fundamental UI elements, you’re ready to dive deeper into building custom Compose elements, managing their state in a performant way and styling them using modifiers and built-in Material Design features. Over the next four chapters, you’ll learn how to: • Attach LiveData structures to your state management. • Rely on different styling modifiers. • Combine these topics to create a powerful UI! Jetpack Compose by Tutorials Introduction raywenderlich.com 19
Section III: Building Complex Apps With Jetpack Compose Now that you’ve built your app’s basic UI, it’s time to take it to another level. In this section, you’ll apply custom, complex designs that help you stand out from thousands of similar apps! This usually involves building complex custom components and applying animations to represent state changes when your users interact with the UI. Over the next five chapters, you’ll dive deeper into the Jetpack Compose API to learn how to: • Connect Compose UI to legacy Android code. • React to Compose UI lifecycles. • Animate different state changes and user interactions. In the process, you’ll build an awesome app that represents a real-world project and you’ll apply some best practices to improve the user experience. We hope you’re ready to jump in and enjoy getting to know the power of Jetpack Compose! Jetpack Compose by Tutorials Introduction raywenderlich.com 20