Tash
06/07/2020, 7:27 PMOnBackPressedDispatcher
, but wondering if there's a better way...Adam Powell
06/07/2020, 7:29 PMTash
06/07/2020, 7:42 PMZach Klippenstein (he/him) [MOD]
06/07/2020, 7:47 PMonBackPressed
property in an onCommit
– I’ve seen a lot of internal Compose code update model properties like directly from the composable function, with no onCommit
wrapper. It looks like an optimization, but I would think onCommit
is actually more expensive than just setting a property. I’m guessing it has something to do with handling frames/threading correctly?Adam Powell
06/07/2020, 9:33 PMMutableState
properties of things that live beyond the current composition pass during composition, it's a bug. And yeah, we've got them here and there.remember {}
across compositionspavi2410
06/08/2020, 4:41 PMclass MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val backPressed = state { false }
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
backPressed.value = true
}
})
MaterialTheme {
Navigator(backPressed)
}
}
}
}
Adam Powell
06/08/2020, 5:43 PMpavi2410
06/08/2020, 5:46 PMAdam Powell
06/08/2020, 5:48 PMpavi2410
06/08/2020, 5:58 PMAdam Powell
06/08/2020, 6:03 PMVinay Gaba
06/09/2020, 4:25 AMAmbientBackPressedDispatcher
gets any value at all. Where is the value being implicitly being passed from given that we initialized it to null in the code example.Provider
that uses it and provides a value (like the current activity in this case)Wrapper.kt
.
.
.
LifecycleOwnerAmbient provides lifecycleOwner