Marko Novakovic
06/24/2021, 4:39 PMIntent
, how do I do it in Compose?Zach Klippenstein (he/him) [MOD]
06/24/2021, 4:52 PMZach Klippenstein (he/him) [MOD]
06/24/2021, 4:54 PM@Composable fun YourScreen(onLaunchSms: () -> Unit) {
// …
Button(onClick = onLaunchSms) { … }
}
and so on, up your composable tree, until you get to the top. Or, until you get to something like a view model:
@Composable fun YourScreen() {
val viewModel by viewModels()
// …
Button(onClick = viewModel::launchSms) { … }
}
Marko Novakovic
06/24/2021, 5:16 PMIan Lake
06/24/2021, 6:04 PMLocalContext.current.startActivity
- the point is that calling that is essentially untestable, so you'd want to ensure that low level composables delegate that call up as much as possibleMarko Novakovic
06/24/2021, 8:22 PMTolriq
06/25/2021, 9:21 AMMarko Novakovic
06/25/2021, 10:02 AMAndroidViewModel
if you need something like that. this is not unit testable.
https://developer.android.com/reference/androidx/lifecycle/AndroidViewModel
am not sure Compose will get rid of Context
. you should be careful where you put these calls as Ian mentioned aboveTolriq
06/25/2021, 10:12 AMMarko Novakovic
06/25/2021, 11:10 AMTolriq
06/25/2021, 11:20 AMColton Idle
06/26/2021, 2:10 PMTolriq
06/26/2021, 5:24 PM