UNPKG

react-native-admob-native-ads

Version:

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

39 lines (33 loc) 901 B
import React, { useContext, useEffect, useRef, useCallback } from "react"; import { findNodeHandle, Text } from "react-native"; import { NativeAdContext } from "./context"; const PriceView = (props) => { const { nativeAd, nativeAdView } = useContext(NativeAdContext); const priceViewRef = useRef(); const _onLayout = useCallback(() => { if (!nativeAdView) return; let handle = findNodeHandle(priceViewRef.current); nativeAdView.setNativeProps({ price: handle, }); }, [nativeAdView, priceViewRef]); useEffect(() => { _onLayout(); }, [nativeAd, nativeAdView]); return ( <Text {...props} ref={priceViewRef} style={[ props.style, { height: nativeAd.price ? undefined : 0, }, ]} onLayout={_onLayout} > {nativeAd ? nativeAd.price : null} </Text> ); }; export default PriceView;