Alexander
09/25/2022, 11:24 AMrsktash
12/16/2022, 11:16 PMAlexander
12/17/2022, 10:24 AMprivate fun View.requestLayoutWithDelay(delayMillis: Long) {
postDelayed({
val t = parent?.parent?.parent
if (t == null) {
postDelayed({
val k = parent?.parent?.parent
if (k != null) {
k.requestLayout()
} else {
Timber.d("NativeBanner: parent is null again")
}
}, delayMillis)
} else {
t.requestLayout()
}
}, delayMillis)
}
AndroidViewBinding(
factory = AdmobBannerBinding::inflate,
update = {
...
if (it.root.tag != true) {
it.root.requestLayoutWithDelay(NATIVE_BANNER_REQUEST_LAYOUT_DELAY)
it.root.tag = true
}
},
modifier = modifier
.background(Color.Black)
.fillMaxWidth()
)
rsktash
12/17/2022, 10:43 AMAlexander
12/17/2022, 1:58 PMrsktash
12/23/2022, 2:14 PMAlexander
12/26/2022, 2:08 PMNamhn1495
12/28/2022, 2:24 PMAndroidView(
modifier = Modifier
.fillMaxWidth(),
factory = {
AdView(context).apply {
setAdSize(AdSize.BANNER)
adUnitId = unitId
adListener = object : AdListener() {
override fun onAdImpression() {
super.onAdImpression()
Timber.v("Banner Ad Impressed.")
}
override fun onAdLoaded() {
super.onAdLoaded()
placeholder.visibility = View.GONE
}
}
loadAd(AdRequest.Builder().build()
})
}
}
)
Alexander
12/28/2022, 2:38 PMOya Canli
04/25/2023, 8:09 AMSudhanshu Siddh
05/09/2023, 4:50 AMonAdLoaded()
to invoke adView.rootView.requestLayout()
is an interesting suggestion. I am also in a similar situation, we already have a working version with delay
logic but it seems that when the app is in the wild the solution works intermittently. Really curious to know what kind of issues did you run into when using delay
? Can you also shed some light on your implementation of using onAdLoaded()
? From what I understand you would only display the Ad when you have a successfully fetched an Ad, how does tying onAdLoaded
to requestLayout
help in this scenario? If you are fetching Ads for a list, you might already have received an onAdLoaded
callback before the Ad item comes into view. Anything you share will be very helpful, since at the minute I am contemplating if it would be worth while to pursue the approach for my use case. Thank you again 🙂Oya Canli
06/02/2023, 8:52 PMCấn Văn Nghị
08/27/2023, 4:47 PMOya Canli
08/27/2023, 7:38 PMAlexander
08/27/2023, 7:53 PMprivate const val NATIVE_BANNER_REQUEST_LAYOUT_DELAY = 1500L
Oya Canli
08/27/2023, 8:50 PMCấn Văn Nghị
08/28/2023, 1:26 AMAlexander
08/29/2023, 11:58 AM