Thursday 30 September 2021

When do I need to add @Composable with Android Studio Compose?

The following code is from the project.

I find that fun MainScreen() add @Composable, and fun launchDetailsActivity doesn't add @Composable.

It make me confused. I think all function which apply to Compose should to add @Composable, why doesn't fun launchDetailsActivity add @Composable?

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        setContent {
            ProvideWindowInsets {
                ProvideImageLoader {
                    CraneTheme {
                        MainScreen(
                            onExploreItemClicked = { launchDetailsActivity(context = this, item = it) }
                        )
                    }
                }
            }
        }
    }
}


@Composable
fun MainScreen(onExploreItemClicked: OnExploreItemClicked) {
  ...
}


fun launchDetailsActivity(context: Context, item: ExploreModel) {
    context.startActivity(createDetailsActivityIntent(context, item))
}


from When do I need to add @Composable with Android Studio Compose?

No comments:

Post a Comment