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
33 lines (28 loc) • 828 B
JavaScript
import React, { createRef, useContext, useEffect } from "react";
import { findNodeHandle, Image } from "react-native";
import { NativeAdContext } from "./context";
const ImageView = (props) => {
const { nativeAd, nativeAdView, setNativeAdView, setNativeAd } = useContext(
NativeAdContext
);
const imageViewRef = createRef();
const _onLayout = () => {
if (!nativeAdView) return;
let handle = findNodeHandle(imageViewRef.current);
nativeAdView.setNativeProps({
image: handle,
});
};
useEffect(() => {
_onLayout();
}, [nativeAd, nativeAdView]);
return nativeAd && nativeAd.images && nativeAd.images[0] ? (
<Image
{...props}
ref={imageViewRef}
onLayout={_onLayout}
source={{ uri: nativeAd.images[0].url }}
/>
) : null;
};
export default ImageView;