/
App.js
160 lines (142 loc) · 4.49 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { Linking, Platform, Animated, Easing } from 'react-native'
import { SafeAreaView } from 'react-navigation'
import KeyboardSpacer from 'react-native-keyboard-spacer'
import React, { PureComponent } from 'react'
import { parse as parseUrl } from '../helpers/url'
import LottieView from 'lottie-react-native'
import { Flex } from './Library'
import FlashMessage from 'react-native-flash-message'
import Accounts from './Screens/Accounts'
import { BASE_WEBSITE_URL, colors } from './../constants'
import { I18nextProvider } from 'react-i18next'
import ReactNativeLanguages from 'react-native-languages'
import i18n from '../i18n'
import Instabug from 'instabug-reactnative';
import { btoa } from 'b64-lite'
import Config from 'react-native-config'
export default class App extends PureComponent {
state = {
loading: true,
showAnim: (process.env['ENVIRONMENT'] !== 'integration_test'),
deepLink: {
routeName: 'main',
params: {},
},
}
constructor (props) {
super(props)
Instabug.setIntroMessageEnabled(false)
if (Platform.OS === 'ios') {
Instabug.startWithToken(
Config.INSTABUG_TOKEN,
[__DEV__ ? Instabug.invocationEvent.none : Instabug.invocationEvent.shake],
)
}
if (__DEV__) {
const DevMenu = require('react-native-dev-menu')
DevMenu.addItem('Show Instabug', () => Instabug.invoke())
}
}
componentDidMount () {
ReactNativeLanguages.addEventListener('change', this._onLanguageChange)
Linking.getInitialURL()
.then(url => {
if (url !== null) {
this.handleOpenURL({ url })
}
})
.catch(() => {})
if (this._handleOpenURL === undefined) {
this._handleOpenURL = this.handleOpenURL.bind(this)
}
Linking.addEventListener('url', this._handleOpenURL)
this.setState({ loading: false })
}
componentWillUnmount () {
ReactNativeLanguages.removeEventListener('change', this._onLanguageChange)
if (this._handleOpenURL !== undefined) {
Linking.removeEventListener('url', this._handleOpenURL)
}
}
_onLanguageChange = ({ language, languages }) => {
i18n.changeLanguage(language)
}
handleOpenURL (event) {
let url = parseUrl(event.url.replace('berty://', `${BASE_WEBSITE_URL}/`))
switch (url.pathname) {
case '/conversation':
this.setState({
deepLink: {
routeName: 'chats/detail',
params: {
conversation: {
title: '',
id: btoa('conversation:' + url.hashParts['id']),
},
},
},
})
break
case '/add-contact':
this.setState({
deepLink: {
routeName: 'modal/contacts/card',
params: {
data: {
id: url.hashParts['public-key'] || '',
displayName: url.hashParts['display-name'] || '',
},
},
},
})
break
default:
console.warn(`Unhandled deep link, URL: ${event.url}`)
break
}
}
clearDeepLink () {
this.setState({ deepLink: null })
}
setDeepLink (deepLink) {
this.setState({ deepLink })
}
render () {
const { loading, deepLink, showAnim, progress } = this.state
return (
<I18nextProvider i18n={i18n}>
<SafeAreaView style={{ flex: 1 }} forceInset={{ bottom: 'never' }}>
{ showAnim && Platform.OS !== 'web'
? <Flex.Rows
align='center'
justify='center'
style={{ 'width': '100%', height: '100%', zIndex: 1000, position: 'absolute', backgroundColor: colors.white }}
>
<LottieView
source={require('./../static/animation/BertyAnimation.json')}
autoPlay={true}
loop={false}
onAnimationFinish={() => this.setState({ showAnim: false })}
style={{ 'width': 320 }}
autoSize
/>
</Flex.Rows>
: null }
{ !loading
? <Accounts
ref={nav => {
this.navigation = nav
}}
screenProps={{
deepLink,
setDeepLink: (deepLink) => this.setDeepLink(deepLink),
clearDeepLink: () => this.clearDeepLink(),
}}
/> : null }
<FlashMessage position='top' />
{Platform.OS === 'ios' && <KeyboardSpacer />}
</SafeAreaView>
</I18nextProvider>
)
}
}