CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-compose-ui--ui-uikitsimarm64

Compose Multiplatform UI library for iOS Simulator ARM64 target providing declarative UI framework based on Jetpack Compose for multiplatform development

Pending
Overview
Eval results
Files

ios-integration.mddocs/

iOS Platform Integration

iOS-specific APIs for integrating Compose Multiplatform UI with iOS applications, UIKit components, and native iOS functionality.

Capabilities

ComposeUIViewController

Primary entry point for embedding Compose content in iOS applications as a UIViewController.

/**
 * Creates a UIViewController containing Compose content for integration with iOS apps
 * @param configure Configuration block for iOS-specific settings
 * @param content Composable content to display
 * @return UIViewController that can be used in iOS navigation hierarchies
 */
fun ComposeUIViewController(
    configure: ComposeUIViewControllerConfiguration.() -> Unit = {},
    content: @Composable () -> Unit
): UIViewController

/**
 * Configuration options for ComposeUIViewController
 */
class ComposeUIViewControllerConfiguration {
    /**
     * Controls validation of Info.plist CADisableMinimumFrameDurationOnPhone requirement
     * Set to false to disable strict validation (not recommended for production)
     */
    var enforceStrictPlistSanityCheck: Boolean
}

Usage Examples:

// Basic usage - create a view controller with Compose content
fun MainViewController(): UIViewController =
    ComposeUIViewController {
        MyComposeApp()
    }

// Advanced configuration
fun ConfiguredViewController(): UIViewController =
    ComposeUIViewController(
        configure = {
            enforceStrictPlistSanityCheck = false
        }
    ) {
        MyComposeApp()
    }

UIKit Interop Components

Components for embedding native UIKit views and view controllers within Compose content.

/**
 * Embed a native UIView inside Compose content
 * @param factory Factory function that creates the UIView instance
 * @param modifier Modifier for styling and layout
 * @param update Function called when the view needs to be updated
 * @param onResize Callback for handling view resize events
 * @param background Background color for the embedded view
 */
@Composable
fun UIKitView(
    factory: () -> UIView,
    modifier: Modifier = Modifier,
    update: (UIView) -> Unit = {},
    onResize: ((view: UIView, rect: CValue<CGRect>) -> Unit)? = null,
    background: Color = Color.Unspecified
)

/**
 * Embed a native UIViewController inside Compose content
 * @param factory Factory function that creates the UIViewController instance
 * @param modifier Modifier for styling and layout
 * @param update Function called when the view controller needs to be updated
 */
@Composable
fun UIKitViewController(
    factory: () -> UIViewController,
    modifier: Modifier = Modifier,
    update: (UIViewController) -> Unit = {}
)

Usage Examples:

// Embed a MapKit view
UIKitView(
    factory = { MKMapView() },
    modifier = Modifier
        .padding(4.dp)
        .border(2.dp, Color.Blue)
        .size(300.dp),
    update = { mapView ->
        // Configure map properties
        mapView.showsUserLocation = true
    }
)

// Embed a UITextField with state synchronization
@OptIn(ExperimentalForeignApi::class)
@Composable
fun NativeTextField() {
    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
        }
    )
}

// Embed a complex camera view with resize handling
UIKitView(
    modifier = Modifier.fillMaxSize(),
    background = Color.Black,
    factory = {
        val cameraContainer = UIView()
        cameraContainer.layer.addSublayer(cameraPreviewLayer)
        cameraPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
        captureSession.startRunning()
        cameraContainer
    },
    onResize = { view: UIView, rect: CValue<CGRect> ->
        CATransaction.begin()
        CATransaction.setValue(true, kCATransactionDisableActions)
        view.layer.setFrame(rect)
        cameraPreviewLayer.setFrame(rect)
        CATransaction.commit()
    }
)

iOS Window Management

iOS-specific window management and safe area handling.

/**
 * System-defined window insets for iOS safe areas and system UI
 */
