Alexander
09/25/2022, 11:24 AMrsktash
12/16/2022, 11:16 PMrsktash
12/17/2022, 9:26 AMAlexander
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)
}
Alexander
12/17/2022, 10:26 AMAndroidViewBinding(
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 PMAlexander
12/17/2022, 2:00 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 PMCấn Văn Nghị
08/27/2023, 6:31 PMOya Canli
08/27/2023, 7:38 PMAlexander
08/27/2023, 7:53 PMprivate const val NATIVE_BANNER_REQUEST_LAYOUT_DELAY = 1500L
Alexander
08/27/2023, 7:59 PMOya Canli
08/27/2023, 8:50 PMCấn Văn Nghị
08/28/2023, 1:26 AMAlexander
08/29/2023, 11:58 AMDoraswamy Vamsi
04/25/2024, 8:05 AMAndroidView(
modifier = Modifier._fillMaxSize_(),
factory = *{* context *->*
LayoutInflater.from(context)
.inflate(R.layout._nativead_layout_, null, false) as NativeAdView
*}*, update = *{* view *->*
val advertiser = view.findViewById<TextView>(R.id._tv_ad_advertiser_)
val title = view.findViewById<TextView>(R.id._tv_ad_headline_)
val description = view.findViewById<TextView>(R.id._tv_ad_body_)
val icon = view.findViewById<ImageView>(R.id._iv_ad_app_icon_)
val ctaButton = view.findViewById<Button>(R.id._btn_ad_call_to_action_)
val fullImage = view.findViewById<ImageView>(R.id._iv_full_image_)
val mediaView = view.findViewById<MediaView>(R.id._ad_media_view_google_)
view._mediaView_ = mediaView
chosenAd.value?._let_ *{*
_setNativeAdCustom_(
*it*,
view,
advertiser,
title,
description,
icon,
view._context_,
ctaButton,
fullImage
)
view.setNativeAd(*it*)
view._requestLayoutWithDelay_(400)
}
}
)
private fun View.requestLayoutWithDelay(delayMillis: Long) {
post {
val t = parent.findAndroidComposeViewParent()
if (t == null) {
println("Calling in if for requesting layout")
postDelayed(delayMillis) {
val k = parent.findAndroidComposeViewParent()
if (k != null) {
k.requestLayout()
} else {
Log.i("TAG", "This should never happen")
}
}
} else {
println("Calling in else for requesting layout")
t.requestLayout()
}
}
}
private fun ViewParent?.findAndroidComposeViewParent(): ViewParent? = when {
this != null && this::class.java.simpleName == "AndroidComposeView" -> this
this != null -> this.parent.findAndroidComposeViewParent() ?: this
else -> null
}
ThanksDoraswamy Vamsi
04/25/2024, 8:10 AMpostDelayed(delayMillis) {
val k = parent.findAndroidComposeViewParent()
if (k != null) {
k.requestLayout()
} else {
Log.i("TAG", "This should never happen")
}
}
In the release build, I checked that it goes into this else conditionCấn Văn Nghị
04/27/2024, 2:09 AM-keep class androidx.compose.ui.platform.AndroidComposeView
Doraswamy Vamsi
05/21/2024, 9:00 AMCấn Văn Nghị
12/16/2024, 9:13 AM