Skip to content

Commit 37a3235

Browse files
committed
created Makiko
1 parent 28a8316 commit 37a3235

File tree

6 files changed

+165
-4
lines changed

6 files changed

+165
-4
lines changed

Example/TextInputEffectsExample.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
Akira,
1616
Hideo,
1717
Kohana,
18+
Makiko,
1819
} from 'react-native-textinput-effects';
1920

2021
export default class TextInputEffectsExample extends Component {
@@ -74,6 +75,13 @@ export default class TextInputEffectsExample extends Component {
7475
iconName={'phone'}
7576
iconColor={'#ddd'}
7677
/>
78+
<Makiko
79+
style={styles.input}
80+
label={'Comment'}
81+
iconClass={FontAwesomeIcon}
82+
iconName={'comment'}
83+
iconColor={'white'}
84+
/>
7785
</ScrollView>
7886
);
7987
}

lib/Hideo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99

1010
import BaseInput from './BaseInput';
1111

12-
export default class Akira extends BaseInput {
12+
export default class Hideo extends BaseInput {
1313

1414
static propTypes = {
1515
/*
@@ -26,7 +26,7 @@ export default class Akira extends BaseInput {
2626
/*
2727
* Passed to react-native-vector-icons library as name prop
2828
*/
29-
iconName: PropTypes.string,
29+
iconName: PropTypes.string.isRequired,
3030
/*
3131
* Passed to react-native-vector-icons library as color prop
3232
*/

lib/Hoshi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
import BaseInput from './BaseInput';
1212

13-
export default class Kaede extends BaseInput {
13+
export default class Hoshi extends BaseInput {
1414

1515
static propTypes = {
1616
borderColor: PropTypes.string,

lib/Kohana.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class Kohana extends BaseInput {
2323
/*
2424
* Passed to react-native-vector-icons library as name prop
2525
*/
26-
iconName: PropTypes.string,
26+
iconName: PropTypes.string.isRequired,
2727
/*
2828
* Passed to react-native-vector-icons library as color prop
2929
*/

lib/Makiko.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+
Easing,
5+
Text,
6+
TextInput,
7+
TouchableWithoutFeedback,
8+
View,
9+
StyleSheet,
10+
} from 'react-native';
11+
12+
import BaseInput from './BaseInput';
13+
14+
const ICON_WIDTH = 60;
15+
const ICON_SIZE = 30;
16+
17+
export default class Makiko extends BaseInput {
18+
19+
static propTypes = {
20+
/*
21+
* This is the icon component you are importing from react-native-vector-icons.
22+
* import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';
23+
* iconClass={FontAwesomeIcon}
24+
*/
25+
iconClass: PropTypes.func.isRequired,
26+
27+
/*
28+
* Passed to react-native-vector-icons library as name prop.
29+
* This icon expands and covers the input.
30+
* So, the icon should not have any blank spaces for animation experience.
31+
* This is the limitation for Makiko.
32+
*/
33+
iconName: PropTypes.string.isRequired,
34+
35+
/*
36+
* Passed to react-native-vector-icons library as color prop
37+
*/
38+
iconColor: PropTypes.string,
39+
};
40+
41+
static defaultProps = {
42+
iconColor: 'white',
43+
height: 48,
44+
easing: Easing.bezier(0.7, 0, 0.3, 1),
45+
animationDuration: 300,
46+
};
47+
48+
render() {
49+
const {
50+
iconClass,
51+
iconColor,
52+
iconName,
53+
style: containerStyle,
54+
height: inputHeight,
55+
inputStyle,
56+
label,
57+
labelStyle,
58+
} = this.props;
59+
const {
60+
width,
61+
focusedAnim,
62+
value,
63+
} = this.state;
64+
const AnimatedIcon = Animated.createAnimatedComponent(iconClass);
65+
66+
return (
67+
<View style={[containerStyle, styles.container]} onLayout={this._onLayout}>
68+
<TouchableWithoutFeedback onPress={this._focus}>
69+
<View>
70+
<AnimatedIcon
71+
name={iconName}
72+
color={iconColor}
73+
style={{
74+
position: 'absolute',
75+
backgroundColor: 'transparent',
76+
top: focusedAnim.interpolate({
77+
inputRange: [0, 0.2],
78+
outputRange: [8, ICON_SIZE * -1],
79+
}),
80+
left: focusedAnim.interpolate({
81+
inputRange: [0, 0.2],
82+
outputRange: [16, -18],
83+
}),
84+
height: focusedAnim.interpolate({
85+
inputRange: [0, 0.2],
86+
outputRange: [ICON_SIZE, inputHeight * 2],
87+
}),
88+
fontSize: focusedAnim.interpolate({
89+
inputRange: [0, 0.2],
90+
outputRange: [ICON_SIZE, ICON_SIZE * 4],
91+
}),
92+
}}
93+
/>
94+
<Text style={[styles.label, labelStyle, { color: iconColor }]}>
95+
{label}
96+
</Text>
97+
</View>
98+
</TouchableWithoutFeedback>
99+
<Animated.View
100+
style={{
101+
position: 'absolute',
102+
backgroundColor: 'white',
103+
left: ICON_WIDTH,
104+
height: inputHeight,
105+
width: focusedAnim.interpolate({
106+
inputRange: [0, 0.2, 1],
107+
outputRange: [0, 0, width],
108+
}),
109+
}}
110+
/>
111+
<TextInput
112+
ref="input"
113+
{...this.props}
114+
style={[styles.textInput, inputStyle, {
115+
width,
116+
height: inputHeight,
117+
}]}
118+
value={value}
119+
onBlur={this._onBlur}
120+
onChange={this._onChange}
121+
onFocus={this._onFocus}
122+
/>
123+
</View>
124+
);
125+
}
126+
}
127+
128+
const styles = StyleSheet.create({
129+
container: {
130+
flex: 1,
131+
flexDirection: 'row',
132+
marginHorizontal: 16,
133+
backgroundColor: '#CBCBCB',
134+
overflow: 'hidden',
135+
},
136+
label: {
137+
position: 'absolute',
138+
top: 16,
139+
left: ICON_WIDTH,
140+
fontSize: 16,
141+
fontFamily: 'Arial',
142+
fontWeight: 'bold',
143+
color: 'white',
144+
backgroundColor: 'transparent',
145+
},
146+
textInput: {
147+
paddingHorizontal: 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
@@ -6,6 +6,7 @@ import Madoka from './Madoka';
66
import Akira from './Akira';
77
import Hideo from './Hideo';
88
import Kohana from './Kohana';
9+
import Makiko from './Makiko';
910

1011
export {
1112
Kaede,
@@ -16,4 +17,5 @@ export {
1617
Akira,
1718
Hideo,
1819
Kohana,
20+
Makiko,
1921
};

0 commit comments

Comments
 (0)