Lukas Anda
07/03/2024, 4:33 PMfillMaxSize()
which if you want to for example show a native text view looks bad (as shown on screenshot) I'd like to preferably get rid of the white background (which can be done by color change) and the forced size by me to 100dp, if I remove manually set height, the resulting height is just 0 which is not what I wantVlad Mircan
07/04/2024, 7:06 AMIOS
view wrap its Compose
children it might be difficult.
I know we had issues with bottomSheets that were supposed to wrap content.
If you're interested, I can go into the details of the workaround we've done.Lukas Anda
07/04/2024, 7:20 AMCompose
wrapping its iOS views
Richard
07/04/2024, 11:28 AMLukas Anda
07/04/2024, 11:31 AMUIKitView
apply sizeToFit()
which does what I need it to do (also one can use in swiftUI the .frame()
function to further modify the behavior) and then in onResize()
I get the final size which I apply to the wrapping view. It's more comprehensible with the code:
@OptIn(ExperimentalForeignApi::class)
@Composable
actual fun NativeText(text: String, modifier: Modifier, backgroundColor: Color) {
val factory = LocalNativeTextViewFactory.current
// It's very tricky to do wrap content on injected views, so
// I guess we need to do this on per-view basis
var viewSize by remember { mutableStateOf(DpSize.Zero) }
Box(modifier.then(if (viewSize == DpSize.Zero) Modifier.fillMaxWidth().height(100.dp) else Modifier.size(viewSize))) {
UIKitViewController(
modifier = modifier.fillMaxSize(),
factory = {
factory.getView(text)
},
background = backgroundColor,
onResize = { controller, size ->
controller.view.apply {
// We set the original frame (compose wrapper rect) to the UIKitView
setFrame(size)
// We force the UIKitView to measure itself to tell us how much size it actually takes
// (this can be further modified by using .frame() in swiftUI for example
sizeToFit()
// We take the newly calculated size and force it to the box wrapping the frame (therefore we have no blank space)
frame.useContents {
val actualHeight = this.size.height
val actualWidth = this.size.width
viewSize = DpSize(actualWidth.dp, actualHeight.dp)
}
this.backgroundColor = UIColor.clearColor
this.opaque = true
this.setClipsToBounds(true)
}
}
)
}
}
Elijah Semyonov
07/04/2024, 12:19 PMLukas Anda
07/05/2024, 10:20 AMMax
07/06/2024, 8:39 AM