Advanced state and side effects in Jetpack Compose

Ғылым және технология

In this workshop you will learn advanced concepts related to State and Side Effects APIs in Jetpack Compose. We'll see how to create a state holder for stateful composables whose logic isn't trivial and how to create coroutines and call suspend functions from Compose code. We'll learn what are side effects, and different APIs, like LaunchedEffect and rememberUpdatedState, to trigger them and accomplish different use cases.
Resources:
State in Jetpack Compose codelab → goo.gle/compose-state-codelab
Advanced State and Side Effects in Jetpack Compose codelab → goo.gle/3Gdhyn5
Side-effects in Compose → goo.gle/3KN54oY
UI state production pipeline → goo.gle/architecture-uistate-...
Architecting your Compose UI → goo.gle/3UonhMN
Consuming flows safely in Jetpack Compose → goo.gle/3GwleAS
Other supported types of state → goo.gle/compose-supported-types
Compose and other libraries → goo.gle/3ZUToor
Save UI state in Compose → goo.gle/40Uw2kj
Lifecycle of composable functions → goo.gle/3KsEPTB
Thinking in Compose → goo.gle/3o2Ie40
Splash screen API → goo.gle/3KKXZ8C
Maps Compose → goo.gle/3GUfGAn
When should I use derivedStateOf? → goo.gle/3GwY11i
Now in Android → goo.gle/nia
Speakers: Alejandra Stamato, Manuel Vicente Vivo
Watch more:
Watch all Android and Play Sessions → goo.gle/IO23_android_play
Watch all the workshops from Google I/O 2023 → goo.gle/IO23_workshops
Watch more Mobile Sessions → goo.gle/IO23_mobile
All Google I/O 2023 Sessions → goo.gle/IO23_all
Subscribe to Android Developers → goo.gle/AndroidDevs
#GoogleIO#Featured #AndroidDevelopers #JetpackCompose

