1import * as Device from 'expo-device'; 2import * as React from 'react'; 3import { Button, ScrollView, View } from 'react-native'; 4 5import HeadingText from '../components/HeadingText'; 6import MonoText from '../components/MonoText'; 7import Colors from '../constants/Colors'; 8 9interface DeviceConstant { 10 name?: string; 11 value?: any; 12} 13 14interface DeviceMethod { 15 name?: string; 16 method: () => Promise<any>; 17} 18 19const deviceTypeMap = { 20 [Device.DeviceType.UNKNOWN]: 'unknown', 21 [Device.DeviceType.PHONE]: 'phone', 22 [Device.DeviceType.TABLET]: 'tablet', 23 [Device.DeviceType.DESKTOP]: 'desktop', 24 [Device.DeviceType.TV]: 'tv', 25}; 26 27function DeviceConstants({ name, value }: DeviceConstant) { 28 return ( 29 <View style={{ marginBottom: 8 }}> 30 <HeadingText>{name}</HeadingText> 31 <MonoText> {typeof value === 'boolean' ? String(value) : value}</MonoText> 32 </View> 33 ); 34} 35 36function DeviceMethods({ name = '', method }: DeviceMethod) { 37 const [value, setValue] = React.useState(''); 38 39 const getValueAsync = async () => { 40 let value: any; 41 try { 42 value = await method(); 43 if (typeof value === 'boolean') { 44 value = value.toString(); 45 } else if (Array.isArray(value)) { 46 value = value.join('\n'); 47 } 48 } catch (error) { 49 alert(error); 50 value = error.message; 51 } 52 setValue(value); 53 }; 54 55 return ( 56 <View style={{ paddingVertical: 8 }}> 57 <View style={{ marginBottom: 8 }}> 58 <HeadingText>{name}</HeadingText> 59 <MonoText>{value}</MonoText> 60 </View> 61 <Button onPress={getValueAsync} title={name} color={Colors.tintColor} /> 62 </View> 63 ); 64} 65 66export default function DeviceScreen() { 67 return ( 68 <ScrollView style={{ flex: 1 }} contentContainerStyle={{ padding: 12 }}> 69 <DeviceConstants name="Device Brand" value={Device.brand} /> 70 <DeviceConstants name="Device manufacturer" value={Device.manufacturer} /> 71 <DeviceConstants name="Device modelName" value={Device.modelName} /> 72 <DeviceConstants name="Device os name" value={Device.osName} /> 73 <DeviceConstants name="Device total Memory" value={Device.totalMemory} /> 74 <DeviceConstants name="Device osBuildFingerprint" value={Device.osBuildFingerprint} /> 75 <DeviceConstants name="Device isDevice" value={Device.isDevice} /> 76 <DeviceConstants name="Device modelId" value={Device.modelId} /> 77 <DeviceConstants 78 name="Device supportedCpuArchitectures" 79 value={Device.supportedCpuArchitectures} 80 /> 81 <DeviceConstants name="Device designName" value={Device.designName} /> 82 <DeviceConstants name="Device osBuildId" value={Device.osBuildId} /> 83 <DeviceConstants name="Device productName" value={Device.productName} /> 84 <DeviceConstants name="Device platformApiLevel" value={Device.platformApiLevel} /> 85 <DeviceConstants name="Device osVersion" value={Device.osVersion} /> 86 <DeviceConstants name="Device deviceName" value={Device.deviceName} /> 87 <DeviceConstants name="Device osInternalBuildId" value={Device.osInternalBuildId} /> 88 <DeviceMethods 89 name="Device deviceType" 90 method={async () => deviceTypeMap[await Device.getDeviceTypeAsync()]} 91 /> 92 <DeviceMethods name="Device get system features" method={Device.getPlatformFeaturesAsync} /> 93 <DeviceMethods name="Device get max memory" method={Device.getMaxMemoryAsync} /> 94 <DeviceMethods 95 name="Device is sideloading enabled" 96 method={Device.isSideLoadingEnabledAsync} 97 /> 98 <DeviceMethods 99 name="Device is rooted experimental" 100 method={Device.isRootedExperimentalAsync} 101 /> 102 </ScrollView> 103 ); 104} 105