/
App.js
123 lines (114 loc) · 3.26 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
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 { colors } from './../constants'
export default class App extends PureComponent {
state = {
loading: true,
hide: true,
duration: 4000,
progress: new Animated.Value(0),
deepLink: {
routeName: 'main',
params: {},
},
}
componentDidMount () {
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.startAnimation()
this.setState({ loading: false })
}
componentWillUnmount () {
if (this._handleOpenURL !== undefined) {
Linking.removeEventListener('url', this._handleOpenURL)
}
}
handleOpenURL (event) {
let url = parseUrl(event.url.replace('berty://', 'https://berty.tech/'))
switch (url.pathname) {
case '/add-contact':
this.setState({
deepLink: {
routeName: 'modal/contacts/add/by-public-key',
params: {
initialKey: url.hashParts['public-key'] || '',
initialName: url.hashParts['display-name'] || '',
},
},
})
break
default:
console.warn(`Unhandled deep link, URL: ${event.url}`)
break
}
}
startAnimation () {
Animated.timing(this.state.progress, {
toValue: 1,
duration: this.state.duration,
easing: Easing.linear,
}).start(({ finished }) => {
if (finished) {
this.setState({ hide: false })
}
})
}
render () {
console.log(this.onAnimationFinished)
const { loading, deepLink, hide, progress } = this.state
return (
<SafeAreaView style={{ flex: 1 }} forceInset={{ bottom: 'never' }}>
{ hide && 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')}
progress={progress}
loop={false}
style={{ 'width': 320 }}
autoSize
/>
</Flex.Rows>
: null }
{ !loading
? <Accounts
ref={nav => {
this.navigation = nav
}}
screenProps={{
deepLink,
}}
/> : null }
<Accounts
ref={nav => {
this.navigation = nav
}}
screenProps={{
deepLink,
}}
/>
<FlashMessage position='top' />
{Platform.OS === 'ios' && <KeyboardSpacer />}
</SafeAreaView>
)
}
}