Side Effects & Effect Handlers - Android Jetpack Compose - Part 10

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 43

  • @PhilippLackner
    @PhilippLackner  3 года назад +23

    I re-uploaded this video because the previous video had a messed up quality (only 480p). This is now in 4K again as usual

    • @otoS97
      @otoS97 3 года назад +7

      Now I don't understand side effects in 4K

  • @nilanjanmukhopadhyay8369
    @nilanjanmukhopadhyay8369 3 года назад +13

    In case you are wondering how LaunchedState does that,
    There are two cases where a LaunchedEffect can get canceled.
    1. The key of the LaunchedEffect changed
    2. The composable launched inside the "LaunchedEffect" isn't in UI the tree anymore after a recomposition
    Reason 2 applies in this case. When the `counter` reaches some value that is divisible by 5 the snackbar, inside the "LaunchedEffect" gets fired and added to the UI tree. On the next click, the value of the counter will be changed to something that is not divisible by 5. For this state change, a recomposition will immediately take place. But this time "counter" wouldn't satisfy the "if" condition. And the "snackbar" won't be added to the UI tree this time. Previously launched `LaunchedState" would notice that and cancel the "snackbar" anymore.
    To summarise,
    1. counter < 5, no snackbar in the UI tree
    2. counter == 5 -> recomposition happens -> snackbar is fired and added in the UI tree (LaunchedState would observe for any recomposition)
    3. counter == 6 -> recomposition happens -> snackbar isn't in the UI tree anymore because of the "if" condition -> LaunchedState observes this and cancels the previously launched snackbar

    • @st4849
      @st4849 3 года назад

      This I understand, thank you. I still don't get why he added key1=... It didn't make any difference, could have added key1=true even. No?

  • @calinpuiu2344
    @calinpuiu2344 2 года назад +1

    Thumb up! You are a mine of knowledge. For five days I struggle between your videos to find a manageable solution to validate a login form with a Retrofit call. I don't know if the LaunchedEffect presented in this video is the perfect solution, but seems to work for me. Thanks, and keep up the good work!

  • @ZaidZakir
    @ZaidZakir 3 года назад +3

    this video was a bit hard to understand haha, so had to rewatch it 3 times :D

  • @ConfusedNDazed
    @ConfusedNDazed 3 года назад +5

    Having come from 1 year of SwiftUI dev, I find this quite verbose and hard to follow. Everything up to this video was pretty easy to follow. Hopefully watching the Pokédex videos will make things clearer

  • @ashutoshsingh4905
    @ashutoshsingh4905 3 года назад +2

    I dont know why but when I watch your video It feels good and I learn a lot from this .
    Thanks for such good video.
    Love from INDIA

  • @ARIHANTJAIN27
    @ARIHANTJAIN27 3 года назад +1

    You should explain guideline and barrier in details for constraint layout using compose

  • @lewekandi784
    @lewekandi784 2 года назад

    I Philip thank you very much for programing the application data.

  • @Mahi-hn8tr
    @Mahi-hn8tr 8 месяцев назад

    Bro.. This is out of the playlist - jetpack compose. Please check

  • @theonlyarjun
    @theonlyarjun 3 года назад +1

    Which side effect can I use to detect the first time the compose composed, I just want to trigger some action for the first time and not every time the compose recomposes

  • @РоманТолстиков-н4е
    @РоманТолстиков-н4е 3 года назад

    Hi Philipp! Thank you for your teaching! Maybe you could answer my question? Do you know how to process the response from API in the html format?

  • @AIejandroide
    @AIejandroide 2 года назад

    10:32 I have a question, you set the scaffold.snackbarHostState as the key of the launchEffect, but when you click on the button you dont actually update that value, you just update the counter, the code won't even enter the if where you set the launchEffect. So why is the coroutine that shows the snackbar cancelled when you inmediately click the button again to change the counter if the counter is not the key ?

  • @AlgeriaHere
    @AlgeriaHere 2 года назад

    Hello Guys , I'm actually facing an issue which is related to this video topic , basically i want to fetch data from Rss Feed and i need to connect to a website to fetch the data , i know this is a side effect to execute network operation inside a composable , but what is the alternative for that , Thank you ?

  • @CybercoderNaj
    @CybercoderNaj 3 года назад +3

    I didn't get this.. how is the coroutine getting cancelled in LaunchedEffect? Can you explain again?

    • @PhilippLackner
      @PhilippLackner  3 года назад +3

      It gets canceled whenever the key you pass changes, so in this case whenever scaffold state changes

    • @mv2e19
      @mv2e19 3 года назад +1

      @@PhilippLackner And the scaffold state changes because the counter changes?

    • @nilanjanmukhopadhyay8369
      @nilanjanmukhopadhyay8369 3 года назад +1

      There are two cases where a LaunchedEffect can get canceled.
      1. The key of the LaunchedEffect changed
      2. The composable launched inside the "LaunchedEffect" isn't in UI the tree anymore after a recomposition
      Reason 2 applies in this case. When the `counter` reaches some value that is divisible by 5 the snackbar, inside the "LaunchedEffect" gets fired and added to the UI tree. On the next click, the value of the counter will be changed to something that is not divisible by 5. For this state change, a recomposition will immediately take place. But this time "counter" wouldn't satisfy the "if" condition. And the "snackbar" won't be added to the UI tree this time. Previously launched `LaunchedState" would notice that and cancel the "snackbar" anymore.
      To summarise,
      1. counter < 5, no snackbar in the UI tree
      2. counter == 5 -> recomposition happens -> snackbar is fired and added in the UI tree (LaunchedState would observe for any recomposition)
      3. counter == 6 -> recomposition happens -> snackbar isn't in the UI tree anymore because of the "if" condition -> LaunchedState observes this and cancels the previously launched snackbar

  • @shivamsethi3829
    @shivamsethi3829 3 года назад +2

    React use Effect android version, I love it

    • @thomaswaldorf2829
      @thomaswaldorf2829 3 года назад

      I was thinking the same thing :D useEffect with cleanup

  • @ambermalandkar1138
    @ambermalandkar1138 3 года назад +1

    man love your videos, thx!!!

  • @jimpauloovejera2599
    @jimpauloovejera2599 3 года назад +2

    I am still pretty confused how LaunchedEffect was able to cancel the snackbar

    • @jimpauloovejera2599
      @jimpauloovejera2599 3 года назад

      LaunchedEffect's scope is cancelled once it leaves the composition. For rememberCoroutineScope, the coroutine keeps running because the composable wasn't removed from the tree, hence, snackbar were just queued.

  • @abada-s
    @abada-s 3 года назад

    I hope you to show effects practically on emulator , to see some examples

  • @DennisEspiritu
    @DennisEspiritu 2 года назад +1

    Your previous Compose videos were easy to follow until this 😄

    • @PhilippLackner
      @PhilippLackner  2 года назад +2

      I know, that's why I recently made a new and better one about effect handlers: ruclips.net/video/gxWcfz3V2QE/видео.html

  • @federicocreti4699
    @federicocreti4699 2 года назад

    Of course I'm missing something but things are unclear. You say you need to do network calls (obviously) but why don't you use view models for this? Then you say if you do a network call inside a compose this call will be triggered everytime the it is recomposed, so I don't understand the effective solution given by SideEffect. You say it run the function just when the component is correctly recomposed, but what does that mean? Isn't the network call done over and over in the same way of not using SideEffect?

  • @CybercoderNaj
    @CybercoderNaj 3 года назад +2

    This video got me anxious about the side effects from the vaccine I just got. 😰😰

  • @md.rafsanbiswas5321
    @md.rafsanbiswas5321 3 года назад

    API is calling when get back to compose screen. Please leave a solution.

  • @amineayachi335
    @amineayachi335 3 года назад

    thanks again

  • @viveksingh9223
    @viveksingh9223 3 года назад +2

    Is this a re-upload or I am having dejavu.🤔🤔

    • @PhilippLackner
      @PhilippLackner  3 года назад +2

      no its a re-upload with fixed quality issues :D

    • @viveksingh9223
      @viveksingh9223 3 года назад

      @@PhilippLackner I got confused because I had finished watching the previous upload just five minutes ago.

  • @nickvillareallycool5228
    @nickvillareallycool5228 3 года назад

    This would have benefited from examples

  • @fahadalotaibi6340
    @fahadalotaibi6340 3 года назад

    thanks

  • @thomaswaldorf2829
    @thomaswaldorf2829 3 года назад

    Most of this feels like programming React with functional components.

  • @sergeyplotnikov5031
    @sergeyplotnikov5031 2 года назад

    difficult topic

  • @pradeepkumarreddykondreddy7048
    @pradeepkumarreddykondreddy7048 3 года назад +1

    Could not understand anything

  • @tommy9x
    @tommy9x 3 года назад

    From lesson 9 to 10 Not understand

  • @yonghunchoi8944
    @yonghunchoi8944 2 года назад

    겁나 어렵네 하 ㅠ

  • @richiekosher6218
    @richiekosher6218 3 года назад

    honestly why do you do half the video without really showing whats happening? kinda feels like being in uni instead of watching a hands-on tutorial on youtube

  • @chenchiaho
    @chenchiaho 3 года назад

    dont quite understand this