Calle Höglund
08/21/2025, 9:29 AM@Composable
actual fun NativeButton(
enabled: Boolean,
onClick: () -> Unit,
modifier: Modifier
) {
val factory: NativeViewFactory = LocalNativeViewFactory.current
UIKitViewController(
modifier = modifier,
factory = {
factory.createNativeButton(
enabled = enabled,
onClick = onClick,
)
}
)
}
Changing the enabled flag is not updating the UI in SwiftUI. How do i achieve this? Any suggestions?Taush Sampley
08/21/2025, 11:22 AMupdate
callback. factory
only gets called on the first composition. Subsequent recompositions need to pass any change in state through an update
callback.
Annoying that I couldn’t find it in the docs, but here’s the signature in source: https://github.com/JetBrains/compose-multiplatform-core/blob/86802de2395e82f726fce[…]uikitMain/kotlin/androidx/compose/ui/interop/UIKitView.uikit.ktCalle Höglund
08/21/2025, 11:29 AM@Composable
actual fun NativeButton(
enabled: Boolean,
onClick: () -> Unit,
modifier: Modifier
) {
val factory: NativeViewFactory = LocalNativeViewFactory.current
val enabledState = remember { MutableStateFlow(enabled) }
UIKitViewController(
modifier = modifier,
factory = {
factory.createNativeButton(
enabled = enabledState.asStateFlow(),
onClick = onClick,
)
},
update = {
enabledState.update { enabled }
}
)
}
SO to @Richard that responded in another 🧵.