Skip to content

Commit cfe58ac

Browse files
committed
created Madoka
1 parent 1d39876 commit cfe58ac

File tree

4 files changed

+163
-4
lines changed

4 files changed

+163
-4
lines changed

Example/TextInputEffectsExample.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Hoshi,
1010
Jiro,
1111
Isao,
12+
Madoka,
1213
} from 'react-native-textinput-effects';
1314

1415
export default class TextInputEffectsExample extends Component {
@@ -41,6 +42,11 @@ export default class TextInputEffectsExample extends Component {
4142
label={'Middle name'}
4243
borderColor={'#da7071'}
4344
/>
45+
<Madoka
46+
style={{ marginTop: 16 }}
47+
label={'Weight'}
48+
borderColor={'#7A7593'}
49+
/>
4450
</ScrollView>
4551
);
4652
}

lib/Jiro.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ export default class Jiro extends BaseInput {
2828
constructor(props, context) {
2929
super(props, context);
3030

31+
const animationValue = props.value ? 1 : 0;
3132
this.state = {
3233
value: props.value,
33-
borderPositionAnim: new Animated.Value(props.value ? 1 : 0),
34-
borderHeightAnim: new Animated.Value(props.value ? 1 : 0),
35-
labelPositionAnim: new Animated.Value(props.value ? 1 : 0),
34+
borderPositionAnim: new Animated.Value(animationValue),
35+
borderHeightAnim: new Animated.Value(animationValue),
36+
labelPositionAnim: new Animated.Value(animationValue),
3637
};
3738
}
3839

@@ -160,4 +161,3 @@ const styles = StyleSheet.create({
160161
right: 0,
161162
},
162163
});
163-

lib/Madoka.js

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

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import Kaede from './Kaede';
22
import Hoshi from './Hoshi';
33
import Jiro from './Jiro';
44
import Isao from './Isao';
5+
import Madoka from './Madoka';
56

67
export {
78
Kaede,
89
Hoshi,
910
Jiro,
1011
Isao,
12+
Madoka,
1113
};

0 commit comments

Comments
 (0)