-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterribleTextInput.js
More file actions
102 lines (92 loc) · 2.63 KB
/
Copy pathterribleTextInput.js
File metadata and controls
102 lines (92 loc) · 2.63 KB
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
import React, { Component } from 'react';
import {
TextInput,
Text,
View,
TouchableOpacity
} from 'react-native';
const pi=Math.PI.toString().split('');
export default class TerribleTextInput extends Component{
constructor(props){
super(props)
this.state={
width:100,
disbale:false,
maxLength:0,
validating:true,
temperary:0
}
}
render(){
let invalid=(
<View>
<Text>String is not allow</Text>
</View>
)
let tes=this.state.validating ? null : invalid;
let reviewInput=(
<View>
<TextInput
placeholder = "Want to try some pie?"
style={{height: 40, borderColor: 'gray', borderWidth: 1,width:303}}
onChangeText={this._piTextInput.bind(this)}
/>
<View>{tes}</View>
</View>
)
return(
<View>
<TextInput
placeholder = "Title"
style={{height: 40, borderColor: 'gray', borderWidth: 1,width:this.state.width}}
editable={this.state.disbale}
maxLength={this.state.maxLength}
/>
<View style={{height:12}} />
{reviewInput}
</View>
)
}
_piTextInput(text){
let tmp;
try{
tmp=parseInt(text) || null;
}catch(e){
console.warn("Non integer")
}
if(text.length >this.state.temperary){
if(this.checkPi(text)){
this.setState({
width:this.state.width+10,
maxLength:this.state.maxLength+1,
disbale:true,
temperary:this.state.maxLength+1
})
}
}else{
if(this.checkPi(text)){
this.setState({
width:(this.state.width < 100 ? 100 : this.state.width-10),
maxLength:text.length,
disbale:this.state.width > 100,
temperary:text.length
})
}
}
return tmp
}
checkPi(text){
for(i=0;i<text.length;i++ ){
if(text[i]!=pi[i]){
return false
}
}
return true
}
}
/**
* <View>
<Text>Oops you can type in to endure the length of your input </Text>
</View>
}
*/