@momo-kits/native-ads
Version:
A simple and robust library for creating & displaying Admob Native Ads in your React Native App using Native Views
37 lines (31 loc) • 1.02 kB
JavaScript
import React, { useCallback, useContext, useEffect, useRef } from "react";
import { findNodeHandle } from "react-native";
import { NativeAdContext } from "./context";
import { Image } from "@momo-kits/foundation";
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 }}
/>
) : null;
};
export default IconView;