Colton Idle
01/03/2024, 12:15 PMcollectAsState
extension function on a flow... should I be remembering { }
the initialValue?
i.e. I have something like this
myflow.collectAsState(initial = runBlocking { a value I NEED to calculate for initial state})
I understand (and am okay with the delay in my main thread, but I want to make sure that the call to initial will only be called... initially 😅Filip Wiesner
01/03/2024, 12:25 PMremembering { }
the initialValue?
No, it's just the initial state of mutable state. If you look into implementation, the value is used like this:
val result = remember { mutableStateOf(initialValue) }
Filip Wiesner
01/03/2024, 12:25 PMStateFlow
instead of Flow
if possibleColton Idle
01/03/2024, 12:25 PMinital
but... I'm using a webview and the value being calculated is the base url. so if i don't wait, then i basically get two loads of the webview, because it'll try to load an actual default like empty string, and then it'll go ahead and reload with the new url it pulls from shared prefs/calculates.
moving to this route has removed a flash in the webview so im going to move forward in this routeColton Idle
01/03/2024, 12:26 PMFilip Wiesner
01/03/2024, 12:28 PMif (baseUrl != null) WebView(baseUrl)
else ProgressBar()
Filip Wiesner
01/03/2024, 12:33 PMColton Idle
01/03/2024, 12:35 PMFilip Wiesner
01/03/2024, 12:37 PMif (baseUrl != null) WebView(baseUrl)
if you don't want the progress bar 😄 But fair enough. Just know what you are doing and hope that the underlying computation won't change to something more heavy in the future. runBlocking
is a dangerous toolsaket
01/03/2024, 6:40 PMI have something like thismyflow.collectAsState(initial = runBlocking { a value I NEED to calculate for initial state})
If your code actually looks like this then you'll need to remember the initial value
saket
01/03/2024, 6:41 PMcollectAsState
functionsaket
01/03/2024, 6:43 PMinitialValue
param was also a lambdaFilip Wiesner
01/03/2024, 8:21 PM