Hi, I'm trying to get banner ads showing in a list on iOS. I'm setting a callback from swift to kotlin to get a UIViewController factory for compose, setting this in swift and invoking it when I draw my list. The ads are clickable (they take me to the webpage), but are not being drawn. Code in 🧵 . Any ideas?
Fergus Hewson
10/13/2024, 6:49 PM
Kotlin
Copy code
@Composable
actual fun GoogleAd() {
UIKitViewController(
factory = factory!!,
modifier = Modifier.fillMaxWidth().height(100.dp).border(2.dp, Color.Blue),
)
}
private var factory: (() ->UIViewController)? = null
fun setFactory(f: ()-> UIViewController){
factory = f
}
Swift
Copy code
Ads_iosKt.setFactory(f : {() -> UIViewController in
let ad = BannerAdView()
.frame(width: GADAdSizeBanner.size.width, height: GADAdSizeBanner.size.height)
.background(Color.red)
return UIHostingController(rootView: ad)
}
)
Fergus Hewson
10/13/2024, 8:01 PM
I was going something with the graphics layer on a containing composable. This prevented the view from being drawn. This is working now.