From 753570b0590d79709ee4ee938a0b5fba3d7124f3 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 10:38:21 +0500 Subject: [PATCH 01/13] fix ad failed to recieve events --- .../nativeads/RNAdMobNativeViewManager.java | 18 +++- .../rnadmob/nativeads/RNNativeAdWrapper.java | 82 +++++++++++++------ 2 files changed, 75 insertions(+), 25 deletions(-) diff --git a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java index 24761737..4d135f4b 100755 --- a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java +++ b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java @@ -2,6 +2,8 @@ import android.view.View; +import androidx.annotation.NonNull; + import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableNativeArray; import com.facebook.react.common.MapBuilder; @@ -31,7 +33,7 @@ public class RNAdMobNativeViewManager extends ViewGroupManager Date: Tue, 21 Apr 2020 10:40:43 +0500 Subject: [PATCH 02/13] add delayAdLoad prop --- index.d.ts | 9 +++++++++ src/index.js | 1 + 2 files changed, 10 insertions(+) diff --git a/index.d.ts b/index.d.ts index 7e15518f..1088f740 100644 --- a/index.d.ts +++ b/index.d.ts @@ -74,6 +74,15 @@ type NativeAdViewProps = { */ refreshInterval?: number; + + /** + * Time in milliseconds to delay ad loading. Default is 1000ms. + * This is usually done so that ad request is done after the views are attached. + */ + + delayAdLoading?: number; + + /** * Set testdevices for the ad. */ diff --git a/src/index.js b/src/index.js index 2e9e17f6..d81ecb3c 100644 --- a/src/index.js +++ b/src/index.js @@ -86,6 +86,7 @@ const NativeAdView = (props) => { onAdOpened={_onAdOpened} onAdClosed={_onAdClosed} onAdImpression={_onAdImpression} + delayAdLoad={props.delayAdLoad? props.delayAdLoad : 1000} style={props.style} onUnifiedNativeAdLoaded={_onUnifiedNativeAdLoaded} adUnitID={props.adUnitID} From e34f4e3315f98f24f92d555b8a464e6222e137d0 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:01:05 +0500 Subject: [PATCH 03/13] use findNodeHandle on android to find views --- src/AdvertiserView.js | 2 +- src/CallToActionView.js | 2 +- src/HeadlineView.js | 2 +- src/IconView.js | 2 +- src/ImageView.js | 2 +- src/PriceView.js | 2 +- src/StarRatingView.js | 2 +- src/StoreView.js | 2 +- src/TaglineView.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/AdvertiserView.js b/src/AdvertiserView.js index 717005ae..4a20b291 100644 --- a/src/AdvertiserView.js +++ b/src/AdvertiserView.js @@ -7,7 +7,7 @@ const AdvertiserView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(advertiserRef.current); nativeAdView.current?.setNativeProps({ advertiser: handle, diff --git a/src/CallToActionView.js b/src/CallToActionView.js index f46d8c77..8e25bb77 100644 --- a/src/CallToActionView.js +++ b/src/CallToActionView.js @@ -8,7 +8,7 @@ const CallToActionView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(callToActionRef.current); nativeAdView.current?.setNativeProps({ callToAction: handle, diff --git a/src/HeadlineView.js b/src/HeadlineView.js index 59c18e3a..1317f2c0 100644 --- a/src/HeadlineView.js +++ b/src/HeadlineView.js @@ -8,7 +8,7 @@ const HeadlineView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(headlineRef.current); nativeAdView.current?.setNativeProps({ headline: handle, diff --git a/src/IconView.js b/src/IconView.js index 93a39318..4029f74c 100644 --- a/src/IconView.js +++ b/src/IconView.js @@ -8,7 +8,7 @@ const IconView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(iconViewRef.current); nativeAdView.current?.setNativeProps({ icon: handle, diff --git a/src/ImageView.js b/src/ImageView.js index 25ae3a6e..1b3144b2 100644 --- a/src/ImageView.js +++ b/src/ImageView.js @@ -8,7 +8,7 @@ const ImageView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(imageViewRef.current); nativeAdView.current?.setNativeProps({ image: handle, diff --git a/src/PriceView.js b/src/PriceView.js index 8ed44dc5..424c634f 100644 --- a/src/PriceView.js +++ b/src/PriceView.js @@ -8,7 +8,7 @@ const PriceView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(priceViewRef.current); nativeAdView.current?.setNativeProps({ price: handle, diff --git a/src/StarRatingView.js b/src/StarRatingView.js index c17a4547..ef60d26e 100644 --- a/src/StarRatingView.js +++ b/src/StarRatingView.js @@ -8,7 +8,7 @@ const StarRatingView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(starRatingRef.current); nativeAdView.current?.setNativeProps({ starrating: handle, diff --git a/src/StoreView.js b/src/StoreView.js index 59c4cc81..8e0160f7 100644 --- a/src/StoreView.js +++ b/src/StoreView.js @@ -7,7 +7,7 @@ const StoreView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(storeViewRef.current); nativeAdView.current?.setNativeProps({ store: handle, diff --git a/src/TaglineView.js b/src/TaglineView.js index fe217d25..f2b362f2 100644 --- a/src/TaglineView.js +++ b/src/TaglineView.js @@ -7,7 +7,7 @@ const TaglineView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - if (Platform.OS === "android") return; + let handle = findNodeHandle(taglineRef.current); nativeAdView.current?.setNativeProps({ tagline: handle, From 9edffea7635d638553a6572f336802dc0c0b97f8 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:01:18 +0500 Subject: [PATCH 04/13] remove nativeID prop --- src/AdvertiserView.js | 7 +++++-- src/CallToActionView.js | 2 -- src/HeadlineView.js | 2 -- src/IconView.js | 2 -- src/ImageView.js | 2 -- src/PriceView.js | 8 +------- src/StarRatingView.js | 2 -- src/StoreView.js | 8 +------- src/TaglineView.js | 8 +------- 9 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/AdvertiserView.js b/src/AdvertiserView.js index 4a20b291..791a395e 100644 --- a/src/AdvertiserView.js +++ b/src/AdvertiserView.js @@ -7,7 +7,6 @@ const AdvertiserView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(advertiserRef.current); nativeAdView.current?.setNativeProps({ advertiser: handle, @@ -16,7 +15,11 @@ const AdvertiserView = (props) => { return ( - {nativeAd ? props.allCaps? nativeAd.advertiser?.toUpperCase() : nativeAd.advertiser : null} + {nativeAd + ? props.allCaps + ? nativeAd.advertiser?.toUpperCase() + : nativeAd.advertiser + : null} ); }; diff --git a/src/CallToActionView.js b/src/CallToActionView.js index 8e25bb77..2eac2de1 100644 --- a/src/CallToActionView.js +++ b/src/CallToActionView.js @@ -8,7 +8,6 @@ const CallToActionView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(callToActionRef.current); nativeAdView.current?.setNativeProps({ callToAction: handle, @@ -17,7 +16,6 @@ const CallToActionView = (props) => { return ( { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(headlineRef.current); nativeAdView.current?.setNativeProps({ headline: handle, @@ -18,7 +17,6 @@ const HeadlineView = (props) => { return ( diff --git a/src/IconView.js b/src/IconView.js index 4029f74c..8e37d84d 100644 --- a/src/IconView.js +++ b/src/IconView.js @@ -8,7 +8,6 @@ const IconView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(iconViewRef.current); nativeAdView.current?.setNativeProps({ icon: handle, @@ -21,7 +20,6 @@ const IconView = (props) => { resizeMode="cover" ref={iconViewRef} onLayout={_onLayout} - nativeID="adIconView" source={{ uri: nativeAd.icon }} /> ) : null; diff --git a/src/ImageView.js b/src/ImageView.js index 1b3144b2..51b7acb5 100644 --- a/src/ImageView.js +++ b/src/ImageView.js @@ -8,7 +8,6 @@ const ImageView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(imageViewRef.current); nativeAdView.current?.setNativeProps({ image: handle, @@ -20,7 +19,6 @@ const ImageView = (props) => { {...props} ref={imageViewRef} onLayout={_onLayout} - nativeID="adImageView" source={{ uri: nativeAd.images[0] }} /> ) : null; diff --git a/src/PriceView.js b/src/PriceView.js index 424c634f..61f747ce 100644 --- a/src/PriceView.js +++ b/src/PriceView.js @@ -8,19 +8,13 @@ const PriceView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(priceViewRef.current); nativeAdView.current?.setNativeProps({ price: handle, }); }; return ( - + {nativeAd ? nativeAd.price : null} ); diff --git a/src/StarRatingView.js b/src/StarRatingView.js index ef60d26e..da6794e9 100644 --- a/src/StarRatingView.js +++ b/src/StarRatingView.js @@ -8,7 +8,6 @@ const StarRatingView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(starRatingRef.current); nativeAdView.current?.setNativeProps({ starrating: handle, @@ -19,7 +18,6 @@ const StarRatingView = (props) => { diff --git a/src/StoreView.js b/src/StoreView.js index 8e0160f7..4e1f1cc5 100644 --- a/src/StoreView.js +++ b/src/StoreView.js @@ -7,7 +7,6 @@ const StoreView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(storeViewRef.current); nativeAdView.current?.setNativeProps({ store: handle, @@ -15,12 +14,7 @@ const StoreView = (props) => { }; return ( - + {nativeAd ? nativeAd.store : null} ); diff --git a/src/TaglineView.js b/src/TaglineView.js index f2b362f2..e7ef82d6 100644 --- a/src/TaglineView.js +++ b/src/TaglineView.js @@ -7,7 +7,6 @@ const TaglineView = (props) => { const { nativeAd, setNativeAd } = useContext(NativeAdContext); const _onLayout = () => { - let handle = findNodeHandle(taglineRef.current); nativeAdView.current?.setNativeProps({ tagline: handle, @@ -15,12 +14,7 @@ const TaglineView = (props) => { }; return ( - + {nativeAd ? nativeAd.tagline : null} ); From 579e3ab1de6e9f040e186d2309bd56556d9dc52a Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:03:16 +0500 Subject: [PATCH 05/13] add allCaps prop to CallToAction View --- src/CallToActionView.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CallToActionView.js b/src/CallToActionView.js index 2eac2de1..343e34e6 100644 --- a/src/CallToActionView.js +++ b/src/CallToActionView.js @@ -32,7 +32,11 @@ const CallToActionView = (props) => { ]} > - {nativeAd ? nativeAd.callToAction : null} + {nativeAd + ? props.allCaps + ? nativeAd.callToAction?.toUpperCase() + : nativeAd.callToAction + : null} ); From 99817da67c885142c89ae38760b3cf236f317ebd Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:03:24 +0500 Subject: [PATCH 06/13] fix .ts definations --- index.d.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1088f740..fa8af3cf 100644 --- a/index.d.ts +++ b/index.d.ts @@ -105,14 +105,11 @@ type SimpleViewProps = { type NestedTextProps = { style?: ViewStyle; textStyle?: TextStyle; -} - -type AdBadgeProps = { - style?: ViewStyle; - textStyle?: TextStyle; allCaps?:boolean } + + declare module "react-native-admob-native-ads" { /** From 54b404a717d3512cca60e3cdd224be42d49062ff Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:07:42 +0500 Subject: [PATCH 07/13] update README.md --- README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ec9f5c71..20aa302d 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,6 @@ src="https://i.imgur.com/yX5GKhN.png" /> -

💫 Features

@@ -265,8 +264,8 @@ Setting this to true will load a placeholder ad (Not from Admob server) incase y Time in ms after which a new ad should be requested from the server. -| Type | Required | Default | Platform | -| -------- | -------- | -------- | -------- | +| Type | Required | Default | Platform | +| -------- | -------- | ------------------- | -------- | | `number` | no | 60000 ms (1 minute) | All | # @@ -308,7 +307,8 @@ User impression has been recorded User has clicked on the ad. ## Children Views -The children views render different data recieved in the Ad from the server. All the values etc are assigned automatically, all you need to do is style the according to your design. + +The children views render different data recieved in the Ad from the server. All the values etc are assigned automatically, all you need to do is style the according to your design. **Note:** Do not set `nativeID` and `onLayout` prop on any of the Children views as these are used to register the views on Native iOS and Android. @@ -506,11 +506,60 @@ import { MediaView } from "react-native-admob-native-ads"; }} />; ``` +### props + +#### `style:ViewStyle` + +Style the outer `MediaView` Component. + +## CallToActionView + +Renders a CallToAction Button + +```jsx +import { CallToActionView } from "react-native-admob-native-ads"; + +; +``` +### props + +#### `allCaps` + +| Type | Required | Platform | +| --------- | -------- | -------- | +| `boolean` | no | All | + +Whether all text should be in capital letters ### props -`style:ViewStyle` -style your media view. +#### `style:ViewStyle` + +Style the outer `View` Component. + +#### `textStyle:TextStyle` + +Style the inner `Text` Component + +#### `allCaps` + +| Type | Required | Platform | +| --------- | -------- | -------- | +| `boolean` | no | All | + +Whether all text should be in capital letters + ## Contact & Support From a9fda7a06a536e0e4808800da7e4f2ba05f9858f Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:09:22 +0500 Subject: [PATCH 08/13] register views with _nativeID --- .../nativeads/RNAdMobNativeViewManager.java | 98 ++++++++++++++++++- 1 file changed, 95 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java index 4d135f4b..3a4597a8 100755 --- a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java +++ b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNAdMobNativeViewManager.java @@ -10,6 +10,7 @@ import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.RequestConfiguration; @@ -39,6 +40,16 @@ public class RNAdMobNativeViewManager extends ViewGroupManager Date: Tue, 21 Apr 2020 11:09:30 +0500 Subject: [PATCH 09/13] remove attachView func --- .../rnadmob/nativeads/RNNativeAdWrapper.java | 95 +++---------------- 1 file changed, 15 insertions(+), 80 deletions(-) diff --git a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java index d545930c..985fe72d 100644 --- a/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java +++ b/android/src/main/java/com/ammarahmed/rnadmob/nativeads/RNNativeAdWrapper.java @@ -117,18 +117,6 @@ private void setNativeAdToJS(UnifiedNativeAd nativeAd) { sendEvent(RNAdMobNativeViewManager.EVENT_UNIFIED_NATIVE_AD_LOADED, args); - attachViews(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - - attachViews(); - } - },500); - - nativeAdView.requestLayout(); - - } catch (Exception e) { @@ -143,67 +131,7 @@ public void run() { }, adRefreshInterval); } } - - public void removeHandler() { - if (handler != null) { - handler.removeCallbacks(null); - handler = null; - } - - } - - - - - public void attachViews() { - - try { - - if (nativeAdView != null) { - - View advertiser = ReactFindViewUtil.findView(nativeAdView, adAdvertiser); - if (advertiser != null) - nativeAdView.setAdvertiserView(advertiser); - - View headline = ReactFindViewUtil.findView(nativeAdView, adHeadline); - if (headline != null) - nativeAdView.setHeadlineView(headline); - - View tagline = ReactFindViewUtil.findView(nativeAdView, adTagline); - if (tagline != null) - nativeAdView.setBodyView(tagline); - - View store = ReactFindViewUtil.findView(nativeAdView, adStoreView); - if (store != null) - nativeAdView.setStoreView(store); - - View iconv = ReactFindViewUtil.findView(nativeAdView, adIconView); - if (iconv != null) - nativeAdView.setIconView(iconv); - - View image = ReactFindViewUtil.findView(nativeAdView, adImageView); - if (image != null) - - nativeAdView.setImageView(image); - - View callToAction = ReactFindViewUtil.findView(nativeAdView, adCallToAction); - if (callToAction != null) - nativeAdView.setCallToActionView(callToAction); - - View adPriceView = ReactFindViewUtil.findView(nativeAdView, adPriceViews); - if (adPriceView != null) - nativeAdView.setCallToActionView(adPriceView); - - View starRating = ReactFindViewUtil.findView(nativeAdView, adStarRating); - if (starRating != null) - nativeAdView.setStarRatingView(starRating); - } - - } catch (Exception e) { - - } - - } + private void sendEvent(String name, @Nullable WritableMap event) { @@ -304,7 +232,6 @@ public void run() { try { - AdLoader.Builder builder = new AdLoader.Builder(mContext, admobAdUnitId); builder.forUnifiedNativeAd(onUnifiedNativeAdLoadedListener); @@ -327,23 +254,22 @@ public void run() { } } - },loadWithDelay); - + }, loadWithDelay); } - public void setLoadWithDelay(int delay) { + public void setLoadWithDelay(int delay) { loadWithDelay = delay; } - + public void addNewView(View child, int index) { try { - nativeAdView.addView(child, index); - nativeAdView.requestLayout(); + nativeAdView.addView(child, index); + nativeAdView.requestLayout(); } catch (Exception e) { } @@ -366,4 +292,13 @@ public void requestLayout() { } + public void removeHandler() { + if (handler != null) { + handler.removeCallbacks(null); + handler = null; + } + + } + + } From dd6d11c2902a83dda649614a2d77e013223bf4a2 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:09:51 +0500 Subject: [PATCH 10/13] update version to 0.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f57971b3..fb47c2cb 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-admob-native-ads", - "version": "0.2.0", + "version": "0.2.1", "description": "A simple and robust library for creating & displaying Admob Native Ads in your React Native App using Native Views", "author": "Ammar Ahmed ", "main": "index.js", From ab5f52e28fb204a8992e376343947d25f1b61ac4 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:11:07 +0500 Subject: [PATCH 11/13] remove unused imports --- src/AdvertiserView.js | 4 ++-- src/CallToActionView.js | 2 +- src/HeadlineView.js | 4 ++-- src/IconView.js | 4 ++-- src/ImageView.js | 4 ++-- src/MediaView.js | 2 +- src/PriceView.js | 4 ++-- src/StarRatingView.js | 6 +++--- src/StoreView.js | 4 ++-- src/TaglineView.js | 4 ++-- src/index.js | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/AdvertiserView.js b/src/AdvertiserView.js index 791a395e..b997635b 100644 --- a/src/AdvertiserView.js +++ b/src/AdvertiserView.js @@ -1,5 +1,5 @@ -import React, { useContext, createRef } from "react"; -import { Text, Platform, findNodeHandle } from "react-native"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle, Text } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; const advertiserRef = createRef(); diff --git a/src/CallToActionView.js b/src/CallToActionView.js index 343e34e6..cee24ffe 100644 --- a/src/CallToActionView.js +++ b/src/CallToActionView.js @@ -1,5 +1,5 @@ import React, { createRef, useContext } from "react"; -import { findNodeHandle, Platform, Text } from "react-native"; +import { findNodeHandle, Text } from "react-native"; import { RawButton } from "react-native-gesture-handler"; import { NativeAdContext, nativeAdView } from "./context"; diff --git a/src/HeadlineView.js b/src/HeadlineView.js index 3dfdb40a..5ecddc8a 100644 --- a/src/HeadlineView.js +++ b/src/HeadlineView.js @@ -1,5 +1,5 @@ -import React, { useContext, createRef } from "react"; -import { Text, Platform, findNodeHandle } from "react-native"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle, Text } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; const headlineRef = createRef(); diff --git a/src/IconView.js b/src/IconView.js index 8e37d84d..64ba7a28 100644 --- a/src/IconView.js +++ b/src/IconView.js @@ -1,5 +1,5 @@ -import React, { useContext, createRef } from "react"; -import { Image, findNodeHandle, Platform } from "react-native"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle, Image } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; const iconViewRef = createRef(); diff --git a/src/ImageView.js b/src/ImageView.js index 51b7acb5..43f9160c 100644 --- a/src/ImageView.js +++ b/src/ImageView.js @@ -1,5 +1,5 @@ -import React, { useContext, createRef } from "react"; -import { Image, findNodeHandle, Platform } from "react-native"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle, Image } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; const imageViewRef = createRef(); diff --git a/src/MediaView.js b/src/MediaView.js index 3645e7ac..16556c39 100644 --- a/src/MediaView.js +++ b/src/MediaView.js @@ -1,5 +1,5 @@ import React, { createRef } from "react"; -import { requireNativeComponent, findNodeHandle } from "react-native"; +import { findNodeHandle, requireNativeComponent } from "react-native"; import { nativeAdView } from "./context"; const adMediaView = createRef(); diff --git a/src/PriceView.js b/src/PriceView.js index 61f747ce..49ddada6 100644 --- a/src/PriceView.js +++ b/src/PriceView.js @@ -1,5 +1,5 @@ -import React, { useContext, createRef } from "react"; -import { Text, Platform, findNodeHandle } from "react-native"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle, Text } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; const priceViewRef = createRef(); diff --git a/src/StarRatingView.js b/src/StarRatingView.js index da6794e9..c651bc89 100644 --- a/src/StarRatingView.js +++ b/src/StarRatingView.js @@ -1,7 +1,7 @@ -import React, { useContext, createRef } from "react"; -import { Platform, findNodeHandle } from "react-native"; -import { NativeAdContext, nativeAdView } from "./context"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle } from "react-native"; import StarRating from "react-native-star-rating"; +import { NativeAdContext, nativeAdView } from "./context"; const starRatingRef = createRef(); const StarRatingView = (props) => { diff --git a/src/StoreView.js b/src/StoreView.js index 4e1f1cc5..ea6bf723 100644 --- a/src/StoreView.js +++ b/src/StoreView.js @@ -1,5 +1,5 @@ -import React, { useContext, createRef } from "react"; -import { Text, findNodeHandle, Platform } from "react-native"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle, Text } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; const storeViewRef = createRef(); diff --git a/src/TaglineView.js b/src/TaglineView.js index e7ef82d6..b9948688 100644 --- a/src/TaglineView.js +++ b/src/TaglineView.js @@ -1,5 +1,5 @@ -import React, { useContext, createRef } from "react"; -import { Text, Platform, findNodeHandle } from "react-native"; +import React, { createRef, useContext } from "react"; +import { findNodeHandle, Text } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; const taglineRef = createRef(); diff --git a/src/index.js b/src/index.js index d81ecb3c..a7c4fd93 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ -import React, { useState, useEffect } from "react"; -import { requireNativeComponent, Platform } from "react-native"; +import React, { useEffect, useState } from "react"; +import { Platform, requireNativeComponent } from "react-native"; import { NativeAdContext, nativeAdView } from "./context"; import Wrapper from "./Wrapper"; From 797917ded28001c0aed6bc9b032dc6906b03e129 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:11:37 +0500 Subject: [PATCH 12/13] format index.d.ts --- index.d.ts | 55 +++++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/index.d.ts b/index.d.ts index fa8af3cf..7df7c4ad 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,9 +1,7 @@ import { ViewStyle, TextProps, ImageProps, TextStyle } from "react-native"; import { StarRatingProps } from "react-native-star-rating"; - type NativeAd = { - /** * Title of the native ad. */ @@ -42,15 +40,13 @@ type NativeAd = { */ rating: number; - /** * if ad has video content or not. */ video: boolean; -} +}; type NativeAdViewProps = { - /** * When you are designing your ad, placeholders for the ad will be loaded * so you can easily design, because for each type of ad recieved from the server, not all the info is available. @@ -58,7 +54,6 @@ type NativeAdViewProps = { enableTestMode?: boolean; - style?: ViewStyle; /** @@ -74,17 +69,15 @@ type NativeAdViewProps = { */ refreshInterval?: number; - - /** + /** * Time in milliseconds to delay ad loading. Default is 1000ms. * This is usually done so that ad request is done after the views are attached. */ delayAdLoading?: number; - /** - * Set testdevices for the ad. + * Set testdevices for the ad. */ testDevices?: Array; onAdOpened?: Function; @@ -99,38 +92,35 @@ type NativeAdViewProps = { type SimpleViewProps = { style?: ViewStyle; - }; type NestedTextProps = { style?: ViewStyle; textStyle?: TextStyle; - allCaps?:boolean -} - - + allCaps?: boolean; +}; declare module "react-native-admob-native-ads" { - /** - * + * * Wrapper for the UnifiedNativeAdView from Google Ads SDK. All your views should be * wrapped inside this view always. - * + * */ - export default function NativeAdView(props: NativeAdViewProps): React.FunctionComponent; - + export default function NativeAdView( + props: NativeAdViewProps + ): React.FunctionComponent; /** * Ad Badge shows the {ad} badge on top of the ad telling the user that this is an AD. - * + * */ export function AdBadge(props: NestedTextProps): React.FunctionComponent; /** - * The title of the native ad recieved from server is renderd here. + * The title of the native ad recieved from server is renderd here. * You dont need to pass any values to it. It will automatically get the title from * context and load it. * You should on style it as you want. @@ -138,12 +128,12 @@ declare module "react-native-admob-native-ads" { export function HeadlineView(props: TextProps): React.FunctionComponent; /** - * * The description of the native ad recieved from server is renderd here. + * * The description of the native ad recieved from server is renderd here. */ export function TaglineView(props: TextProps): React.FunctionComponent; /** - * * The adveriser name of the native ad recieved from server is renderd here. + * * The adveriser name of the native ad recieved from server is renderd here. */ export function AdvertiserView(props: TextProps): React.FunctionComponent; /** @@ -153,7 +143,7 @@ declare module "react-native-admob-native-ads" { /** * Many times, the ad recieved will be from the Google Playstore or AppStore for iOS. - * In that case, you can show the store name using this view. + * In that case, you can show the store name using this view. */ export function StoreView(props: TextProps): React.FunctionComponent; @@ -172,19 +162,20 @@ declare module "react-native-admob-native-ads" { export function MediaView(props: SimpleViewProps): React.FunctionComponent; /** - * A simple button to open the adveriser website or store page etc. It is a simple - * Text Component wrapped in a View. I dont know how to make the Touchables or Buttons + * A simple button to open the adveriser website or store page etc. It is a simple + * Text Component wrapped in a View. I dont know how to make the Touchables or Buttons * work since they have no effect. Native side does not recieve the call hence simple * Text Component is used to receive the clicks. */ - export function CallToActionView(props: NestedTextProps): React.FunctionComponent; + export function CallToActionView( + props: NestedTextProps + ): React.FunctionComponent; /** * A Star Rating View to show the star rating for the app ads that you might recieve from * the server. */ - export function StarRatingView(props: StarRatingProps): React.FunctionComponent; - - - + export function StarRatingView( + props: StarRatingProps + ): React.FunctionComponent; } From eb66a98fea0626a1fd0ba6545f3397482f0c19e8 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 21 Apr 2020 11:24:31 +0500 Subject: [PATCH 13/13] add delayAdLoad prop on ios --- ios/RNGADNativeView.h | 2 +- ios/RNGADNativeView.m | 18 ++++++++++-------- ios/RNGADNativeViewManager.m | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ios/RNGADNativeView.h b/ios/RNGADNativeView.h index 41b4b265..32125463 100755 --- a/ios/RNGADNativeView.h +++ b/ios/RNGADNativeView.h @@ -12,7 +12,7 @@ @property (nonatomic, copy) NSArray *testDevices; @property (nonatomic, copy) NSNumber *refreshInterval; @property (nonatomic, copy) NSString *adUnitID; - +@property (nonatomic, copy) NSNumber *delayAdLoad; @property (nonatomic, copy) NSNumber *headline; @property (nonatomic, copy) NSNumber *tagline; @property (nonatomic, copy) NSNumber *advertiser; diff --git a/ios/RNGADNativeView.m b/ios/RNGADNativeView.m index 7bbe1212..d19e5c32 100755 --- a/ios/RNGADNativeView.m +++ b/ios/RNGADNativeView.m @@ -20,9 +20,12 @@ @implementation RNGADNativeView : GADUnifiedNativeAdView NSString *adUnitId; NSNumber *refreshingInterval; +NSNumber *delay; + - (instancetype)initWithBridge:(RCTBridge *)_bridge { + delay = @1000; refreshingInterval = @60000; if (self = [super init]) { bridge = _bridge; @@ -30,6 +33,11 @@ - (instancetype)initWithBridge:(RCTBridge *)_bridge return self; } +- (void)setDelayAdLoad:(NSNumber *)delayAdLoad +{ + delay = delayAdLoad; +} + - (void)setTestDevices:(NSArray *)testDevices { _testDevices = RNAdMobProcessTestDevices(testDevices, kDFPSimulatorID); @@ -253,6 +261,7 @@ - (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(GADRequest - (void)adLoader:(GADAdLoader *)adLoader didReceiveUnifiedNativeAd:(GADUnifiedNativeAd *)nativeAd { + dispatch_after((int64_t)((delay.intValue/1000) * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){ if (self.onAdLoaded) { self.onAdLoaded(@{}); @@ -271,16 +280,13 @@ - (void)adLoader:(GADAdLoader *)adLoader didReceiveUnifiedNativeAd:(GADUnifiedNa [dic setValue:nativeAd.price forKey:@"price"]; [dic setValue:nativeAd.callToAction forKey:@"callToAction"]; - if (nativeAd.mediaContent.hasVideoContent) { [dic setValue:@YES forKey:@"video"]; }else { [dic setValue:@NO forKey:@"video"]; } - NSMutableArray *images = [NSMutableArray array]; - GADNativeAdImage *image = [nativeAd.images objectAtIndex:0]; NSString *url = [image.imageURL absoluteString]; [images addObject:url]; @@ -298,11 +304,7 @@ - (void)adLoader:(GADAdLoader *)adLoader didReceiveUnifiedNativeAd:(GADUnifiedNa dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self loadAd:adUnitId]; }); - - - - - + }); } diff --git a/ios/RNGADNativeViewManager.m b/ios/RNGADNativeViewManager.m index d2d14620..cd65dc83 100755 --- a/ios/RNGADNativeViewManager.m +++ b/ios/RNGADNativeViewManager.m @@ -33,7 +33,7 @@ -(UIView *)view RCT_EXPORT_VIEW_PROPERTY(testDevices, NSArray) RCT_EXPORT_VIEW_PROPERTY(refreshInterval, NSNumber) RCT_EXPORT_VIEW_PROPERTY(adUnitID, NSString) - +RCT_EXPORT_VIEW_PROPERTY(delayAdLoad, NSNumber) RCT_EXPORT_VIEW_PROPERTY(headline, NSNumber) RCT_EXPORT_VIEW_PROPERTY(tagline, NSNumber) RCT_EXPORT_VIEW_PROPERTY(advertiser, NSNumber)