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

30 lines (25 loc) 749 B
import React, { createRef, useContext, useEffect } from "react"; import { findNodeHandle, Text } from "react-native"; import { NativeAdContext } from "./context"; const StoreView = (props) => { const { nativeAd, nativeAdView, setNativeAdView, setNativeAd } = useContext( NativeAdContext ); const storeViewRef = createRef(); const _onLayout = () => { if (!nativeAdView) return; let handle = findNodeHandle(storeViewRef.current); nativeAdView.setNativeProps({ store: handle, }); }; useEffect(() => { _onLayout(); }, [nativeAd, nativeAdView]); return ( <Text {...props} ref={storeViewRef} onLayout={_onLayout}> {nativeAd ? nativeAd.store : null} </Text> ); }; export default StoreView;