NativeTemplateCompose

fun NativeTemplateCompose(adUnitId: String, template: NativeAdTemplate = NativeAdTemplate.CARD_MODERN, modifier: Modifier = Modifier, loadingStrategy: AdLoadingStrategy? = null, onAdLoaded: () -> Unit? = null, onAdFailedToLoad: (LoadAdError?) -> Unit? = null, onAdClicked: () -> Unit? = null, onAdImpression: () -> Unit? = null, onAdOpened: () -> Unit? = null, onAdClosed: () -> Unit? = null, onPaidEvent: (AdValue) -> Unit? = null, customLayoutResId: Int? = null, customShimmerResId: Int? = null, customSizeHint: NativeAdSize = NativeAdSize.MEDIUM)

A Jetpack Compose wrapper for NativeTemplateView.

Supports all 17 template styles with Material 3 theming.

Since

2.6.0

Parameters

adUnitId

The AdMob ad unit ID

template

The template style to use (default: CARD_MODERN)

modifier

Modifier for styling the ad container

loadingStrategy

Loading strategy. All four strategies are supported for native ads; ONLY_CACHE serves a cached ad if one is ready and otherwise hides the container without issuing a network request.

onAdLoaded

Callback when the ad loads successfully

onAdFailedToLoad

Callback when the ad fails to load

onAdClicked

Callback when the ad is clicked

onAdImpression

Callback when the ad impression is recorded

onAdOpened

Callback when the ad opens an overlay

onAdClosed

Callback when the ad overlay is closed

onPaidEvent

Callback when a paid event occurs (for revenue tracking)

customLayoutResId

Optional fully custom native ad layout, overrides template when set. Root must be (or inflate as) a NativeAdView reusing the standard asset ids (ad_headline, ad_body, ad_call_to_action, ad_app_icon, ad_advertiser, ad_media, ad_stars, ad_choices_view). See NativeTemplateView.setCustomTemplate.

customShimmerResId

Optional loading placeholder for customLayoutResId. Falls back to template's shimmer if omitted.

customSizeHint

Cache classification / Yandex waterfall fallback size for customLayoutResId, since a custom layout has no built-in size bucket.