Hello, I tried SwiftUI inside Compose Multiplatfor...
# compose
u
Hello, I tried SwiftUI inside Compose Multiplatform to use Lottie animation on Android iOS. It works fine on Android, but on iOS, it doesn't match the parent view
Copy code
Box(
    modifier = Modifier
        .fillMaxSize()
        .background(DmsTheme.colors.background),
    contentAlignment = Alignment.Center,
) {
    DmsLottieAnimation(
        modifier = Modifier
            .fillMaxSize()
            .horizontalPadding(100.dp)
            .background(DmsTheme.colors.background),
        animationFileName = animationName
    )
}
Copy code
@Composable
actual fun DmsLottieAnimation(
    modifier: Modifier,
    animationFileName: String,
) {

    UIKitViewController(
        factory = {
            LottieControllerProvider.lottieAnimationController(animationFileName)
        },
        modifier = modifier,
    )
}
Copy code
fun mainViewController(
    lottieUIViewController: (String) -> UIViewController
) = ComposeUIViewController(
    configure = { LottieControllerProvider.lottieAnimationController = lottieUIViewController }
) {
    DmsApp()
}
*func* makeUIViewController(context: Context) -> UIViewController {
MainViewControllerKt.mainViewController(
lottieUIViewController: { animationName *in*
*return* UIHostingController(rootView: DmsLottieView(animationName: animationName))
}
)
}
*struct* DmsLottieView: UIViewRepresentable {
*var* animationName: String
*func* makeUIView(context: Context) -> LottieAnimationView {
*let* animationView = LottieAnimationView(name: animationName)
animationView.translatesAutoresizingMaskIntoConstraints =
false
animationView.contentMode = .scaleAspectFit
animationView.backgroundColor = UIColor.clear
animationView.isOpaque = *false*
animationView.play()
*return* animationView
}
func updateUIView(_ uiView: LottieAnimationView, context: Context) {
uiView.backgroundColor = UIColor.clear NSLayoutConstraint.activate([ uiView.widthAnchor.constraint(equalTo: uiView.widthAnchor), uiView.heightAnchor.constraint(equalTo: uiView.heightAnchor) ]) } }
🧡 9
z
Please keep long code snippets to the thread, thanks!
v
Try using Compottie
u
v
Upgrade kotlinx serialization to 1.7.3 and this error goes away
u
change this kotlinx serialization?
Copy code
org.jetbrains.kotlinx:kotlinx-serialization-json
v
Yes
u
Thank you I will try
I have this problem with iOS
Compilation failed: IrTypeAliasSymbolImpl is already bound. Signature: <http://io.ktor.utils.io|io.ktor.utils.io>.core/ByteReadPacket|null[0]. Owner: TYPEALIAS name:ByteReadPacket visibility:public expandedType:kotlinx.io.Source
j
u
I used kottie library but it's have problem https://github.com/ismai117/kottie/issues/26