Mahozad
Mahozad

Reputation: 24532

What is ComposeViewAdapter used for in Jetpack Compose?

I have a simple composable function in com.example.Example.kt:

@Preview
@Composable fun ExampleComposable() {
    Text("Hello")
}

I tried to use ComposeViewAdapter like below:

<androidx.compose.ui.tooling.ComposeViewAdapter
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:composableName="com.example.ExampleKt" />

Android Studio does not show any preview of the composable in the design pane.

Also, how is ComposeViewAdapter different from androidx.compose.ui.platform.ComposeView?

Upvotes: 4

Views: 1410

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 87844

Example.kt file can have many composables, you need to specify the composable name:

<androidx.compose.ui.tooling.ComposeViewAdapter
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:composableName="com.example.ExampleKt.ExampleComposable" />

Upvotes: 3

Related Questions