React Native 배너 광고
배너광고 노출하기
import React, { useRef, useState } from 'react'
import { Button, Dimensions, StyleSheet, Text, View } from 'react-native'
import { AdropBanner } from 'adrop-ads-react-native'
interface IBanner {
load: () => void
}
const BannerExample: React.FC = () => {
const bannerRef = useRef<IBanner>(null)
const screenWidth = Dimensions.get('window').width
const loadBanner = () => {
bannerRef.current?.load()
}
const onAdClicked = (unitId: string, creativeId: string) => {
console.log('배너 광고 클릭됨', unitId, creativeId)
}
const onAdReceived = (unitId: string, creativeId: string) => {
console.log('배너 광고 수신됨', unitId, creativeId)
}
const onAdFailedToReceive = (unitId: string, error?: string) => {
console.log('배너 광고 수신 실패', unitId, error)
}
return (
<View style={styles.container}>
<Button title="배너 광고 로드" onPress={loadBanner} />
<AdropBanner
ref={bannerRef}
unitId="YOUR_UNIT_ID"
style={{ width: screenWidth, height: 50 }}
autoLoad={false}
onAdClicked={onAdClicked}
onAdReceived={onAdReceived}
onAdFailedToReceive={onAdFailedToReceive}
/>
</View>
)
}
export default BannerExample
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
padding: 16,
}
})적용 확인하기
Last updated