@@ -144,45 +144,48 @@ You can use Compose Wasm.
144144<div class =" kotlin-code " data-target-platform =" compose-wasm " >
145145
146146``` kotlin
147- import androidx.compose.ui.ExperimentalComposeUiApi
148- import androidx.compose.ui.window.CanvasBasedWindow
149147import androidx.compose.animation.AnimatedVisibility
150- import androidx.compose.foundation.Image
151148import androidx.compose.foundation.layout.Column
149+ import androidx.compose.foundation.layout.fillMaxSize
152150import androidx.compose.foundation.layout.fillMaxWidth
153151import androidx.compose.material.Button
154152import androidx.compose.material.MaterialTheme
155153import androidx.compose.material.Text
156- import androidx.compose.runtime.Composable
157- import androidx.compose.runtime.getValue
158- import androidx.compose.runtime.mutableStateOf
159- import androidx.compose.runtime.remember
160- import androidx.compose.runtime.setValue
154+ import androidx.compose.runtime.*
161155import androidx.compose.ui.Alignment
156+ import androidx.compose.ui.ExperimentalComposeUiApi
162157import androidx.compose.ui.Modifier
158+ import androidx.compose.ui.window.ComposeViewport
159+ import kotlinx.browser.document
163160
164161// sampleStart
165162@OptIn(ExperimentalComposeUiApi ::class )
166163fun main () {
167- CanvasBasedWindow { App () }
164+ ComposeViewport (viewportContainer = document.body!! , content = {
165+ App ()
166+ })
168167}
169168
170169@Composable
171170fun App () {
172171 MaterialTheme {
173- var greetingText by remember { mutableStateOf(" Hello World!" ) }
174- var showImage by remember { mutableStateOf(false ) }
175- var counter by remember { mutableStateOf(0 ) }
176- Column (Modifier .fillMaxWidth(), horizontalAlignment = Alignment .CenterHorizontally ) {
177- Button (onClick = {
178- counter++
179- greetingText = " Compose: ${Greeting ().greet()} "
180- showImage = ! showImage
181- }) {
182- Text (greetingText)
172+ var showContent by remember { mutableStateOf(false ) }
173+ Column (
174+ modifier = Modifier
175+ .fillMaxSize(),
176+ horizontalAlignment = Alignment .CenterHorizontally ,
177+ ) {
178+ Button (onClick = { showContent = ! showContent }) {
179+ Text (" Click me!" )
183180 }
184- AnimatedVisibility (showImage) {
185- Text (counter.toString())
181+ AnimatedVisibility (showContent) {
182+ val greeting = remember { Greeting ().greet() }
183+ Column (
184+ modifier = Modifier .fillMaxWidth(),
185+ horizontalAlignment = Alignment .CenterHorizontally ,
186+ ) {
187+ Text (" Compose: $greeting " )
188+ }
186189 }
187190 }
188191 }
0 commit comments