Пікірлер: 34

  • @AndroidDevelopers
    @AndroidDevelopers Жыл бұрын

    To learn more about what's new in Android, check out the Android Keynote at #GoogleIO → goo.gle/IO23_androidkey_pin

  • @Himachaliyan

    @Himachaliyan

    8 ай бұрын

    Hi @AndroidDevelopers , We are using compose for our application , we are group of 6 engineers working on the app, from all around the world, Our app is having very laggy behavior and need your help if you can so that we can follow the best practices, we have developed very big app on the compose and as we can see the laggy behavior, we are scratching our head, We have used good compose practice everything is in small set of composables, we using states, we are using coroutines, Can you please help us, is there any way we can get over a call, for some help

  • @AmitJayant
    @AmitJayant Жыл бұрын

    Manuel: I'm Manuel - same team, same title Manuel making use of state very well 😄

  • @tch.777
    @tch.777 Жыл бұрын

    Thank you very much. That video was so important😊!! The new thing for me that I was searching for was the Saver for the rememberSaveable to survive configuration changes with my own non primitive type. I built a very buteful and customized calendar and needed that. Thank you!!!❤

  • @technophile_
    @technophile_ Жыл бұрын

    This talk, hands down, had the best flow ever! Great job Stamato and Manuel!! 👏🏻👏🏻❤

  • @leandroperalta4476
    @leandroperalta4476 Жыл бұрын

    Gracias gente! Me llevo algunos conceptos nuevos después de ver este video. Muy bien por mencionar España y Argentina durante el tutorial. 😄Existe algún otro video o CodeLab que explique como escribir tests para este tipo de implementación?

  • @chandra_83
    @chandra_83 Жыл бұрын

    Great video. Good understanding of producestate,launchedeffect,coroutinescope

  • @dmorales8027
    @dmorales8027 Жыл бұрын

    Muchas gracias por la informacion. Han dado el panorama completo de los efectos secundarios y estados avanzados, vi el codelab y me mareaba, viendo el video, fue como decimos aca en Peru, "directo a la vena", mucho mas didactico. Ya le toca a cad auno profundizar mas y ponerlos en practica. Muchas gracias!!!!

  • @user-um4tv2yk9i
    @user-um4tv2yk9i7 ай бұрын

    Great video!

  • @gajendrasinghrathore5994
    @gajendrasinghrathore59943 ай бұрын

    Thanks for sharing, it was helpful.

  • @McMouse88
    @McMouse883 ай бұрын

    "like so" sounds so cute )) Alejandra and Manuel thanks a lot for your work )

  • @user-ru8gs1fi8z
    @user-ru8gs1fi8z7 ай бұрын

    Thank you very much.

  • @user-po2lc9df8w
    @user-po2lc9df8w Жыл бұрын

    Great video! In the section about saving the input state you implemented a custom saver in the state object and use that in rememberSaveable. One way that I have approached this in the past is to make the state object parcelable using the kotlinx parcelize annotation. From that point I just have the initialization of this object wrapped in rememberSaveable and it is restored as expected through process death configuration changes. What are the benefits of creating a custom saver versus this other approach? Are they both valid or is the parcelable approach I described not as beneifical?

  • @AlejandraStamato

    @AlejandraStamato

    Жыл бұрын

    For sure! That's actually the simplest way as per developer.android.com/jetpack/compose/state#ways-to-store In the video we show an alternative using listSaver if you can't add the plugin/annotate the class for any reason.

  • @ellasaro
    @ellasaro Жыл бұрын

    Hi! There is something that I can't quite get my head around. In step six, when talking about LaunchedEffect vs rememberCoroutineScope, it reads: "LaunchedEffect guarantees that the side-effect will be executed when the call to that composable makes it into the Composition. If you use rememberCoroutineScope and scope.launch in the body of the LandingScreen, the coroutine will be executed every time LandingScreen is called by Compose regardless of whether that call makes it into the Composition or not." - What would be the case for a Composable to be called but not "making it into the Composition"? Can a Composable function be called but not end up in the UI? How so? Thanks!

  • @carlosdiestro6924
    @carlosdiestro6924 Жыл бұрын

    Awesome guys! That was really helpful! I have a question though regarding the section for the InputText and its State: What are the differences between creating and declaring the state for the composable the way you do in the video and providing the state through the viewmodel? Being more specific: - Having a screen state in the viewmodel (as a data class and then wrapped with StateFlow) composed of the input text and hint - Collecting that state in the screen with the collectAsStateWithLifecycle API and passing the corresponding arguments to the InputText composable - Using an event call to the viewmodel to update the input text (this will call _state.update and make a copy of the screen state updating the value for input text) Is it a better practice to do it the way you show in the video when the information of that composable isn't dependable on the domain/data layer? However, this option delegates more "thinking" work to the UI rather than keeping it "dumb". What are your views about this? Thanks in advance and keep up the good work!

  • @AlejandraStamato

    @AlejandraStamato

    Жыл бұрын

    Hoisting to the VM is fine, if you need to apply business logic to the TextField state for sure. But be careful as currently we do not recommend using a reactive stream (such as StateFlow) to represent the textfield. consider using mutable state in the viewmodel and avoid async validations. The full explanation is described in this blog medium.com/androiddevelopers/effective-state-management-for-textfield-in-compose-d6e5b070fbe5

  • @gorudonu
    @gorudonuАй бұрын

    I wonder how people who's written this code didn't look at it and said "this is way too over engineered, we should step back and think it over".

  • @hansonhuang6434
    @hansonhuang64343 ай бұрын

    I'm confused about this bit, in which scenario that 'onTimeout' would be changed? feel like in practice, this lambda function would barely be changed. so didn't get the point of using "val currentOnTimeout by rememberUpdatedState(onTimeout)", which makes it look like that onTimeout would be changed quite often. Just wondering the scenarios? Thanks.

  • @nzdas
    @nzdas7 ай бұрын

    In the ToDestinationUserInput composable I'm wondering why you chose to trigger a side effect to call the onToDestinationChanged lambda. Is there a reason why you can't simply use an if statement that invokes the lambda when the text is not the hint?

  • @ingenieroluisfer
    @ingenieroluisfer5 ай бұрын

    👋🏼🇨🇴🧔🏻👍🏻🤝🏻 Estupenda información

  • @GTEK0122
    @GTEK01222 ай бұрын

    personal memo 4:03 viewModel as single source of truth 9:40 side-effect

  • @frankensteingodzilla2444
    @frankensteingodzilla2444Ай бұрын

    Hi, 9:01, why composable functions run multiple times, please?

  • @frank4pickerson
    @frank4pickerson Жыл бұрын

    Not very clear why derived state is used. Does the composable function recomposes if there is a calculation that checks if X>0?

  • @dleonardo3238
    @dleonardo32387 ай бұрын

    Was night light activated or what?

  • @cetateanturmentat1200
    @cetateanturmentat12006 ай бұрын

    I would really love to see how it compares with a different approach and why we should really use these. Crane app si a bad example, too big, too much noise. Less code but more examples would work better. I am still not very sure why would I use most of these. 1. "Consuming a Flow safely..." what's the unsafe way? Why it is unsafe? What "safe" actually means in this context? 2. Side effects seem more like an after thought than something organic. I try to avoid them as much as I can but maybe I'm wrong. Nevertheless this didn't quite help clarifying it. 3. The language is very dogmatic: "better approach" but why? "safer" but why? Not very scientific. Sounds like an advertisement to me. Works for IO but if you really try learn things... go figure.

  • @shreekarki1771
    @shreekarki1771Ай бұрын

    Disposable Effect??????

  • @JamesGoodwin86
    @JamesGoodwin863 ай бұрын

    Too small for display on a mobile device

  • @ismaelsanchez3492
    @ismaelsanchez349210 ай бұрын

    Very confusing as usual, Google's technologies looks like they are made on a contest of how to make things much more complex than they should. I don't need to show off how well I manage with complex technologies, I just need to be productive and make complex things simple, not otherwise. The probability of developers making mistakes are enormous using this APIs, unacceptable in my opinion.

  • @simbelarium

    @simbelarium

    10 ай бұрын

    Completely agree with you on this, as time passes, Google makes thing more and more complex, and it seems that they simply wont stop.

  • @kirwakelvinkering3122

    @kirwakelvinkering3122

    6 ай бұрын

    Ooooh no , just do more on jetpack compose first , this was really helpful😢

  • @SumriseHD

    @SumriseHD

    6 ай бұрын

    ​@@kirwakelvinkering3122I agree. Once you get started with this stuff you see how it's actually pretty helpful. And yes, I agree with OP that it seems like a lot of it is pretty useless, and some of it definitely is, but a lot of other stuff definitely makes sense after a while.

  • @ShivamVermaokdone

    @ShivamVermaokdone

    3 ай бұрын

    okay then they tried to give you some value which can differentiate you from others who know only easy stuff!!!!!

  • @techocia

    @techocia

    Ай бұрын

    Bro just tap on anything that says “Advanced” a bit later 😊

Келесі