UNPKG

react-native-admob-native-ads

Version:

A simple and robust library for creating & displaying Admob Native Ads in your React Native App using Native Views

43 lines (37 loc) 1.03 kB
import React, { useContext, useEffect, useRef, useCallback } from "react"; import { findNodeHandle, Text } from "react-native"; import { NativeAdContext } from "./context"; const AdvertiserView = (props) => { const { nativeAd, nativeAdView } = useContext(NativeAdContext); const advertiserRef = useRef(); const _onLayout = useCallback(() => { if (!nativeAdView) return; let handle = findNodeHandle(advertiserRef.current); nativeAdView.setNativeProps({ advertiser: handle, }); }, [nativeAdView, advertiserRef]); useEffect(() => { _onLayout(); }, [nativeAd, nativeAdView]); return ( <Text {...props} nativeID="adAdvertiserView" style={[ props.style, { height: nativeAd.advertiser ? undefined : 0, }, ]} onLayout={_onLayout} > {nativeAd ? props.allCaps ? nativeAd.advertiser?.toUpperCase() : nativeAd.advertiser : null} </Text> ); }; export default AdvertiserView;