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
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!
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
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
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 ?
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 ?
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
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.
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?
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
I re-uploaded this video because the previous video had a messed up quality (only 480p). This is now in 4K again as usual
Now I don't understand side effects in 4K
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
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?
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!
this video was a bit hard to understand haha, so had to rewatch it 3 times :D
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
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
You should explain guideline and barrier in details for constraint layout using compose
I Philip thank you very much for programing the application data.
Bro.. This is out of the playlist - jetpack compose. Please check
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
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?
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 ?
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 ?
I didn't get this.. how is the coroutine getting cancelled in LaunchedEffect? Can you explain again?
It gets canceled whenever the key you pass changes, so in this case whenever scaffold state changes
@@PhilippLackner And the scaffold state changes because the counter changes?
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
React use Effect android version, I love it
I was thinking the same thing :D useEffect with cleanup
man love your videos, thx!!!
I am still pretty confused how LaunchedEffect was able to cancel the snackbar
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.
I hope you to show effects practically on emulator , to see some examples
Your previous Compose videos were easy to follow until this 😄
I know, that's why I recently made a new and better one about effect handlers: ruclips.net/video/gxWcfz3V2QE/видео.html
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?
This video got me anxious about the side effects from the vaccine I just got. 😰😰
API is calling when get back to compose screen. Please leave a solution.
thanks again
Is this a re-upload or I am having dejavu.🤔🤔
no its a re-upload with fixed quality issues :D
@@PhilippLackner I got confused because I had finished watching the previous upload just five minutes ago.
This would have benefited from examples
thanks
Most of this feels like programming React with functional components.
difficult topic
Could not understand anything
From lesson 9 to 10 Not understand
겁나 어렵네 하 ㅠ
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
dont quite understand this