Browse Source

Blue border around UIKitView (#3619)

pull/3624/head
dima.avdeev 1 year ago committed by GitHub
parent
commit
eb5cf4f677
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      examples/interop/ios-uikit-in-compose/shared/src/iosMain/kotlin/UseUITextField.kt
  2. 6
      examples/interop/ios-uikit-in-compose/shared/src/iosMain/kotlin/main.ios.kt

7
examples/interop/ios-uikit-in-compose/shared/src/iosMain/kotlin/UseUITextField.kt

@ -1,14 +1,11 @@
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.interop.UIKitView import androidx.compose.ui.interop.UIKitView
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import kotlinx.cinterop.ExperimentalForeignApi import kotlinx.cinterop.ExperimentalForeignApi
@ -20,7 +17,7 @@ import platform.UIKit.UITextField
@OptIn(ExperimentalForeignApi::class) @OptIn(ExperimentalForeignApi::class)
@Composable @Composable
fun UseUITextField() { fun UseUITextField(modifier: Modifier = Modifier) {
var message by remember { mutableStateOf("Hello, World!") } var message by remember { mutableStateOf("Hello, World!") }
UIKitView( UIKitView(
factory = { factory = {
@ -37,7 +34,7 @@ fun UseUITextField() {
) )
textField textField
}, },
modifier = Modifier.padding(4.dp).fillMaxWidth().height(30.dp).border(2.dp, Color.Blue), modifier = modifier.fillMaxWidth().height(30.dp),
update = { textField -> update = { textField ->
textField.text = message textField.text = message
} }

6
examples/interop/ios-uikit-in-compose/shared/src/iosMain/kotlin/main.ios.kt

@ -1,6 +1,7 @@
import androidx.compose.foundation.border import androidx.compose.foundation.border
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
@ -21,14 +22,15 @@ fun ComposeEntryPoint(): UIViewController =
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text("How to use UIKitView inside Compose") Text("How to use UIKitView inside Compose")
UIKitView( UIKitView(
factory = { MKMapView() }, factory = { MKMapView() },
modifier = Modifier.size(300.dp).border(2.dp, Color.Blue), modifier = Modifier.padding(4.dp).border(2.dp, Color.Blue).size(300.dp),
update = {}, update = {},
) )
Spacer(Modifier.size(20.dp)) Spacer(Modifier.size(20.dp))
UseUITextField() UseUITextField(Modifier.padding(4.dp).border(2.dp, Color.Blue))
} }
} }

Loading…
Cancel
Save