1import * as Device from 'expo-device'; 2import * as React from 'react'; 3import { Button, ScrollView, View, Platform } 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 Year" value={Device.deviceYearClass} /> 71 <DeviceConstants name="Device manufacturer" value={Device.manufacturer} /> 72 <DeviceConstants name="Device modelName" value={Device.modelName} /> 73 <DeviceConstants name="Device os name" value={Device.osName} /> 74 <DeviceConstants name="Device total Memory" value={Device.totalMemory} /> 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 osVersion" value={Device.osVersion} /> 82 <DeviceConstants name="Device deviceName" value={Device.deviceName} /> 83 <DeviceConstants name="Device osInternalBuildId" value={Device.osInternalBuildId} /> 84 {Platform.OS === 'android' && ( 85 <View> 86 <DeviceConstants name="Device osBuildFingerprint" value={Device.osBuildFingerprint} /> 87 <DeviceConstants name="Device designName" value={Device.designName} /> 88 <DeviceConstants name="Device osBuildId" value={Device.osBuildId} /> 89 <DeviceConstants name="Device productName" value={Device.productName} /> 90 <DeviceConstants name="Device platformApiLevel" value={Device.platformApiLevel} /> 91 </View> 92 )} 93 <DeviceMethods 94 name="Device deviceType" 95 method={async () => deviceTypeMap[await Device.getDeviceTypeAsync()]} 96 /> 97 {Platform.OS === 'android' && ( 98 <View> 99 <DeviceMethods 100 name="Device get system features" 101 method={Device.getPlatformFeaturesAsync} 102 /> 103 <DeviceMethods name="Device get max memory" method={Device.getMaxMemoryAsync} /> 104 <DeviceMethods 105 name="Device is sideloading enabled" 106 method={Device.isSideLoadingEnabledAsync} 107 /> 108 </View> 109 )} 110 <DeviceMethods 111 name="Device is rooted experimental" 112 method={Device.isRootedExperimentalAsync} 113 /> 114 </ScrollView> 115 ); 116} 117