-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchInput.js
55 lines (50 loc) · 1.56 KB
/
SearchInput.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
import React, { Component } from 'react';
import {TouchableWithoutFeedback, View, AppRegistry, TextInput, Text } from 'react-native';
var styles = require('./styles');
export default class MyInput extends Component {
constructor(props) {
super(props);
var ctx = this;
this.state = { text: 'Useless Placeholder' };
this.state.text = this.props.text;
this.state.placeholder = this.props.text;
this.clear = function(){
ctx.setState({removeDiv:true,text:""})
ctx.refs.nameInput.focus();
}
this.checkEmpty = function(){
if(ctx.state.text === ""){
ctx.setState({removeDiv:false,text:ctx.state.placeholder})
}
ctx.props.blurFunc();
}
}
render() {
var clearDivStyle = styles.clearDivActive;
var textStyle;
if(this.state.removeDiv){
clearDivStyle = styles.clearDivHidden;
textStyle = styles.defaultInputFocus;
}
return (
<View>
<TouchableWithoutFeedback onPressIn={this.clear}>
<View style={clearDivStyle}></View>
</TouchableWithoutFeedback>
<View style={styles.searchInputView} elevation={5}>
<TextInput
style={[styles.searchInput,textStyle]}
onChangeText={(t) => this.setState({text:t})}
value={this.state.text}
underlineColorAndroid="white"
onBlur={this.checkEmpty}
onFocus={this.props.focusFunc}
ref="nameInput"
onSubmitEditing={this.props.fin}
type={this.props.type}
/>
</View>
</View>
);
}
}