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
Box(
modifier = Modifier
.fillMaxSize()
.background(DmsTheme.colors.background),
contentAlignment = Alignment.Center,
) {
DmsLottieAnimation(
modifier = Modifier
.fillMaxSize()
.horizontalPadding(100.dp)
.background(DmsTheme.colors.background),
animationFileName = animationName
)
}
@Composable
actual fun DmsLottieAnimation(
modifier: Modifier,
animationFileName: String,
) {
UIKitViewController(
factory = {
LottieControllerProvider.lottieAnimationController(animationFileName)
},
modifier = modifier,
)
}
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)
])
}
}