Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeAdView is not loading properly. #365

Open
CygnetUrvashi opened this issue Apr 23, 2024 · 1 comment
Open

NativeAdView is not loading properly. #365

CygnetUrvashi opened this issue Apr 23, 2024 · 1 comment

Comments

@CygnetUrvashi
Copy link

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",

@misterjoshm
Copy link

This is happening for my app too. It will load ads for about 3 or 4 hours fine, but then it just stops working after that. Every time I try to load ads after it stops working, it doesn't do anything. It doesn't crash but the advertisement area goes blank.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants