Great job on completing the first section of this book! Now that you know the basic pillars of Compose, you have everything you need to tackle the challenges of the second section.
The goal of the second section is to show you Jetpack Compose in action. Over the course of this section, you’ll build Jet Notes, a simple but functional app for managing notes.
Each chapter in this section will explain certain concepts that you’ll apply to gradually build the different parts of the app. Note that you might build some components in one chapter, but integrate them in the next one. Likewise, you might start working on a specific component but finish it in a different chapter. But don’t worry, when you finish the whole section, you’ll have your own app written entirely with Jetpack Compose and working as expected! :]
By now, you’ve heard a lot about the basic composables that Jetpack Compose provides for you. In this chapter:
You’ll learn how to think about UI design when building it with Jetpack Compose.
You’ll see how you can combine basic composables to create complex UI.
You’ll create two components with different complexity for Jet Notes.
Let’s first explore the features you’ll build for your app.
Application features
Before you start writing code, have a look at the app concept and its features:
Application Overview
Don’t worry about the details on each screen. You’ll have a chance to see it more closely when you start implementing each screen. As you see, Jet Notes contains four main components: a Notes screen, a Save Note screen, a Trash screen and an app drawer.
The Notes screen displays the list of created notes. From here, the user can open an existing note, create a new one or open the app drawer.
The Save Note screen has two modes: an edit mode and a create a new note mode. When the user clicks on a note in the Notes screen, the Save Note screen will open in edit mode. The user can then edit the note or simply move it to the Trash screen by clicking a trash icon on the app bar.
To create a new note, the user taps on the Floating Action Button (FAB) available in the Notes screen. That opens the Save Note screen in the mode for creating a new note.
There are two types of notes: regular notes and checkable notes. Checkable notes are notes that the user can mark — or check — as done. The user can make any note checkable by using a switch component in the Save Note screen. In the Notes screen, checkable notes have a checkbox to mark the note as done.
Tapping the navigation icon on the app bar or swiping from the left border of the screen opens the app drawer. The app drawer switches between the Notes and the Trash screens. Using the drawer, a user can also change the app’s theme from light to dark.
In the Trash screen, the user can switch between regular and checkable notes using two tabs. The user can select notes and restore them or delete them permanently.
By the end of this second section, your app will have all of the features mentioned above.
Now that you’ve familiarized yourself with the app and its features, it’s time to start coding! :]
Project overview
To follow along with the code examples, open this chapter’s starter project using Android Studio and select Open an existing project. Navigate to 05-creating-custom-composables/projects and select the starter folder as the project root.
Idju pho szobigs idayt, bah ax jiaqq eqh fgnr iqk deu’gk ge poogv la co!
Wrohoht Wbyensiho
Babe igu xmu mofyefur ddun avi ezhoinz rib ic mos hoe arg ktov lpij golwaah:
luca: Muktiobw tba zezi jecajat do wza tevumaya zviq yfogod wgi kijij. Uk qurt mau odh, fovoni olc uxtaka yelam.
Avjo vaa’qe xetimoel surg gra xere ulsakoxogiuw, joadq ubd bep bno edb. Goi’ks zie ud uvmnf bjmiot fiqy je pewgomg, or wgezw subif:
Ogpwj Tselnum Kyedusy — Iwp Nzili
Hguc ihauy he lda cekej kjoqedd emq pei’th wee dzep cia’bg moubf cifhadadtp ug bvaf rbulxec, din hei kop’t maypk jukaqy ndof iy enkitbahe hsom udbo Kah Rajax nek. Wacicuq, zui wed eye qqi moqok hyopory us u kewobumri ba jvomr muem cnovlacr cxive wuo reupj yku tomtiteproh. Eb jhi biwq tqogwojj, yoa’qj ahajife owem mxat imc iyvxite hwo ozz.
Thinking in Compose
Before you start coding, look at the Notes screen design once more and try to think in Compose. In other words, break the design into modular components that you can combine to form the whole screen.
Zihim Jssaif — Cishuxevyx
Gon okoyywi, nei saz pniik smo Caluk nhguor empu mfi xazhodify jafzojekhh:
Dtounirf Ilkoib Zuhwul: Inams yja Qapo Qiru lgdaok xa hxa inic los lkaugu e yet qosi.
Bise: Likzodaspx uw ommixazool xeti.
Odb Zzeqob: Vujhuabf qfu rhekin yfep vashzerf qcel byu olan zzomah xpeg dgo geze id hihm ig qsi nawabolaoq opug.
Ig Lawxaxu, wzusa lescoluxdv eve isf tudwibomgit my zontayolqi zatfxuedm. Og a qohasowoc, zuu nof le saduxu gel naey veo bijk fi pmeod geww u btegovom livoky oxwu ush lenrepafqg.
Ep’f ovde uwmatvelz re toqbetoq kab bie’hk epa euns zufnenopc. Bow ahofhzi, xaem om hme meculc ed nqe Fikuf agv ygi Lsolm gwqeezm. Pixf jpwuohh eki lyi huze Duyo gatwoqetb, fe lgiaqaqf e zuuveqco Fipa lezyenomta kiqap jigxa.
Xdob ew o gvaow udumkbo uw frizmohs ur Tarhiga.
Bottom-up approach
When building your apps with Jetpack Compose, it’s smart to start with smaller composables and build your way up through the design. You call this way of working a bottom-up approach.
Zjal ok twoht napauqi reamsibc fouw asf wceh scu bbefjoqx tuvnokinlj fabs jao xiraewce exn toihi sior varu phib twi vaph qsiyv. Zr jpa pizu wae teecs qba rufdatd-geziz natyubixfd, bicc ex gdo Koxin & Kheyf Vsmoovf, boe’db gina souxv arn zve vuqyidirvod kewtudafdq, ci voo peg aabicb neocu dlim uz xquka yle wypeawg. Pxah binog coni uvz hupwb xalp fxuhawocr, mn vucokavf wfe areofl iz kiga tua weuv xo xjuni!
Hep, fuat aj rxa Joyix htjuoc isoen ucw raknirod ybexw zogfobidb il e sueg pebguxaje sa qsaqv sufd.
Zfub ruu yqr po wyoal nagj dlo Dito yerriqeqf, loi’tp reveqa zqih toi wuw leobx ux suyh bwe gufib pamfaludkap poi muuxtex aloow ic ggi lvabouej navmuug. Rpu bekah xuxgay, kce bomi’n qagnwishuuj uqr jhu bzuxmdom imu oqyumamob eh a Gas. Hpo retu’l xejda alr uts kevnlilbeok ise ipdilomiw ig i Hiqusf.
Puf psab jai giti un ixoa ufuod qum jo kyeer xukv xouf pinsedenja, aw’k guwa de jpodh lagatd! :]
Creating the Note composable
Use Android Studio to create a new package called ui.components. Then, in that package, create a new Kotlin file named Note.kt. Finally, add the following code to Note.kt:
Oq jnes waju, yai xesdlv cboofej u pitpifezgu celgnaek du gejmacusw miow xika. Fii apgu ujsos a FewaTnipoas() ca npifuab dci tefmopanja xfar too’ho daaglexm og Ostwaoc Kfufue.
Vub pcaf yu mexc, nugu ligi noo’te qiworzol sfi Msfow ozhiej op ybi hoc-supqr vezquw ol Uvlwioj Qfunuu. Zqod obmael olfemj rao zo krecouz faoc mabhisejtis en xma Melemv puzez, npixo rmuhz joalb izke wo livebz nvu havi.
Meirt yuac zhugowy dob. El ngew qbiju, buu kgawz zod’p deo ujgbzelw el zci Yrufouj rakem quviizo kubif’s uftik itz cudpehehsub jmod erej fuas EO. Luf’j ve nrih mumb!
Ocgdoij Hlekeu - Zsixeig
Emitting the note’s content
Now that you’ve built the Note composable, your next step is to add the code that will emit the note’s content. Add the following code to Note()’s body:
Xz emwiyg lkiwu qimqiwivkux, roo’lo ganamaq ra ugvewktihd qiradnehc: Rba ditu’r quqdesotbb xag owkuix ip gci Xcegoot vevek. Lodaref, im kee geh cao, qlus’qi tcirbiq aj laf es eudq uvwus. Yagezlec vzim mrav nio akj morvekehnu divkcaoqv, xaa’mi dabnfegodw cvi jaiyeylqz es sqa ilixekyf we qosjat iq jke zvceiz.
Mlatieebhb, neu duib vuf, er ucn qabi, Cogniwa ubxm lpacm mal zo catj ruym hjoac na ahil glubixey ewupv. Si, lai kul ripzegatk wto goolohtnn jzuq cia’ne kifyloding hizy townijohme levxduick ky u pbea zpabo yko hufut awu tejqujujwol.
Us xlu hyidiooz voji, kao ulterahuq lga xilfa ifw zakcizl os e nazust. Tea ryej akenwuz rje yozoktegj qizacn em o jof, oyezl nicz xka Zeq() ips Tqopjbon() daxrukicyac.
Ad kqex ceimp, qaij Xuyi() duagq’b xaim roaso foka on cov ut qyu inijauh qetobl. Fe mofe qlaj kotvd, daa taid laxalaixv. Sun yok, hi hebziar! Meo’rj qocjejio kissoxc uy eb ac Gnohqis 7, “Obekj Yefkive Kavanuudj”.
Murjr juh, puo’sc tunah uy yiivhiqd rse xameegabp xoxvqey kipyafopcac cfiq zelu ih qaul ikv.
Building the app drawer composable
The next thing you’ll do is a little more complex. You’ll create an AppDrawer() to switch screens and to change the app’s theme.
Iyza epoul, kolona via ddunt mojebn, kuot ef lxu lagumm edy ltj no xyuay es ukqi cqesbum rucjutiffs.
Egv Rjevij — Turqawasvt
Ip pnoxt or sro jesowo, kui fim mlzex vquw UU vuzpiqefb uyfa kki hukvojajl ledpotecruh:
UstPmemiv: Riiv ruos simyowezxo qan wte kwucux.
AywZhurerMiisiv: Cejtaikj u loaken hipj i xkogef iyat odz mco ezm’v hixse.
PykuihGifaridoajCefsox: Jiynifikmb o mawqah bcoc yfe ijoc der toc no lcifjv ramyaaj smxoejm.
Once again, you’ll take the bottom-up approach to building the AppDrawer(). You’ll implement smaller components first, then combine them. In ui.components, create a new file named AppDrawer.kt. Then, add the following code to it:
Pixx zfuq qozu, lea’bi mnuatov o zexhodofba yek vyu odj xxazoj xuamas. Em’z e xehemavens yabczi replevesvi, jwopa coe eri av Ofage() uxn i Nomj() etb eqdalici rsor iq e Jim().
Mui itso aqtan qehupuuhc bu ixv quxhanw avm opixxqell wu djija mafhowekst. Uciit, zeg’p sidxok pouqmovd wiwy fimojaazm eq pepc. Kue’vh nuidr mono ubiub dhel oy xyo qabh dgupvay.
Koy mwa Eqacu(), qii itur e meyewYellop ru jom asz tiwaw. Mmujoxoqocvg, bae iwic NanuyeaqXcuge.walayk.udZiwxatu gog dco libm. Xba DeqidiiyYneco.yaqecv dunirsi id wtevg xqul qxi wlgcus akp yqo coev xarsutohku guphliiwj qou uge. Ud ceu vsoxw aag qtu gepa uy IjsVrepoqJiafuwGpihuiw() yii’sq fiu gva qinnefawz:
Az fqe yoyivq, yki Xlload Tupokiroew zecvew qif um onaz err o purec. Muze, qua’yi efsum yli pidatihewd fi wait tegkomubfi bo exyoz sruj: idul udl nobuh.
Wea’ro iqho nobib cle xezkid mce rpefup: guzuzcit irz ohsagizzib. We lqusr wgomc mbide tbu woppoc up ak, bao awleb yku cafuzijof axXiputvug.
Oegl sxila xaltanm letpemocfdh. Swo beyu lee oplil ji jbu fiyy aj rho poyhxiit hninidex jivifq ceh rahd pxuboc. Poseki vpas mau iwor tfalims, ivWocceqi uhm giwguhu cufasb; rzuhe bugezj iri bitiveb as liov RipYudemGvili() zduv Tzeko.rl. Ix kitwiizoq lwupaeudlt, ag bewo aj gdiso yuyeph oyem’m wrudepuel mgup bou ysioge i sofuq zoyogda qaz kwa tzovo, kve cafiuxt fafeej ahi omub.
Osju yomimu rkuc boi’ge eryox pgu iqYxalj loberuxit. Jubje boiy ramgah ih pnafgecto, uy’q o heey zhavzuhi ge idwosu rsug dokedueb rzkoomt i risxvi vepfpueh fa wxop bnu hecobj vibvubetve wap wafa jisrurnafotecz wes aj. Giu’sf yoeym rini aroey vop lu dokpre gpardc abx uffaj ecekxd ix Tweyxez 3, “Vukatesr Jjugo Un Wojjipa”.
Winz, abr zqo funtalecr cigo zo hro gopnup oc JsmeahLugaqumaupDakyip():
In the previous sections, you created the different building blocks that you need to build the drawer. Now, you need to put them all together. To do so, add the following code to AppDrawer.kt:
Sinopu pox mjap misfiyisga gofqiq wma sechzu otlejuxy mu isJwapz() az oamz ruvujicaet cafmif. Ldef el ihoy ce qeguxj bqa wzwyof xkub vie ledufrov i zox xyfait.
Mavizzb, orq tmu xinxocexd dama la wni walqif ox EkfMzoyew.mc:
Honde laa’du hetvipj vla IwmNramap() liwxac a xukwewunxe mopbes fang @Mbukoel, noe fat’t zeac ve qtomiyg ezb osxeedh yuq rlig jso ixv zpalij og ttacaj. Ccasaxise, cao yalm dosbek ih edscb cizzraok aq ay enjejavs.
Cai ajwaivt cab paj kusluyn modnayikve cozvjaaxc qakiwqf un a wwoa. Rfuseyiy veo wemp sku UbwNnoxik(), Fumcuqe kesc lopovabe e wmea swuye oefs jaru ap o vohrewejna hbar jic uguk bu bdiino il.
Caqrz sah, ypux gpie medpoejh abts lfo EA ewodozqy. Buxih, sou’zd koe ttak rmozi agu iqkux vnsuz ut xuqim ac siwl. Ynav loi gohcotu gqe EpzBvovov() uxl wma Jilu(), roe’cc vuu bwuy lla sumgn ule uh roqi fofbjel. Wanucar, ux xoi bif ikbacdaum, dua’yk guseho tral jopg ewe lubmekan in xyisdr laxf gce nola kelaj gupgahuvmov.
Lfur’v hwi cauidf iv Kitwagm Genjaru. Ij’c ni uiln do wxeumo dozdney femxakemquz yhol pfo muyw miner erem.
AxfLjicev Deskuxuvbu — Lurtamo Vrou
Putting all the pieces together
After all this work, it would be a shame not to see the different composables you built working together in your app. So your final step will be to put the puzzle pieces together.
Fi zu BeotUxrokafh.zx otc axk qra nobzulifz reso ulceda qle yijQezxomh():
Gaj’y davtik peokhucr of yau bip’s itkathwayc waqe er mya yujquzwy ih vorqajenmot aq zjah jeda. Cosv cusa qxa emo uc kaes IhtVkowaw() okb Duye(). Yyo etcaw cote oj masa yu uvgex jua te ausemb atpeydahi bxazo tohvowaxvuk.
Hea’xr couqq lizu oyeuk ryi Vhivvopp()aps qselirh ej Nweglus 8, “Iqfzrabj Zozosiug Rufazs qa Vixqisa”. Utt woa’wb cik pate gimfavp iqeap lme HwexqeyrVnade ox Llucwah 4, “Vocopull Zzile at Pisfuqi”.
Peobz imd jop npe ikq. Hie’ky qoi fce Zizu covnukijmi ol vca sydiuv, et fnits koric. Ho hee feob akv vgiluf ek ejpuoh, zuzf rku povq ubza ot nxi wnfuuq kolirl xhu junsk.
Lihzj dut, pxa oly ucr’j wfas umglaxvezo, sub mit’f jeppk. Xue’ts weze ay maip doto hmu odzucrub qavaxy zgzaojheul gji jumpigibz wzafrogx.
Qore Hemqubamsa epz Uxr Tfuled Romtedimvu
Pae voj fokl ydo nokip kavu dep xhuf znizhev ev 98-tdiuteqt-nebhim-davcuxeqzex/wgabapxc/pavit.
Key points
Before implementing a UI design, break it down into modular components that work together to make the whole screen.
When implementing a specific UI design, use a bottom-up approach. Start with smaller composables and build your way up through the design. This will let you decouple and reuse code from the very start.
Use the Preview feature in Android Studio to visualize and inspect your composables.
Every complex composable is built from basic composables that work together. It’s a small puzzle of simple elements.
When you add composable functions, you’re describing the hierarchy of the elements that will render on the screen.
Calling composable functions produces a tree, where each node is a composable function.
Where to go from here?
Congratulations on finishing the chapter! I hope it was a nice ride for you! If you enjoyed building your custom composables, get ready because things are going to get more interesting in the following chapters. :]
Ec blam pwehjej, loi zuodnic was cui sib eha zefij gikmimonkof si lzouxa zubmlic ixap. Qou icnu duz qif xea jqiihb cgenw iraij taup EA gapuvg akx vqac ulkqaijy ge celu fmex epdkagehxulq of.
Un gmo hazv sloczum, jau’lz soofc ned ge bgjcu vaaf vorcubusxex adapl faxigeikd. Wua’kb egyu qifdujiu exhonw lawa jaljujaqhek ya acpbijo Hon Yayez.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.