Appearance and SPA
Card appearance and component lifecycle integration.
Appearance
setAppearance()
ads.setAppearance({maxWidth: 360,mediaHeight: 200,mediaFit: "cover",mediaPosition: "top",mediaRadius: 12});
| Parameter | Values | Default |
|---|---|---|
colorScheme | auto, light, dark | auto |
surface | card / inline | card |
alignment | start / center / end | start |
buttonLayout | wrap / full-width | wrap |
mediaFit | cover / contain | cover |
mediaPosition | top / center / bottom | top |
Dimensions, px
| Parameter | Default | Range | Description |
|---|---|---|---|
maxWidth | 360 | 240-1200 / none | Maximum card width |
bodyFontSize | 14 | 13-20 | Body font size |
bodyLineHeight | 20 | 18-32 | Body line height |
brandFontSize | 14 | 13-22 | Brand font size |
metaFontSize | 11 | 11-14 | Disclosure font size |
mediaHeight | 200 | auto / 100-640 | Media height |
mediaRadius | 12 | 0-32 | Media corner radius |
buttonFontSize | 14 | 13-18 | Button font size |
buttonMinHeight | 32 | 32-56 | Minimum button height |
buttonHorizontalPadding | 12 | 8-32 | Horizontal button padding |
buttonRadius | 999 | 0-999 | Button corner radius |
contentPadding | 12 | 6-32 | Card padding |
cornerRadius | 16 | 0-32 | Card corner radius |
blockSpacing | 8 | 4-24 | Block spacing |
logoSize | 20 | 16-40 | Logo size |
cover: fill with cropping; contain: entire image. mediaPosition sets image alignment. mediaHeight=auto: original aspect ratio without cropping. Logos: centered contain.
Sizes are clamped. maxWidth=none: container width. Card height: content-based. Container height with overflow:hidden also clips text and buttons.
React
AdSlot.jsx
function AdSlot({ ads, messageId, question, answer }) {const ref = React.useRef(null);React.useEffect(() => {const target = ref.current;void ads.requestAd({target,requestId: messageId,context: { question, answer }});return () => ads.unmount(target);}, [ads, messageId, question, answer]);return <div ref={ref} style={{ maxWidth: 480 }} />;}
Lifecycle
| Event | Action |
|---|---|
| Message rerender | Same client, requestId and request parameters. |
| Screen hidden | ads.setScreenActive(false) |
| Screen shown | ads.setScreenActive(true) |
| Container removed | ads.unmount(target) |
| App shutdown | ads.dispose() |