Skip to content

Commit e0de43f

Browse files
committed
created Akira
1 parent cfe58ac commit e0de43f

File tree

4 files changed

+163
-2
lines changed

4 files changed

+163
-2
lines changed

Example/TextInputEffectsExample.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Jiro,
1111
Isao,
1212
Madoka,
13+
Akira,
1314
} from 'react-native-textinput-effects';
1415

1516
export default class TextInputEffectsExample extends Component {
@@ -43,10 +44,14 @@ export default class TextInputEffectsExample extends Component {
4344
borderColor={'#da7071'}
4445
/>
4546
<Madoka
46-
style={{ marginTop: 16 }}
47+
style={{ marginTop: 8 }}
4748
label={'Weight'}
4849
borderColor={'#7A7593'}
4950
/>
51+
<Akira
52+
label={'Maiden Name'}
53+
borderColor={'#7A7593'}
54+
/>
5055
</ScrollView>
5156
);
5257
}

lib/Akira.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import React, { PropTypes, Component } from 'react';
2+
import {
3+
Animated,
4+
Text,
5+
TextInput,
6+
TouchableWithoutFeedback,
7+
View,
8+
StyleSheet,
9+
} from 'react-native';
10+
11+
import BaseInput from './BaseInput';
12+
13+
const LABEL_HEIGHT = 24;
14+
const PADDING = 16;
15+
16+
export default class Akira extends BaseInput {
17+
18+
static propTypes = {
19+
/*
20+
* this is applied as active border and label color
21+
*/
22+
borderColor: PropTypes.string,
23+
height: PropTypes.number,
24+
};
25+
26+
static defaultProps = {
27+
borderColor: '#7A7593',
28+
height: 48,
29+
animationDuration: 200,
30+
};
31+
32+
render() {
33+
const {
34+
label,
35+
style: containerStyle,
36+
height: inputHeight,
37+
inputStyle,
38+
labelStyle,
39+
borderColor,
40+
} = this.props;
41+
const {
42+
width,
43+
focusedAnim,
44+
value,
45+
} = this.state;
46+
47+
return (
48+
<View style={[containerStyle, styles.container]} onLayout={this._onLayout}>
49+
<TouchableWithoutFeedback onPress={this._focus}>
50+
<Animated.View style={{
51+
width,
52+
height: LABEL_HEIGHT,
53+
transform: [{
54+
translateY: focusedAnim.interpolate({
55+
inputRange: [0, 1],
56+
outputRange: [LABEL_HEIGHT + PADDING, 0],
57+
}),
58+
}],
59+
}}>
60+
<Text style={[styles.label, labelStyle]}>
61+
{label}
62+
</Text>
63+
</Animated.View>
64+
</TouchableWithoutFeedback>
65+
<TextInput
66+
ref="input"
67+
{...this.props}
68+
style={[styles.textInput, inputStyle, {
69+
width,
70+
height: inputHeight,
71+
}]}
72+
value={value}
73+
onBlur={this._onBlur}
74+
onChange={this._onChange}
75+
onFocus={this._onFocus}
76+
/>
77+
{/* left border */}
78+
<Animated.View
79+
style={{
80+
position: 'absolute',
81+
left: 0,
82+
bottom: 0,
83+
height: inputHeight,
84+
width: focusedAnim.interpolate({
85+
inputRange: [0, 1],
86+
outputRange: [6, 1],
87+
}),
88+
backgroundColor: borderColor,
89+
}}
90+
/>
91+
{/* top border */}
92+
<Animated.View
93+
style={{
94+
position: 'absolute',
95+
top: LABEL_HEIGHT,
96+
width,
97+
height: focusedAnim.interpolate({
98+
inputRange: [0, 1],
99+
outputRange: [6, 1],
100+
}),
101+
backgroundColor: borderColor,
102+
}}
103+
/>
104+
{/* right border */}
105+
<Animated.View
106+
style={{
107+
position: 'absolute',
108+
right: 0,
109+
bottom: 0,
110+
height: inputHeight,
111+
width: focusedAnim.interpolate({
112+
inputRange: [0, 1],
113+
outputRange: [6, 1],
114+
}),
115+
backgroundColor: borderColor,
116+
}}
117+
/>
118+
{/* bottom border */}
119+
<Animated.View
120+
style={{
121+
position: 'absolute',
122+
bottom: 0,
123+
height: focusedAnim.interpolate({
124+
inputRange: [0, 1],
125+
outputRange: [6, 1],
126+
}),
127+
width,
128+
backgroundColor: borderColor,
129+
}}
130+
/>
131+
</View>
132+
);
133+
}
134+
}
135+
136+
const styles = StyleSheet.create({
137+
container: {
138+
flex: 1,
139+
marginHorizontal: 16,
140+
},
141+
label: {
142+
backgroundColor: 'transparent',
143+
fontFamily: 'Arial',
144+
fontSize: 14,
145+
fontWeight: 'bold',
146+
color: '#cc6055',
147+
textAlign: 'center',
148+
},
149+
textInput: {
150+
padding: PADDING,
151+
color: 'black',
152+
fontSize: 18,
153+
textAlign: 'center',
154+
},
155+
});

lib/Isao.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,3 @@ const styles = StyleSheet.create({
134134
right: 0,
135135
},
136136
});
137-

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import Hoshi from './Hoshi';
33
import Jiro from './Jiro';
44
import Isao from './Isao';
55
import Madoka from './Madoka';
6+
import Akira from './Akira';
67

78
export {
89
Kaede,
910
Hoshi,
1011
Jiro,
1112
Isao,
1213
Madoka,
14+
Akira,
1315
};

0 commit comments

Comments
 (0)