-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
132 lines (128 loc) · 4.25 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
import React from 'react'
import { StyleSheet, Text, TextInput, View, SafeAreaView, StatusBar, WebView } from 'react-native'
import Menu, { MenuProvider, MenuOptions, MenuOption, MenuTrigger } from 'react-native-popup-menu'
import { Icon } from 'react-native-elements'
import nodejs from 'nodejs-mobile-react-native'
import I18n from './i18n/'
import commonStyles from './styles/common'
import PageIndicator from './components/PageIndicator'
export default class App extends React.Component {
constructor () {
super()
this.state = {
typingUrl: 'https://google.com',
updatedUrl: 'https://google.com',
url: 'https://google.com',
status: 'loading'
}
this.>
}
onNavigation ({ url, loading }) {
StatusBar.setNetworkActivityIndicatorVisible(false)
this.setState({ url, typingUrl: url })
this.setState({ status: 'http' })
if (url.startsWith('dat://')) this.setState({ status: 'dat' })
if (url.startsWith('https://')) this.setState({ status: 'https' })
if (loading) {
StatusBar.setNetworkActivityIndicatorVisible(true)
this.setState({ status: 'loading' })
}
}
componentWillMount () {
nodejs.start('main.js')
nodejs.channel.addListener(
'message',
msg => {
alert('From node: ' + msg)
},
this
)
}
render () {
return (
<SafeAreaView style={styles.container}>
<StatusBar barStyle='light-content' />
<MenuProvider>
<View style={styles.navbar}>
<PageIndicator status={this.state.status} />
<TextInput
style={[commonStyles.font, styles.addressbar]}
autoCapitalize='none'
autoCorrect={false}
clearButtonMode='while-editing'
disableFullscreenUI
underlineColorAndroid='transparent'
selectionColor='#3498db'
value={this.state.typingUrl}
placeholder='dat://imstu.bid'
=> this.setState({ typingUrl: text })}
=> {
let url = this.state.typingUrl
// In many cases users only enter an url like google.com, we'll need to add a scheme.
if (!/^(about|https|http|dat):/i.test(url)) url = 'http://' + url
this.setState({ url, updatedUrl: url })
}}
/>
<Menu>
<MenuTrigger>
<Icon
name='more-vert'
color='#fff'
style={[commonStyles.font, styles.menu]}
/>
</MenuTrigger>
<MenuOptions>
<MenuOption value='refresh' => this.refs['mainFrame'].reload()}>
<Text style={commonStyles.font}>{I18n.t('controls.refresh')}</Text>
</MenuOption>
<MenuOption value={2}>
<Text style={commonStyles.font}>{I18n.t('controls.about')}</Text>
</MenuOption>
<MenuOption value={3}>
<Text style={commonStyles.font}>{I18n.currentLocale()}</Text>
</MenuOption>
</MenuOptions>
</Menu>
</View>
<WebView
ref='mainFrame'
source={{uri: this.state.updatedUrl}}
>
/>
</MenuProvider>
</SafeAreaView>
)
}
}
const StyleConstants = {
navbarSpacing: 7
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#3498db'
},
navbar: {
paddingTop: (StatusBar.currentHeight || 0) + StyleConstants.navbarSpacing,
paddingBottom: StyleConstants.navbarSpacing,
paddingLeft: StyleConstants.navbarSpacing,
paddingRight: StyleConstants.navbarSpacing,
backgroundColor: '#3498db',
flexDirection: 'row',
alignItems: 'center'
},
addressbar: {
flex: 1,
color: '#333',
backgroundColor: '#fff',
marginLeft: StyleConstants.navbarSpacing,
marginRight: StyleConstants.navbarSpacing,
padding: 3,
borderRadius: 2,
// Reset shadows for iOS only.
shadowRadius: 0,
shadowOffset: { width: 0, height: 0 },
elevation: 2, // Android
shadowOpacity: 1
}
})
You can’t perform that action at this time.