1import * as Network from 'expo-network'; 2import * as React from 'react'; 3import { ScrollView, Text } from 'react-native'; 4 5import MonoText from '../components/MonoText'; 6import { useResolvedValue } from '../utilities/useResolvedValue'; 7 8export default function NetworkScreen() { 9 const isMounted = React.useRef(true); 10 const [airplaneMode] = useResolvedValue(Network.isAirplaneModeEnabledAsync); 11 const [networkState] = useResolvedValue(Network.getNetworkStateAsync); 12 const [ip, ipError] = useResolvedValue(Network.getIpAddressAsync); 13 14 React.useEffect(() => { 15 if (ipError) alert(ipError.message); 16 }, [ipError]); 17 18 React.useEffect(() => { 19 isMounted.current = true; 20 return () => { 21 isMounted.current = false; 22 }; 23 }, []); 24 25 return ( 26 <ScrollView style={{ padding: 10 }}> 27 <MonoText> 28 {JSON.stringify( 29 { 30 ipAddress: ip, 31 networkState, 32 airplaneModeEnabled: airplaneMode, 33 }, 34 null, 35 2 36 )} 37 </MonoText> 38 <Text> 39 <Text style={{ fontWeight: 'bold' }}>airplaneModeEnabled</Text> is only supported on 40 Android. It should be <Text style={{ fontWeight: 'bold' }}>null</Text> on iOS. 41 </Text> 42 </ScrollView> 43 ); 44} 45