UNPKG

react-native-admob-native-ads-mrousavy

Version:

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

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