import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.interop.UIKitView import androidx.compose.ui.unit.dp import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.ObjCAction import platform.CoreGraphics.CGRectMake import platform.Foundation.NSSelectorFromString import platform.UIKit.UIControlEventEditingChanged import platform.UIKit.UITextField @OptIn(ExperimentalForeignApi::class) @Composable fun UseUITextField(modifier: Modifier = Modifier) { var message by remember { mutableStateOf("Hello, World!") } UIKitView( factory = { val textField = object : UITextField(CGRectMake(0.0, 0.0, 0.0, 0.0)) { @ObjCAction fun editingChanged() { message = text ?: "" } } textField.addTarget( target = textField, action = NSSelectorFromString(textField::editingChanged.name), forControlEvents = UIControlEventEditingChanged ) textField }, modifier = modifier.fillMaxWidth().height(30.dp), update = { textField -> textField.text = message } ) }