-
Notifications
You must be signed in to change notification settings - Fork 73
/
AddressBar.js
89 lines (72 loc) · 1.94 KB
/
AddressBar.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
'use strict';
import React from 'react-native';
var {
TextInput,
View,
} = React;
import BaseComponent from './BaseComponent'
import Utils from './Utils'
import styles from './styles'
const TEXT_INPUT_REF = 'urlInput';
class AddressBar extends BaseComponent {
constructor(props) {
super(props);
this.inputText = '';
this.state = {
url: this.props.url
};
this._bind(
'handleTextInputChange',
'onSubmitEditing'
);
}
componentWillReceiveProps(nextProps) {
this.setState({
url: nextProps.url
});
}
handleTextInputChange(event) {
const url = Utils.sanitizeUrl(event.nativeEvent.text);
this.inputText = url;
}
onSubmitEditing(event) {
this.load();
}
load() {
const url = this.inputText;
if (url === this.props.url) {
this.props.onReload();
} else {
this.props.onLoad(url)
}
// dismiss keyboard
this.refs[TEXT_INPUT_REF].blur();
}
render() {
return (
<View style={[styles.addressBarRow]}>
<TextInput
ref={TEXT_INPUT_REF}
autoCapitalize="none"
defaultValue={this.state.url}
onSubmitEditing={this.onSubmitEditing}
onChange={this.handleTextInputChange}
clearButtonMode="while-editing"
style={[styles.addressBarTextInput, this.props.foregroundColor && {color:this.props.foregroundColor}]}
/>
</View>
);
}
}
AddressBar.propTypes = {
url: React.PropTypes.string,
onLoad: React.PropTypes.func,
onReload: React.PropTypes.func,
foregroundColor: React.PropTypes.string
};
AddressBar.defaultProps = {
url: '',
onLoad: (url)=>{},
onReload: ()=>{}
};
module.exports = AddressBar;