@@ -2,7 +2,6 @@ import React, { useCallback, useLayoutEffect, useState } from 'react';
22import {
33 StyleSheet ,
44 Button ,
5- SafeAreaView ,
65 View ,
76 Text ,
87 TouchableOpacity ,
@@ -14,11 +13,18 @@ import NetworkLogger, {
1413 startNetworkLogging ,
1514 stopNetworkLogging ,
1615} from 'react-native-network-logger' ;
17- import { getHero , getRates , getUser } from './apolloClient' ;
16+ import { SafeAreaProvider , SafeAreaView } from 'react-native-safe-area-context' ;
17+ import { getTodos } from './apolloClient' ;
1818
1919const formData = new FormData ( ) ;
2020formData . append ( 'test' , 'hello' ) ;
2121
22+ const fetchStatus = async ( status : number , sleepSeconds ?: number ) => {
23+ return fetch ( `https://httpbin.org/status/${ status } ` , {
24+ headers : { 'X-HttpBin-Sleep' : `${ sleepSeconds || 0 } ` } ,
25+ } ) ;
26+ } ;
27+
2228const requests = [
2329 async ( ) =>
2430 fetch (
@@ -35,29 +41,27 @@ const requests = [
3541 method : 'POST' ,
3642 body : formData ,
3743 } ) ,
38- async ( ) => fetch ( 'https://httpstat.us /200' , { method : 'HEAD' } ) ,
44+ async ( ) => fetch ( 'https://httpbin.org/status /200' , { method : 'HEAD' } ) ,
3945 async ( ) =>
4046 fetch ( 'https://postman-echo.com/put' , {
4147 method : 'PUT' ,
4248 body : JSON . stringify ( { test : 'hello' } ) ,
4349 } ) ,
44- async ( ) => fetch ( 'https://httpstat.us/ 200?sleep=300' ) ,
45- async ( ) => fetch ( 'https://httpstat.us/ 204?sleep=200' ) ,
46- async ( ) => fetch ( 'https://httpstat.us/ 302?sleep=200' ) ,
47- async ( ) => fetch ( 'https://httpstat.us/ 400?sleep=200' ) ,
48- async ( ) => fetch ( 'https://httpstat.us/ 401?sleep=200' ) ,
49- async ( ) => fetch ( 'https://httpstat.us/ 403?sleep=200' ) ,
50- async ( ) => fetch ( 'https://httpstat.us/ 404?sleep=400' ) ,
51- async ( ) => fetch ( 'https://httpstat.us/ 500?sleep=5000' ) ,
52- async ( ) => fetch ( 'https://httpstat.us/ 503?sleep=200' ) ,
53- async ( ) => fetch ( 'https://httpstat.us/ 504?sleep=10000' ) ,
50+ async ( ) => fetchStatus ( 200 , 0.3 ) ,
51+ async ( ) => fetchStatus ( 204 , 0.2 ) ,
52+ async ( ) => fetchStatus ( 302 , 0.2 ) ,
53+ async ( ) => fetchStatus ( 400 , 0.2 ) ,
54+ async ( ) => fetchStatus ( 401 , 0.2 ) ,
55+ async ( ) => fetchStatus ( 403 , 0.2 ) ,
56+ async ( ) => fetchStatus ( 404 , 0.4 ) ,
57+ async ( ) => fetchStatus ( 500 , 5 ) ,
58+ async ( ) => fetchStatus ( 503 , 0.2 ) ,
59+ async ( ) => fetchStatus ( 504 , 10 ) ,
5460
5561 // Non JSON response
5662 async ( ) => fetch ( 'https://postman-echo.com/stream/2' ) ,
5763
58- async ( ) => getRates ( ) , // 405
59- async ( ) => getHero ( ) , // 400
60- async ( ) => getUser ( ) , // 200
64+ async ( ) => getTodos ( ) ,
6165 // Test requests that fail
6266 // async () => fetch('https://failingrequest'),
6367] ;
@@ -78,7 +82,7 @@ export default function App() {
7882 startNetworkLogging ( {
7983 ignoredHosts : [ '127.0.0.1' ] ,
8084 maxRequests,
81- ignoredUrls : [ 'https://httpstat.us /other' ] ,
85+ ignoredUrls : [ 'https://httpbin.org/status /other' ] ,
8286 ignoredPatterns : [ / ^ P O S T h t t p : \/ \/ ( 1 9 2 | 1 0 ) / , / \/ l o g s $ / , / \/ s y m b o l i c a t e $ / ] ,
8387 } ) ;
8488 } , [ ] ) ;
@@ -118,36 +122,38 @@ export default function App() {
118122 ) ;
119123
120124 return (
121- < SafeAreaView style = { styles . container } >
122- < StatusBar
123- barStyle = { isDark ? 'light-content' : 'dark-content' }
124- backgroundColor = { isDark ? '#2d2a28' : 'white' }
125- />
126- < View style = { styles . header } >
127- < TouchableOpacity
128- style = { styles . navButton }
129- testID = "backButton"
130- onPress = { backHandler }
131- hitSlop = { { top : 20 , left : 20 , bottom : 20 , right : 20 } }
132- >
133- < Text style = { styles . backButtonText } > { '‹' } </ Text >
134- </ TouchableOpacity >
135- < Text style = { styles . title } accessibilityRole = "header" >
136- react-native-network-logger
137- </ Text >
138- < View style = { styles . navButton } />
139- </ View >
140- { ( unmountNetworkLogger && remountButton ) || (
141- < NetworkLogger theme = { theme } maxRows = { 10 } />
142- ) }
143- < View style = { styles . bottomView } >
144- < Button
145- title = "Toggle Theme"
146- onPress = { ( ) => setTheme ( theme === 'light' ? 'dark' : 'light' ) }
125+ < SafeAreaProvider >
126+ < SafeAreaView style = { styles . container } >
127+ < StatusBar
128+ barStyle = { isDark ? 'light-content' : 'dark-content' }
129+ backgroundColor = { isDark ? '#2d2a28' : 'white' }
147130 />
148- < Button title = "Make request" onPress = { makeRequest } />
149- </ View >
150- </ SafeAreaView >
131+ < View style = { styles . header } >
132+ < TouchableOpacity
133+ style = { styles . navButton }
134+ testID = "backButton"
135+ onPress = { backHandler }
136+ hitSlop = { { top : 20 , left : 20 , bottom : 20 , right : 20 } }
137+ >
138+ < Text style = { styles . backButtonText } > { '‹' } </ Text >
139+ </ TouchableOpacity >
140+ < Text style = { styles . title } accessibilityRole = "header" >
141+ react-native-network-logger
142+ </ Text >
143+ < View style = { styles . navButton } />
144+ </ View >
145+ { ( unmountNetworkLogger && remountButton ) || (
146+ < NetworkLogger theme = { theme } maxRows = { 10 } />
147+ ) }
148+ < View style = { styles . bottomView } >
149+ < Button
150+ title = "Toggle Theme"
151+ onPress = { ( ) => setTheme ( theme === 'light' ? 'dark' : 'light' ) }
152+ />
153+ < Button title = "Make request" onPress = { makeRequest } />
154+ </ View >
155+ </ SafeAreaView >
156+ </ SafeAreaProvider >
151157 ) ;
152158}
153159
@@ -156,7 +162,6 @@ const themedStyles = (dark = false) =>
156162 container : {
157163 flex : 1 ,
158164 backgroundColor : dark ? '#2d2a28' : 'white' ,
159- paddingTop : 0 ,
160165 } ,
161166 header : {
162167 flexDirection : 'row' ,
0 commit comments