1import * as Cellular from 'expo-cellular';
2import * as React from 'react';
3import { ScrollView } from 'react-native';
4
5import MonoText from '../components/MonoText';
6import { useResolvedValue } from '../utilities/useResolvedValue';
7
8export default function CellularScreen() {
9  const [generation, error] = useResolvedValue(Cellular.getCellularGenerationAsync);
10
11  React.useEffect(() => {
12    if (error) alert(error.message);
13  }, [error]);
14
15  return (
16    <ScrollView style={{ padding: 10 }}>
17      <MonoText>
18        {JSON.stringify(
19          {
20            allowsVoip: Cellular.allowsVoip,
21            carrier: Cellular.carrier,
22            isoCountryCode: Cellular.isoCountryCode,
23            mobileCountryCode: Cellular.mobileCountryCode,
24            mobileNetworkCode: Cellular.mobileNetworkCode,
25            generation,
26            generationName: generationMap[generation ?? 0],
27          },
28          null,
29          2
30        )}
31      </MonoText>
32    </ScrollView>
33  );
34}
35
36const generationMap = {
37  [Cellular.CellularGeneration.UNKNOWN]: 'unknown',
38  [Cellular.CellularGeneration.CELLULAR_2G]: '2G',
39  [Cellular.CellularGeneration.CELLULAR_3G]: '3G',
40  [Cellular.CellularGeneration.CELLULAR_4G]: '4G',
41};
42