Skip to content

Commit 1a61957

Browse files
committed
created BaseInput and Kaede
1 parent c078f72 commit 1a61957

File tree

4 files changed

+152
-22
lines changed

4 files changed

+152
-22
lines changed

Example/TextInputEffectsExample.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
import React, { Component } from 'react';
22
import {
3-
View,
3+
Dimensions,
4+
ScrollView,
45
StyleSheet,
56
} from 'react-native';
67

7-
import TextInputEffects from 'react-native-textinput-effects';
8+
import { Kaede } from 'react-native-textinput-effects';
9+
10+
const screenWidth = Dimensions.get('window').width;
811

912
export default class TextInputEffectsExample extends Component {
1013

1114
render() {
1215
return (
13-
<View style={styles.container}>
14-
<TextInputEffects />
15-
</View>
16+
<ScrollView style={styles.container} keyboardDismissMode={'on-drag'}>
17+
<Kaede
18+
placeholder={'First Name'}
19+
width={screenWidth}
20+
/>
21+
<Kaede
22+
placeholder={'Second Name'}
23+
width={screenWidth}
24+
/>
25+
</ScrollView>
1626
);
1727
}
1828
}
29+
1930
const styles = StyleSheet.create({
2031
container: {
2132
flex: 1,
22-
paddingTop: 54,
23-
paddingLeft: 16,
33+
paddingTop: 100,
34+
backgroundColor: '#F9F7F6',
2435
},
2536
});

lib/BaseInput.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React, {
2+
PropTypes,
3+
Component
4+
} from 'react';
5+
import {
6+
Animated,
7+
} from 'react-native';
8+
9+
export default class BaseInput extends Component {
10+
11+
static propTypes = {
12+
placeholder: PropTypes.string.isRequired,
13+
width: PropTypes.number.isRequired,
14+
};
15+
16+
constructor(props, context) {
17+
super(props, context);
18+
19+
this._onChange = this._onChange.bind(this);
20+
this._focus = this._focus.bind(this);
21+
this._blur = this._blur.bind(this);
22+
23+
this.currentText = '';
24+
this.state = {
25+
focusedAnim: new Animated.Value(0),
26+
};
27+
}
28+
29+
_onChange(event) {
30+
this.currentText = event.nativeEvent.text;
31+
}
32+
33+
_focus() {
34+
this._toggle(true);
35+
this.refs.input.focus();
36+
}
37+
38+
_blur() {
39+
if (!this.currentText) {
40+
this._toggle(false);
41+
}
42+
}
43+
44+
_toggle(displayed) {
45+
Animated.timing(
46+
this.state.focusedAnim, {
47+
toValue: displayed ? 1 : 0,
48+
duration: 300,
49+
},
50+
).start();
51+
}
52+
}

lib/Kaede.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
render() {
16+
const { placeholder, width } = this.props;
17+
const { focusedAnim } = this.state;
18+
const inputWidth = width * 0.6;
19+
20+
return (
21+
<View style={styles.container}>
22+
<Animated.View style={[styles.textInputContainer, {
23+
width: inputWidth,
24+
marginLeft: focusedAnim.interpolate({
25+
inputRange: [0, 1],
26+
outputRange: [inputWidth * -1, 0],
27+
}),
28+
}]}>
29+
<TextInput
30+
ref="input"
31+
style={styles.textInput}
32+
onBlur={this._blur}
33+
onChange={this._onChange}
34+
/>
35+
</Animated.View>
36+
<TouchableWithoutFeedback onPress={this._focus}>
37+
<Animated.View style={[styles.placeholderContainer, {
38+
width,
39+
marginRight: focusedAnim.interpolate({
40+
inputRange: [0, 1],
41+
outputRange: [0, inputWidth * -1],
42+
}),
43+
}]}>
44+
<Text style={styles.placeholder}>
45+
{placeholder}
46+
</Text>
47+
</Animated.View>
48+
</TouchableWithoutFeedback>
49+
</View>
50+
);
51+
}
52+
}
53+
54+
const styles = StyleSheet.create({
55+
container: {
56+
flex: 1,
57+
flexDirection: 'row',
58+
},
59+
placeholderContainer: {
60+
backgroundColor: '#EBEAEA',
61+
height: 62,
62+
},
63+
placeholder: {
64+
padding: 16,
65+
fontSize: 18,
66+
color: '#6a7989',
67+
},
68+
textInputContainer: {
69+
height: 62,
70+
backgroundColor: 'white',
71+
padding: 16,
72+
},
73+
textInput: {
74+
height: 30,
75+
color: 'black',
76+
fontSize: 18,
77+
},
78+
});

lib/index.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
1-
import React from 'react';
2-
import {
3-
Text,
4-
View,
5-
} from 'react-native';
1+
import Kaede from './Kaede';
62

7-
export default class TextInputEffects extends React.Component {
8-
9-
render() {
10-
return (
11-
<View>
12-
<Text>test</Text>
13-
</View>
14-
);
15-
}
16-
}
3+
export {
4+
Kaede,
5+
};

0 commit comments

Comments
 (0)