object WindowInsets {
    val systemBars: WindowInsets
    val statusBars: WindowInsets
    val navigationBars: WindowInsets
    val ime: WindowInsets
    val safeDrawing: WindowInsets
    val safeGestures: WindowInsets
    val safeContent: WindowInsets
}

/**
 * Apply window insets padding to respect iOS safe areas
 */
fun Modifier.windowInsetsPadding(insets: WindowInsets): Modifier

Usage Examples:

// Respect iOS safe areas
Column(
    modifier = Modifier
        .fillMaxSize()
        .windowInsetsPadding(WindowInsets.systemBars),
    horizontalAlignment = Alignment.CenterHorizontally
) {
    // Content automatically respects safe areas
    Text("This content respects iOS safe areas")
}

// Handle keyboard insets
LazyColumn(
    modifier = Modifier
        .fillMaxSize()
        .windowInsetsPadding(WindowInsets.ime)
) {
    // List content that adjusts for keyboard
}

iOS-SwiftUI Integration

Pattern for integrating Compose UIViewController with SwiftUI applications.

SwiftUI Integration Pattern:

// SwiftUI wrapper for Compose content
struct ComposeView: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UIViewController {
        let controller = Main_iosKt.MainViewController()
        controller.overrideUserInterfaceStyle = .light
        return controller
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
        // Handle updates if needed
    }
}

// Use in SwiftUI
struct ContentView: View {
    var body: some View {
        ComposeView()
            .ignoresSafeArea()
    }
}

Required iOS Imports

Essential imports for iOS platform integration:

// Core iOS integration
import androidx.compose.ui.window.ComposeUIViewController
import androidx.compose.ui.interop.UIKitView
import androidx.compose.ui.interop.UIKitViewController

// Native iOS APIs
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCAction
import kotlinx.cinterop.CValue
import platform.UIKit.*
import platform.Foundation.*
import platform.CoreGraphics.*

// For advanced integrations
import platform.AVFoundation.*
import platform.MapKit.*

iOS Accessibility Support

Configuration for iOS accessibility integration:

/**
 * Accessibility synchronization options for iOS
 */
enum class AccessibilitySyncOptions {
    /**
     * Always synchronize accessibility tree with iOS
     */
    Always,
    
    /**
     * Synchronize only when accessibility services are enabled
     */
    WhenAccessibilityServicesEnabled,
    
    /**
     * Never synchronize accessibility tree
     */
    Never
}

/**
 * Configure content with accessibility support
 */
@ExperimentalComposeApi
fun setContentWithAccessibility(
    accessibilitySyncOptions: AccessibilitySyncOptions = AccessibilitySyncOptions.WhenAccessibilityServicesEnabled,
    content: @Composable () -> Unit
)

iOS Configuration Requirements

Important configuration requirements for iOS apps using Compose:

Info.plist Requirement:

<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>

Alternative Configuration:

ComposeUIViewController(
    configure = {
        // Opt-out of strict plist validation (not recommended for production)
        enforceStrictPlistSanityCheck = false
    }
) {
    content()
}

Types

/**
 * iOS-specific geometry types from CoreGraphics
 */
typealias CGRect = platform.CoreGraphics.CGRect
typealias CGPoint = platform.CoreGraphics.CGPoint
typealias CGSize = platform.CoreGraphics.CGSize

/**
 * Common UIKit view types for interop
 */
typealias UIView = platform.UIKit.UIView
typealias UIViewController = platform.UIKit.UIViewController
typealias UITextField = platform.UIKit.UITextField
typealias UILabel = platform.UIKit.UILabel

Install with Tessl CLI

npx tessl i tessl/maven-org-jetbrains-compose-ui--ui-uikitsimarm64

docs

composables.md

core-ui.md

graphics.md

index.md

input.md

ios-integration.md

layout.md

material-design.md

resources.md

state.md

text.md

window.md

tile.json