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) 758 B
import React, { createRef, useContext, useEffect } from "react"; import { findNodeHandle, Text } from "react-native"; import { NativeAdContext } from "./context"; const HeadlineView = (props) => { const { nativeAd, nativeAdView, setNativeAdView, setNativeAd } = useContext( NativeAdContext ); const headlineRef = createRef(); const _onLayout = () => { if (!nativeAdView) return; let handle = findNodeHandle(headlineRef.current); nativeAdView.setNativeProps({ headline: handle, }); }; useEffect(() => { _onLayout(); }, [nativeAd, nativeAdView]); return ( <Text {...props} ref={headlineRef} onLayout={_onLayout}> {nativeAd ? nativeAd.headline : null} </Text> ); }; export default HeadlineView;