Skip to content

Instantly share code, notes, and snippets.

@aasierra
Created July 21, 2021 13:57
Show Gist options
  • Save aasierra/1d34c3001b965b223802627b2feec46e to your computer and use it in GitHub Desktop.
Save aasierra/1d34c3001b965b223802627b2feec46e to your computer and use it in GitHub Desktop.
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Create view model that normally would be created in an injection system such as
// by viewModel, or Dagger, or Hilt.
// For our purposes of discussion we are just instantiating here as it does not matter
// where our BusinessLogicCenter (ViewModel) comes from.
val viewModel = ProductInfoBusinessLogicCenterViewModel()
setContent {
ProductInformation(viewModel.productInfo.observeAsState())
}
}
}
@Composable
fun ProductInformation(displayObject: State<ProductInfoDisplay?>) {
displayObject.value?.let {
Column() {
Text(
text = it.productName
)
Text(
text = it.price
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment