Skip to content

Commit 44531c6

Browse files
committed
created Hoshi
1 parent 1bd36e5 commit 44531c6

File tree

5 files changed

+146
-7
lines changed

5 files changed

+146
-7
lines changed

Example/TextInputEffectsExample.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {
44
StyleSheet,
55
} from 'react-native';
66

7-
import { Kaede } from 'react-native-textinput-effects';
7+
import {
8+
Kaede,
9+
Hoshi,
10+
} from 'react-native-textinput-effects';
811

912
export default class TextInputEffectsExample extends Component {
1013

@@ -13,21 +16,24 @@ export default class TextInputEffectsExample extends Component {
1316
<ScrollView style={styles.container} keyboardDismissMode={'on-drag'}>
1417
<Kaede
1518
label={'Name'}
16-
value={'halil'}
1719
/>
1820
<Kaede
1921
label={'Number'}
20-
style={{ marginTop: 8 }}
2122
labelStyle={{
22-
color: 'red',
23-
backgroundColor: 'yellow',
23+
color: '#990fe2',
24+
backgroundColor: '#f5f785',
2425
}}
2526
inputStyle={{
2627
color: 'white',
27-
backgroundColor: 'grey',
28+
backgroundColor: '#d693f9',
2829
}}
2930
keyboardType="numeric"
3031
/>
32+
<Hoshi
33+
label={'Street'}
34+
backgroundColor={'#F9F7F6'}
35+
borderColor={'#00ffaa'}
36+
/>
3137
</ScrollView>
3238
);
3339
}

lib/BaseInput.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class BaseInput extends Component {
2222
* so, i'm calling them manually
2323
*/
2424
onBlur: PropTypes.func,
25+
onFocus: PropTypes.func,
2526
onChange: PropTypes.func,
2627
};
2728

@@ -31,6 +32,7 @@ export default class BaseInput extends Component {
3132
this._onLayout = this._onLayout.bind(this);
3233
this._onChange = this._onChange.bind(this);
3334
this._onBlur = this._onBlur.bind(this);
35+
this._onFocus = this._onFocus.bind(this);
3436
this._focus = this._focus.bind(this);
3537

3638
this.state = {
@@ -67,8 +69,16 @@ export default class BaseInput extends Component {
6769
}
6870
}
6971

70-
_focus() {
72+
_onFocus(event) {
7173
this._toggle(true);
74+
75+
const onFocus = this.props.onFocus;
76+
if (onFocus) {
77+
onFocus(event);
78+
}
79+
}
80+
81+
_focus() {
7282
this.refs.input.focus();
7383
}
7484

lib/Hoshi.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
export default class Kaede extends BaseInput {
14+
15+
static propTypes = {
16+
borderColor: PropTypes.string,
17+
18+
/*
19+
* this is used to set backgroundColor of label mask.
20+
* this should be replaced if we can find a better way to mask label animation.
21+
*/
22+
backgroundColor: PropTypes.string,
23+
};
24+
25+
static defaultProps = {
26+
borderColor: 'red',
27+
};
28+
29+
render() {
30+
const {
31+
label,
32+
style: containerStyle,
33+
inputStyle,
34+
labelStyle,
35+
backgroundColor: maskColor,
36+
borderColor,
37+
} = this.props;
38+
const {
39+
width,
40+
focusedAnim,
41+
value,
42+
} = this.state;
43+
44+
return (
45+
<View style={[containerStyle, styles.container, { height: 60 }]} onLayout={this._onLayout}>
46+
<TextInput
47+
ref="input"
48+
{...this.props}
49+
style={[styles.textInput, inputStyle, { width, height: 30 }]}
50+
value={value}
51+
onBlur={this._onBlur}
52+
onChange={this._onChange}
53+
onFocus={this._onFocus}
54+
/>
55+
<TouchableWithoutFeedback onPress={this._focus}>
56+
<Animated.View style={[styles.labelContainer, {
57+
opacity: focusedAnim.interpolate({
58+
inputRange: [0, 0.5, 1],
59+
outputRange: [1, 0, 1],
60+
}),
61+
top: focusedAnim.interpolate({
62+
inputRange: [0, 0.5, 0.51, 1],
63+
outputRange: [24, 24, 0, 0],
64+
}),
65+
left: focusedAnim.interpolate({
66+
inputRange: [0, 0.5, 0.51, 1],
67+
outputRange: [16, 32, 0, 16],
68+
}),
69+
}]}>
70+
<Text style={[styles.label, labelStyle]}>
71+
{label}
72+
</Text>
73+
</Animated.View>
74+
</TouchableWithoutFeedback>
75+
<View style={[styles.labelMask, { backgroundColor: maskColor }]} />
76+
<Animated.View
77+
style={[styles.border, {
78+
width: focusedAnim.interpolate({
79+
inputRange: [0, 1],
80+
outputRange: [0, width],
81+
}),
82+
backgroundColor: borderColor,
83+
}]}
84+
/>
85+
</View>
86+
);
87+
}
88+
}
89+
90+
const styles = StyleSheet.create({
91+
container: {
92+
flex: 1,
93+
borderBottomWidth: 2,
94+
},
95+
labelContainer: {
96+
position: 'absolute',
97+
},
98+
label: {
99+
fontSize: 18,
100+
color: '#6a7989',
101+
},
102+
textInput: {
103+
position: 'absolute',
104+
bottom: 8,
105+
left: 16,
106+
color: 'black',
107+
fontSize: 18,
108+
},
109+
labelMask: {
110+
height: 24,
111+
width: 16,
112+
},
113+
border: {
114+
position: 'absolute',
115+
bottom: 0,
116+
left: 0,
117+
right: 0,
118+
height: 3,
119+
},
120+
});

lib/Kaede.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default class Kaede extends BaseInput {
3737
style={[styles.textInput, inputStyle]}
3838
value={value}
3939
onBlur={this._onBlur}
40+
onFocus={this._onFocus}
4041
onChange={this._onChange}
4142
/>
4243
</Animated.View>

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Kaede from './Kaede';
2+
import Hoshi from './Hoshi';
23

34
export {
45
Kaede,
6+
Hoshi,
57
};

0 commit comments

Comments
 (0)