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

39 lines (33 loc) 1 kB
import React, { useCallback, useContext, useEffect, useRef } from "react"; import { findNodeHandle, Image } from "react-native"; import { NativeAdContext } from "./context"; const IconView = (props) => { const { nativeAd, nativeAdView } = useContext(NativeAdContext); const iconViewRef = useRef(); const _onLayout = useCallback(() => { if (!nativeAdView) return; let handle = findNodeHandle(iconViewRef.current); nativeAdView.setNativeProps({ icon: handle, }); }, [nativeAdView, iconViewRef]); useEffect(() => { _onLayout(); }, [nativeAd, nativeAdView]); if (nativeAd && nativeAd.icon === "empty") { return <Image style={props.style} ref={iconViewRef} onLayout={_onLayout} />; } return ( nativeAd?.icon !== "noicon" && nativeAd.icon && ( <Image {...props} resizeMode="cover" ref={iconViewRef} onLayout={_onLayout} source={{ uri: nativeAd.icon }} /> ) ); }; export default IconView;