Timo Drick
04/07/2021, 9:47 AMTimo Drick
04/07/2021, 9:51 AMFilip Wiesner
04/07/2021, 9:53 AMstaticCompositionLocalOf
but there might be some better solution.
But I would really like to see the very special use case if you don't mind sharing.
Documentation of `staticCompositionLocalOf`:
Create a CompositionLocal key that can be provided using CompositionLocalProvider. Changing the value provided will cause the entire tree below CompositionLocalProvider to be recomposed, disabling skipping of composable calls.
A static CompositionLocal should be only be used when the value provided is highly unlikely to change.
Timo Drick
04/07/2021, 10:00 AMFilip Wiesner
04/07/2021, 10:02 AMTimo Drick
04/07/2021, 10:03 AMFilip Wiesner
04/07/2021, 10:04 AMTimo Drick
04/07/2021, 10:19 AMval providableLiveObj = staticCompositionLocalOf {
liveObj
}
Box() {
block(providableLiveObj.current, version)
}
block is: block: @Composable I.(Int) -> Unit
Filip Wiesner
04/07/2021, 10:22 AMProvider
first:
CompositionLocalProvider(providableLiveObj provides ...) {
block(providableLiveObj.current, version)
}
Filip Wiesner
04/07/2021, 10:23 AMTimo Drick
04/07/2021, 10:23 AMTimo Drick
04/07/2021, 10:24 AMTimo Drick
04/07/2021, 10:25 AMFilip Wiesner
04/07/2021, 10:25 AMTimo Drick
04/07/2021, 10:26 AMTimo Drick
04/07/2021, 10:27 AMTimo Drick
04/07/2021, 10:27 AMval providableLiveObj = staticCompositionLocalOf {
liveObj
}
CompositionLocalProvider(providableLiveObj provides liveObj) {
Box() {
block(providableLiveObj.current, version)
}
}
Timo Drick
04/07/2021, 10:27 AMFilip Wiesner
04/07/2021, 10:28 AMTimo Drick
04/07/2021, 10:28 AMAlbert Chang
04/07/2021, 10:58 AMcurrentRecomposeScope.invalidate()
?Timo Drick
04/07/2021, 11:01 AMTimo Drick
04/07/2021, 11:02 AMTimo Drick
04/07/2021, 11:21 AMFilip Wiesner
04/07/2021, 11:22 AMGive me maybe one day
I knew you'll regret this :D
Timo Drick
04/07/2021, 11:25 AMButton(onClick = { text.value = "Button pressed 1" }) {
Text("Press button1")
}
So when i change the text of Text it gets updated. But when i change the text inside the onClick lambda the old lamda is executed again.Timo Drick
04/07/2021, 11:26 AMTimo Drick
04/07/2021, 11:28 AMTimo Drick
04/07/2021, 11:31 AMkey(liveObj) {
liveObj?.let { block(it) }
}
Also does not flicker any more. But of course the remembered variables are gone.Sean McQuillan [G]
04/07/2021, 5:47 PMSean McQuillan [G]
04/07/2021, 5:49 PMTimo Drick
04/07/2021, 5:50 PMSean McQuillan [G]
04/07/2021, 5:50 PMSean McQuillan [G]
04/07/2021, 5:51 PMTimo Drick
04/07/2021, 5:52 PMSean McQuillan [G]
04/07/2021, 5:53 PMAdam Powell
04/07/2021, 6:26 PMRecomposer.Companion.saveStateAndDisposeForHotReload()/loadStateAndComposeForHotReload()
- the latter accepts the token returned by the former but today it's just a placeholderAdam Powell
04/07/2021, 6:27 PMTimo Drick
04/07/2021, 6:44 PMval token = remember(liveObj) {
saveStateAndDisposeForHotReload()
}
loadStateAndComposeForHotReload(token)
libeObj.composable()
Leland Richardson [G]
04/07/2021, 7:00 PMTimo Drick
04/07/2021, 7:03 PMLeland Richardson [G]
04/07/2021, 7:05 PMTimo Drick
04/07/2021, 7:08 PMText("Test1")
than change the code to: Text("Test2")
it does not change the displayed text without using at least the staticCompositionLocalOf approachTimo Drick
04/07/2021, 7:09 PMTimo Drick
04/07/2021, 7:14 PMLeland Richardson [G]
04/07/2021, 7:21 PMTimo Drick
04/07/2021, 7:22 PMLeland Richardson [G]
04/07/2021, 7:22 PMTimo Drick
04/07/2021, 7:55 PM/*
// Without any enforced recursive invalidation it does not work at all :-(
liveObj?.let { block(it) }
*/
// This method of hot reload swapping is working but lambda functions are not swapped reliable
/*
val LocalLiveObj = staticCompositionLocalOf {
liveObj
}
CompositionLocalProvider(LocalLiveObj provides liveObj) {
LocalLiveObj.current?.let { block(it) }
}
*/
// This method of hot reload swapping is working well as far as i tested but the remembered variables get lost.
key(liveObj) {
liveObj?.let { block(it) }
}
/*
//TODO figure out how this can be used and how to call internal functions
val token = remember(liveObj) {
saveStateAndDisposeForHotReload()
}
loadStateAndComposeForHotReload(token)
composeableBlock(libeObj)
*/
Timo Drick
04/07/2021, 7:56 PMTimo Drick
04/07/2021, 8:04 PMTimo Drick
04/07/2021, 8:35 PMLeland Richardson [G]
04/07/2021, 9:29 PMLeland Richardson [G]
04/07/2021, 9:30 PMkey
like youโre doing in the linked file. but as mentioned above, this will lose all state beneath that key callTimo Drick
04/07/2021, 9:44 PM