ammarahm-ed/react-native-admob-native-ads

NativeAdView is not loading properly.

CygnetUrvashi opened this issue · 1 comments

I am using NativeAdView in react-native my ad component . And its not reflecting / removed after some time.This is a random issue which i am facing . below is my code.

useEffect(() => {
if (repositoryName && repositoryName?.length > 0) {
loadAd();
} else {
debounceForFunc(() => {
if (blankFeedImages.length > 0) {
setDummyUri(blankFeedImages[Math.floor(Math.random() * blankFeedImages.length)]);
}
}, 3000);
}
}, [repositoryName]);

return (
<ImageBackground
source={{ uri: uri || dummyUri }}
style={{
width: Dimensions.get("window").width,
height,
backgroundColor: colors.black,
}}
onLoad={() => {
if (dummyUri) {
setShowLoader(false);
}
}}
onError={() => setShowLoader(false)}
blurRadius={uri ? 15 : 0}
>
<View style={{ height }}>
{repositoryName && currentRepository?.current ? (
<NativeAdView
ref={nativeAdViewRef as MutableRefObject}
enableTestMode={env === "dev" || env === "qa"}
repository={currentRepository.current || undefined}
style={styles.container}
onNativeAdLoaded={(ad: NativeAd) => {
setShowLoader(false);
appLogger.warn("Ad Loaded", ad);
setUri(ad?.images?.[0]?.url);
setDummyUri(undefined);
currentAdJSON.current = ad;
setLoaded(true);
trackEvent({ eventName: Events.nativeAdLoaded, eventData: ad });
}}
onAdImpression={() => {
trackEvent({
eventName: Events.nativeAdImpression,
eventData: currentAdJSON,
});
}}
onAdFailedToLoad={(error: any) => {
setShowLoader(false);
setUri(null);
appLogger.error("Failed to load ad", error);
trackEvent({
eventName: Events.nativeAdError,
eventData: error,
});
}}
>
<View
style={{
height: height,
width: Dimensions.get("window").width,
}}
>
{currentItemId === post.id ? (
<ImageView
style={{
width: Dimensions.get("window").width,
height: "40%",
marginTop: 150,
}}
/>
) : (
<View
style={{
width: Dimensions.get("window").width,
height: "70%",
}}
/>
)}
<View
style={{
width: Dimensions.get("window").width,
alignItems: "center",
}}
>

<View style={{ marginBottom: 5 }}>



{uri ? (

) : null}



{showLoader ? (
<ActivityIndicator
size={"small"}
style={{ position: "absolute", top: 0, bottom: 0, left: 0, right: 0 }}
color={colors.blue}
/>
) : null}


) : null}

    <AdBadge style={styles.adTextView} textStyle={styles.adTextStyle} />
  </View>
</ImageBackground>

);

Note : Its working fine with "ImageView" . But i cant use it as i want serve video ads as well. Can you please help me out?

"react-native": "0.71.13",
"react-native-admob-native-ads": "0.6.6",