-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
84 lines (75 loc) · 1.92 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import 'react-native-gesture-handler';
import React, {useState, useEffect} from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
Dimensions,
} from 'react-native';
import NetInfo from "@react-native-community/netinfo";
const App = () => {
const [networkState, setNetworkState] = useState(undefined);
useEffect(() => {
const netInfoUnsubscribe = NetInfo.addEventListener(networkState=>{
console.log("subscribing", networkState)
setNetworkState(networkState);
})
return () => {
console.log("unsubscribing")
netInfoUnsubscribe();
}
}, [])
const mapObject = (obj)=>{
return (
obj && Object.keys(obj).map(val=>{
return (
<View key={val}>
<Text>{`${val}: ${JSON.stringify(obj[val])}`}</Text>
{/* <Text>{JSON.stringify(obj[val])}</Text> */}
</View>
)
})
)
}
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={{flex:1}}>
<View style={styles.safeContainer}>
{networkState && Object.keys(networkState).map((val,i)=>{
// return <Text key={i}></Text>
// console.log(typeof )
return (
<View key={val}>
<Text style={{fontWeight:"bold"}}>{val}</Text>
{typeof networkState[val] ==='object' ?
mapObject(networkState[val]) : <Text>{JSON.stringify(networkState[val])}</Text>
}
<Text/>
</View>
)
})}
</View>
</SafeAreaView>
</>
);
};
export default App;
const { height, width} = Dimensions.get('window')
const styles = StyleSheet.create({
safeContainer: {
display: 'flex',
flexDirection: 'column',
padding: width*5/100,
}
})