-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathApp.js
116 lines (104 loc) · 2.64 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* @Author: czy0729
* @Date: 2019-03-30 19:25:19
* @Last Modified by: czy0729
* @Last Modified time: 2019-09-05 16:28:20
*/
import React from 'react'
import { StyleSheet, View } from 'react-native'
import { useScreens } from 'react-native-screens'
import { AppLoading } from 'expo'
import * as Font from 'expo-font'
import { Provider } from '@ant-design/react-native'
import { ImageViewer } from '@components'
import Stores, { systemStore } from '@stores'
import { observer } from '@utils/decorators'
import { hm } from '@utils/fetch'
import _ from '@styles'
import theme from '@styles/theme'
import Navigations from './navigations/index'
// https://reactnavigation.org/docs/zh-Hans/react-native-screens.html
useScreens()
console.disableYellowBox = true
/**
* 能打印循环引用
*/
global.log = (value, space) => {
const handleCircular = () => {
const cache = []
const keyCache = []
return (key, value) => {
if (typeof value === 'object' && value !== null) {
const index = cache.indexOf(value)
if (index !== -1) {
return `[Circular ${keyCache[index]}]`
}
cache.push(value)
keyCache.push(key || 'root')
}
return value
}
}
console.log(JSON.stringify(value, handleCircular(), space))
}
export default
@observer
class App extends React.Component {
state = {
isLoadingComplete: false
}
componentDidCatch(error) {
hm(`error?error=${error}`, '错误')
}
loadResourcesAsync = async () =>
Promise.all([
Stores.init(),
// Asset.loadAsync([]),
Font.loadAsync({
bgm: require('./assets/fonts/AppleColorEmoji.ttf')
})
])
handleLoadingError = error => {
console.warn(error)
}
handleFinishLoading = () => {
this.setState({
isLoadingComplete: true
})
}
closeImageViewer = () => {
systemStore.closeImageViewer()
}
render() {
const { skipLoadingScreen } = this.props
const { isLoadingComplete } = this.state
if (!isLoadingComplete && !skipLoadingScreen) {
return (
<AppLoading
startAsync={this.loadResourcesAsync}
onFinish={this.handleFinishLoading}
onError={this.handleLoadingError}
/>
)
}
const { visible, imageUrls } = systemStore.imageViewer
return (
<View style={styles.container}>
<Provider theme={theme}>
<Navigations />
</Provider>
<ImageViewer
visible={visible}
imageUrls={imageUrls}
onCancel={this.closeImageViewer}
/>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: _.colorBg
}
})