88 ScrollView ,
99 Alert ,
1010 ActivityIndicator ,
11+ Switch ,
1112} from 'react-native' ;
1213import { networkLogger , NetworkLoggerOverlay } from 'react-native-api-debugger' ;
1314import { GestureHandlerRootView } from 'react-native-gesture-handler' ;
@@ -72,8 +73,15 @@ const ButtonComponent: React.FC<ButtonComponentProps> = ({
7273
7374const App : React . FC = ( ) => {
7475 const [ loading , setLoading ] = useState < LoadingState > ( { } ) ;
76+ const [ showHeaders , setShowHeaders ] = useState < boolean > ( false ) ;
7577
7678 useEffect ( ( ) => {
79+ networkLogger . configure ( {
80+ maxLogs : 50 ,
81+ ignoredUrls : [ '/health' , '/ping' ] ,
82+ ignoredDomains : [ 'analytics.example.com' ] ,
83+ slowRequestThreshold : 2000 ,
84+ } ) ;
7785 networkLogger . setupInterceptor ( ) ;
7886 } , [ ] ) ;
7987
@@ -214,7 +222,7 @@ const App: React.FC = () => {
214222 ) ;
215223 } ;
216224
217- // Test Error Request
225+ // Test Error Request (404)
218226 const handleErrorRequest = async ( ) : Promise < void > => {
219227 await makeAPIRequest (
220228 'https://jsonplaceholder.typicode.com/posts/999999' ,
@@ -229,6 +237,52 @@ const App: React.FC = () => {
229237 ) ;
230238 } ;
231239
240+ // Test Server Error (500)
241+ const handleServerError = async ( ) : Promise < void > => {
242+ await makeAPIRequest (
243+ 'https://httpstat.us/500' ,
244+ {
245+ method : 'GET' ,
246+ headers : {
247+ Accept : 'application/json' ,
248+ } ,
249+ } ,
250+ 'serverError' ,
251+ ( ) => 'Unexpected success'
252+ ) ;
253+ } ;
254+
255+ // Test Slow Request
256+ const handleSlowRequest = async ( ) : Promise < void > => {
257+ await makeAPIRequest (
258+ 'https://httpstat.us/200?sleep=3000' ,
259+ {
260+ method : 'GET' ,
261+ headers : {
262+ Accept : 'application/json' ,
263+ } ,
264+ } ,
265+ 'slowRequest' ,
266+ ( ) => 'Slow request completed'
267+ ) ;
268+ } ;
269+
270+ // Test Ignored URL (should not appear in logs)
271+ const handleIgnoredRequest = async ( ) : Promise < void > => {
272+ setButtonLoading ( 'ignoredRequest' , true ) ;
273+ try {
274+ await fetch ( 'https://jsonplaceholder.typicode.com/health' ) ;
275+ Alert . alert (
276+ 'Ignored Request' ,
277+ 'This request should NOT appear in the network logger because "/health" is in the ignored URLs list.'
278+ ) ;
279+ } catch ( error ) {
280+ Alert . alert ( 'Error' , 'Request failed' ) ;
281+ } finally {
282+ setButtonLoading ( 'ignoredRequest' , false ) ;
283+ }
284+ } ;
285+
232286 return (
233287 < GestureHandlerRootView style = { styles . root } >
234288 < SafeAreaView style = { styles . container } >
@@ -280,12 +334,46 @@ const App: React.FC = () => {
280334 < Text style = { styles . sectionTitle } > Error & Edge Cases </ Text >
281335 < View style = { styles . buttonRow } >
282336 < ButtonComponent
283- title = "Test 404 Error "
337+ title = "Test 404"
284338 onPress = { handleErrorRequest }
285339 buttonId = "errorRequest"
286340 color = "#F44336"
287341 loading = { loading . errorRequest }
288342 />
343+ < ButtonComponent
344+ title = "Test 500"
345+ onPress = { handleServerError }
346+ buttonId = "serverError"
347+ color = "#9C27B0"
348+ loading = { loading . serverError }
349+ />
350+ </ View >
351+ < View style = { styles . buttonRow } >
352+ < ButtonComponent
353+ title = "Slow Request"
354+ onPress = { handleSlowRequest }
355+ buttonId = "slowRequest"
356+ color = "#FF5722"
357+ loading = { loading . slowRequest }
358+ />
359+ < ButtonComponent
360+ title = "Ignored URL"
361+ onPress = { handleIgnoredRequest }
362+ buttonId = "ignoredRequest"
363+ color = "#607D8B"
364+ loading = { loading . ignoredRequest }
365+ />
366+ </ View >
367+
368+ < Text style = { styles . sectionTitle } > Display Settings</ Text >
369+ < View style = { styles . settingRow } >
370+ < Text style = { styles . settingLabel } > Show Headers</ Text >
371+ < Switch
372+ value = { showHeaders }
373+ onValueChange = { setShowHeaders }
374+ trackColor = { { false : '#e0e0e0' , true : '#81b0ff' } }
375+ thumbColor = { showHeaders ? '#007AFF' : '#f4f3f4' }
376+ />
289377 </ View >
290378
291379 < View style = { styles . instructions } >
@@ -294,19 +382,41 @@ const App: React.FC = () => {
294382 1. Tap any button to make an API request{ '\n' }
295383 2. Check the floating network logger button{ '\n' }
296384 3. Tap the logger to view request details{ '\n' }
297- 4. Expand requests to see headers & responses { '\n' }
298- 5. Use cURL generation for debugging
385+ 4. Use filter chips (2xx, 4xx, 5xx, Errors) to filter logs{ '\n' }
386+ 5. Search by URL, method, or response body{ '\n' }
387+ 6. Expand requests to see headers & responses { '\n' }
388+ 7. Use cURL generation for debugging
389+ </ Text >
390+ </ View >
391+
392+ < View style = { styles . configInfo } >
393+ < Text style = { styles . configTitle } > ⚙️ Current Config:</ Text >
394+ < Text style = { styles . configText } >
395+ • Max Logs: 50{ '\n' } • Ignored URLs: /health, /ping{ '\n' } • Slow
396+ Request Threshold: 2000ms{ '\n' } • Dev Mode Only: enabled
397+ (default)
398+ </ Text >
399+ </ View >
400+
401+ < View style = { styles . devModeInfo } >
402+ < Text style = { styles . devModeTitle } > 🔒 Production Safety:</ Text >
403+ < Text style = { styles . devModeText } >
404+ The network logger only shows in development builds by default
405+ (__DEV__). This prevents accidental exposure of sensitive API
406+ data in production apps.
299407 </ Text >
300408 </ View >
301409 </ View >
302410 </ ScrollView >
411+ { /* enabled defaults to __DEV__, so it only shows in development builds */ }
303412 < NetworkLoggerOverlay
304413 draggable = { true }
305414 enableDeviceShake = { false }
306415 useCopyToClipboard = { true }
307- showRequestHeader = { false }
308- showResponseHeader = { false }
416+ showRequestHeader = { showHeaders }
417+ showResponseHeader = { showHeaders }
309418 networkLogger = { networkLogger }
419+ // enabled={true} // Uncomment to force enable in production (not recommended)
310420 />
311421 </ SafeAreaView >
312422 </ GestureHandlerRootView >
@@ -400,6 +510,59 @@ const styles = StyleSheet.create({
400510 instructionsText : {
401511 fontSize : 14 ,
402512 color : '#666' ,
513+ lineHeight : 22 ,
514+ } ,
515+ configInfo : {
516+ backgroundColor : '#E3F2FD' ,
517+ padding : 20 ,
518+ borderRadius : 12 ,
519+ marginTop : 16 ,
520+ borderWidth : 1 ,
521+ borderColor : '#BBDEFB' ,
522+ } ,
523+ configTitle : {
524+ fontSize : 16 ,
525+ fontWeight : '600' ,
526+ color : '#1976D2' ,
527+ marginBottom : 10 ,
528+ } ,
529+ configText : {
530+ fontSize : 13 ,
531+ color : '#1565C0' ,
532+ lineHeight : 20 ,
533+ } ,
534+ settingRow : {
535+ flexDirection : 'row' ,
536+ justifyContent : 'space-between' ,
537+ alignItems : 'center' ,
538+ backgroundColor : '#fff' ,
539+ padding : 16 ,
540+ borderRadius : 8 ,
541+ marginBottom : 8 ,
542+ } ,
543+ settingLabel : {
544+ fontSize : 16 ,
545+ color : '#333' ,
546+ fontWeight : '500' ,
547+ } ,
548+ devModeInfo : {
549+ backgroundColor : '#FCE4EC' ,
550+ padding : 20 ,
551+ borderRadius : 12 ,
552+ marginTop : 16 ,
553+ marginBottom : 40 ,
554+ borderWidth : 1 ,
555+ borderColor : '#F8BBD9' ,
556+ } ,
557+ devModeTitle : {
558+ fontSize : 16 ,
559+ fontWeight : '600' ,
560+ color : '#C2185B' ,
561+ marginBottom : 10 ,
562+ } ,
563+ devModeText : {
564+ fontSize : 13 ,
565+ color : '#AD1457' ,
403566 lineHeight : 20 ,
404567 } ,
405568} ) ;
0 commit comments