-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyInput.js
80 lines (67 loc) · 2.11 KB
/
MyInput.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
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:""})
}
this.clearAndFocus = function(){
ctx.clear();
ctx.refs.nameInput.focus();
}
this.clearAndBlur = function(){
ctx.clear();
ctx.refs.nameInput.blur();
}
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;
}
var isPass = (this.props.type==="password" && this.state.text!==this.state.placeholder);
var textView = [styles.defaultInputView];
if(this.props.type==="gameInput"){
textView.push(styles.gameInputView);
textStyle=styles.gameInputText;
if(this.state.removeDiv){
textStyle = styles.gameTextInputFocus;
}
}
return (
<View>
<TouchableWithoutFeedback onPressIn={this.clearAndFocus}>
<View style={clearDivStyle}></View>
</TouchableWithoutFeedback>
<View style={textView}>
<TextInput
style={[styles.defaultInput,textStyle]}
onChangeText={(t) => this.setState({text:t})}
value={this.state.text}
underlineColorAndroid="#e3e3e3"
onBlur={this.checkEmpty}
onFocus={this.props.focusFunc}
ref="nameInput"
onSubmitEditing={()=>{this.props.fin(this.state.text)}}
type={this.props.type}
secureTextEntry={isPass}
/>
</View>
</View>
);
}
}