Skip to content

Commit 2315d01

Browse files
mithun50claude
andcommitted
Uncomment ads implementation for production build
- Restore AdMob initialization code - Restore interstitial ad hooks (useInterstitialAd, useExitAd) - Restore navigation state change handler for tab ads - Re-enable MobileAds import - Ready for production APK build with ads enabled 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 48fa65b commit 2315d01

1 file changed

Lines changed: 47 additions & 50 deletions

File tree

App.tsx

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import * as Notifications from 'expo-notifications';
1111
import { db } from './firebase.config';
1212
import { doc, setDoc } from 'firebase/firestore';
1313
import AsyncStorage from '@react-native-async-storage/async-storage';
14-
// COMMENTED OUT FOR EXPO GO TESTING
15-
// import { useInterstitialAd } from './hooks/useInterstitialAd';
16-
// import { useExitAd } from './hooks/useExitAd';
17-
// import MobileAds from 'react-native-google-mobile-ads';
14+
import { useInterstitialAd } from './hooks/useInterstitialAd';
15+
import { useExitAd } from './hooks/useExitAd';
16+
import MobileAds from 'react-native-google-mobile-ads';
1817

1918
// Create context for notifications navigation
2019
const NotificationsContext = createContext<{
@@ -163,33 +162,32 @@ const AppContent = () => {
163162
checkFirstLaunch();
164163
}, []);
165164

166-
// COMMENTED OUT FOR EXPO GO TESTING
167165
// Track AdMob initialization state
168-
// const [adMobInitialized, setAdMobInitialized] = useState(false);
166+
const [adMobInitialized, setAdMobInitialized] = useState(false);
169167

170168
// Initialize Google Mobile Ads
171-
// useEffect(() => {
172-
// console.log('🚀 Starting AdMob initialization...');
173-
// MobileAds()
174-
// .initialize()
175-
// .then(adapterStatuses => {
176-
// console.log('✅ AdMob initialized successfully:', adapterStatuses);
177-
// setAdMobInitialized(true);
178-
// })
179-
// .catch(error => {
180-
// console.error('❌ AdMob initialization error:', error);
181-
// console.error('Error details:', JSON.stringify(error));
182-
// // Still set to true to allow ads to attempt loading
183-
// setAdMobInitialized(true);
184-
// });
185-
// }, []);
169+
useEffect(() => {
170+
console.log('🚀 Starting AdMob initialization...');
171+
MobileAds()
172+
.initialize()
173+
.then(adapterStatuses => {
174+
console.log('✅ AdMob initialized successfully:', adapterStatuses);
175+
setAdMobInitialized(true);
176+
})
177+
.catch(error => {
178+
console.error('❌ AdMob initialization error:', error);
179+
console.error('Error details:', JSON.stringify(error));
180+
// Still set to true to allow ads to attempt loading
181+
setAdMobInitialized(true);
182+
});
183+
}, []);
186184

187185
// Interstitial ad hook for tab navigation - ONLY AFTER initialization
188-
// const { showAd, isLoaded } = useInterstitialAd();
186+
const { showAd, isLoaded } = useInterstitialAd();
189187

190188
// Exit ad hook - shows rewarded interstitial when user presses back button
191189
// ONLY enable after AdMob is initialized
192-
// useExitAd({ enabled: adMobInitialized });
190+
useExitAd({ enabled: adMobInitialized });
193191

194192
useEffect(() => {
195193
registerForPushNotificationsAsync().then(token => {
@@ -226,33 +224,32 @@ const AppContent = () => {
226224
};
227225
}, []);
228226

229-
// COMMENTED OUT FOR EXPO GO TESTING
230227
// Handle navigation state changes to show interstitial ads
231-
// const handleNavigationStateChange = (state: any) => {
232-
// if (!state) return;
233-
234-
// const currentRoute = state.routes[state.index]?.name;
235-
236-
// // Log navigation changes
237-
// if (currentRoute && currentRoute !== previousRoute) {
238-
// console.log(`📱 Tab changed: ${previousRoute} → ${currentRoute}`);
239-
// console.log('Ad state - isLoaded:', isLoaded, 'adMobInitialized:', adMobInitialized);
240-
// }
241-
242-
// // Show interstitial ad occasionally when switching tabs (not every time to avoid annoyance)
243-
// // Show ad 30% of the time when changing tabs
244-
// const randomValue = Math.random();
245-
// if (currentRoute && currentRoute !== previousRoute && isLoaded && randomValue < 0.3) {
246-
// console.log(`🎲 Random value: ${randomValue.toFixed(2)} < 0.3 - Showing interstitial ad`);
247-
// showAd();
248-
// } else if (currentRoute && currentRoute !== previousRoute && isLoaded) {
249-
// console.log(`🎲 Random value: ${randomValue.toFixed(2)} >= 0.3 - Skipping ad this time`);
250-
// } else if (currentRoute && currentRoute !== previousRoute && !isLoaded) {
251-
// console.log('⚠️ Tab changed but ad not loaded yet');
252-
// }
253-
254-
// setPreviousRoute(currentRoute);
255-
// };
228+
const handleNavigationStateChange = (state: any) => {
229+
if (!state) return;
230+
231+
const currentRoute = state.routes[state.index]?.name;
232+
233+
// Log navigation changes
234+
if (currentRoute && currentRoute !== previousRoute) {
235+
console.log(`📱 Tab changed: ${previousRoute}${currentRoute}`);
236+
console.log('Ad state - isLoaded:', isLoaded, 'adMobInitialized:', adMobInitialized);
237+
}
238+
239+
// Show interstitial ad occasionally when switching tabs (not every time to avoid annoyance)
240+
// Show ad 30% of the time when changing tabs
241+
const randomValue = Math.random();
242+
if (currentRoute && currentRoute !== previousRoute && isLoaded && randomValue < 0.3) {
243+
console.log(`🎲 Random value: ${randomValue.toFixed(2)} < 0.3 - Showing interstitial ad`);
244+
showAd();
245+
} else if (currentRoute && currentRoute !== previousRoute && isLoaded) {
246+
console.log(`🎲 Random value: ${randomValue.toFixed(2)} >= 0.3 - Skipping ad this time`);
247+
} else if (currentRoute && currentRoute !== previousRoute && !isLoaded) {
248+
console.log('⚠️ Tab changed but ad not loaded yet');
249+
}
250+
251+
setPreviousRoute(currentRoute);
252+
};
256253

257254
return (
258255
<NotificationsContext.Provider value={{ openNotifications: () => setShowNotificationsScreen(true) }}>
@@ -278,7 +275,7 @@ const AppContent = () => {
278275
<StatusBar style="dark" />
279276
</SafeAreaView>
280277
) : (
281-
<NavigationContainer>
278+
<NavigationContainer onStateChange={handleNavigationStateChange}>
282279
<SafeAreaView style={{ flex: 1, backgroundColor: '#FFFFFF' }}>
283280

284281
<Tab.Navigator

0 commit comments

Comments
 (0)