1import React from 'react';
2import { ScrollView, View, Text, Button, Platform } from 'react-native';
3import * as Device from 'expo-device';
4import HeadingText from '../components/HeadingText';
5import MonoText from '../components/MonoText';
6
7interface DeviceConstant {
8  name?: string;
9  value?: any;
10}
11
12interface DeviceMethod {
13  name?: string;
14  method?: any;
15}
16
17interface State {
18  value?: any;
19}
20
21class DeviceConstants extends React.Component<DeviceConstant> {
22  render() {
23    let { name, value } = this.props;
24    if (typeof value === 'boolean') {
25      return (
26        <View style={{ marginBottom: 10 }}>
27          <HeadingText>{name}</HeadingText>
28          <MonoText> {String(value)}</MonoText>
29        </View>
30      );
31    } else {
32      return (
33        <View style={{ marginBottom: 10 }}>
34          <HeadingText>{name}</HeadingText>
35          <MonoText> {value}</MonoText>
36        </View>
37      );
38    }
39  }
40}
41
42class DeviceMethods extends React.Component<DeviceMethod, State> {
43  state = {
44    value: '',
45  };
46
47  _getValue = async () => {
48    let method = this.props.method;
49    let value = await method();
50    if (typeof value === 'boolean') {
51      value = value.toString();
52    } else if (Array.isArray(value)) {
53      value = value.join('\n');
54    }
55    this.setState({ value });
56  };
57
58  render() {
59    let { name } = this.props;
60    if(!name) name = '';
61    return (
62      <View style={{ padding: 10 }}>
63        <View style={{ marginBottom: 10 }}>
64          <HeadingText>{name}</HeadingText>
65          <MonoText> {this.state.value}</MonoText>
66        </View>
67        <Button onPress={this._getValue} title={name} color="#DCA42D" />
68      </View>
69    );
70  }
71}
72
73export default class DeviceScreen extends React.Component {
74  static navigationOptions = {
75    title: 'Device',
76  };
77
78  render() {
79    return (
80      <ScrollView style={{ padding: 20, flex: 1, margin: 10 }}>
81        <DeviceConstants name="Device Brand" value={Device.brand} />
82        <DeviceConstants name="Device manufacturer" value={Device.manufacturer} />
83        <DeviceConstants name="Device modelName" value={Device.modelName} />
84        <DeviceConstants name="Device os name" value={Device.osName} />
85        <DeviceConstants name="Device total Memory" value={Device.totalMemory} />
86        <DeviceConstants name="Device osBuildFingerprint" value={Device.osBuildFingerprint} />
87        <DeviceConstants name="Device isDevice" value={Device.isDevice} />
88        <DeviceConstants name="Device modelId" value={Device.modelId} />
89        <DeviceConstants
90          name="Device supportedCpuArchitectures"
91          value={Device.supportedCpuArchitectures}
92        />
93        <DeviceConstants name="Device designName" value={Device.designName} />
94        <DeviceConstants name="Device osBuildId" value={Device.osBuildId} />
95        <DeviceConstants name="Device productName" value={Device.productName} />
96        <DeviceConstants name="Device platformApiLevel" value={Device.platformApiLevel} />
97        <DeviceConstants name="Device osVersion" value={Device.osVersion} />
98        <DeviceConstants name="Device deviceName" value={Device.deviceName} />
99        <DeviceConstants name="Device osInternalBuildId" value={Device.osInternalBuildId} />
100        <DeviceMethods name="Device deviceType" method={Device.getDeviceTypeAsync} />
101        <DeviceMethods name="Device get system features" method={Device.getPlatformFeaturesAsync} />
102        <DeviceMethods name="Device get max memory" method={Device.getMaxMemoryAsync} />
103        <DeviceMethods
104          name="Device is sideloading enabled"
105          method={Device.isSideLoadingEnabledAsync}
106        />
107        <DeviceMethods
108          name="Device is rooted experimental"
109          method={Device.isRootedExperimentalAsync}
110        />
111      </ScrollView>
112    );
113  }
114}
115