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

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