The App is working fine even when I disconnect the internet, but when I disconnect the internet app pages are not working where I implemented google ads. the app pages show blank pages not even load the app page data. I know ads will not appear when I disconnect the internet but the problem is I am also not getting the page data, it shows blank page. how can I solve this issue? thank you in advance for your support.
import React, { useState, useEffect } from "react";
import { View, Button, Text, TouchableOpacity } from 'react-native'
import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';
const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-3940256099942544/1033173712';
const interstitial = InterstitialAd.createForAdRequest(adUnitId, {
requestNonPersonalizedAdsOnly: true,
keywords: ['fashion', 'clothing'],
});
const Test = ({ navigation }) => {
const [loaded, setLoaded] = useState(false);
useEffect(() => {
const unsubscribe = interstitial.addAdEventListener(AdEventType.LOADED, () => {
setLoaded(true);
interstitial.show()
});
interstitial.load();
return unsubscribe;
}, []);
if (!loaded) {
return null;
}
return (
<View>
<Text>Hello World</Text>
</View>
)
}
export default Test
CodePudding user response:
That's because you have this in your code
if (!loaded) {
return null;
}
It returns null
when your ad is not loaded so it shows blank screen remove that and you'll have your screen