NativeAdSlot

fun NativeAdSlot(adUnitId: String, presentation: NativeAdPresentation, modifier: Modifier = Modifier, position: GroupedItemPosition = GroupedItemPosition.SINGLE, showContainer: Boolean = true, cornerRadius: Dp = SizeConstants.ExtraLargeSize, containerColor: Color = Color.Unspecified, style: NativeAdStyle = NativeAdStyle(), label: String? = null, cache: NativeAdCache? = null, cacheKey: Any? = null, onAdLoaded: (Boolean) -> Unit = {})(source)

The single entry point for rendering a native ad anywhere in the toolkit.

Every native ad surface goes through this composable. New surfaces add a NativeAdPresentation rather than a new component with its own view tree, so ad policy, lifecycle, palette handling, and the disclosure label live in one place.

Behaviour worth knowing:

  • Nothing is rendered until an ad is actually bound. The container used to be drawn up front, which left an empty bordered card behind whenever the load failed.

  • onAdLoaded reports true once an ad is bound and false when there is none, so hosts can collapse the slot together with its spacing instead of leaving a gap.

  • The user's ads preference and a blank adUnitId both suppress the request entirely.

  • Under LocalInspectionMode a NativeAdPlaceholder is drawn instead of loading anything.

  • Inside a lazy list or grid, pass cache and cacheKey so the ad survives its item scrolling out of view instead of being destroyed and requested again; see NativeAdCache.

Parameters

adUnitId

the AdMob native ad unit to request.

presentation

the shape the ad takes on screen.

position

position inside a grouped list; affects the container's corners.

showContainer

false renders the ad without a card behind it.

cornerRadius

corner radius used when position is GroupedItemPosition.SINGLE.

containerColor

overrides the card container. The default is an unstyled card, so the ad matches ordinary content; pass a colour on screens that build their cards differently, and in consumer apps whose surfaces are their own. Ignored when showContainer is false.

style

the ad's finish on this screen: badge silhouette and colour, text sizes and colours, and whether the call to action is a filled pill or a text button. It overrides only what it names, so the default leaves the presentation exactly as it was built.

label

replaces the disclosure text ("Sponsored Ad"), for a placement whose label reads as a section title. It must still say the content is an ad, and it stays inside the ad view.

cache

keeps the ad while the slot is out of composition. Ignored without cacheKey.

cacheKey

identifies this slot in cache; unique among the slots composed at one time.

onAdLoaded

invoked with whether an ad is currently displayed.