UNPKG

3.68 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import {
4 Animated,
5 Easing,
6 Text,
7 TextInput,
8 TouchableWithoutFeedback,
9 View,
10 StyleSheet,
11} from 'react-native';
12
13import BaseInput from './BaseInput';
14
15export default class Kohana extends BaseInput {
16 static propTypes = {
17 /*
18 * This is the icon component you are importing from react-native-vector-icons.
19 * import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';
20 * iconClass={FontAwesomeIcon}
21 */
22 iconClass: PropTypes.func.isRequired,
23 /*
24 * Passed to react-native-vector-icons library as name prop
25 */
26 iconName: PropTypes.string.isRequired,
27 /*
28 * Passed to react-native-vector-icons library as color prop
29 */
30 iconColor: PropTypes.string,
31 /*
32 * Passed to react-native-vector-icons library as size prop.
33 */
34 iconSize: PropTypes.number,
35
36 inputPadding: PropTypes.number,
37 };
38
39 static defaultProps = {
40 easing: Easing.bezier(0.2, 1, 0.3, 1),
41 iconSize: 25,
42 inputPadding: 16,
43 useNativeDriver: false,
44 };
45
46 render() {
47 const {
48 iconClass: Icon,
49 iconColor,
50 iconSize,
51 iconName,
52 label,
53 style: containerStyle,
54 inputPadding,
55 inputStyle,
56 labelStyle,
57 iconContainerStyle,
58 labelContainerStyle,
59 } = this.props;
60 const { focusedAnim, value } = this.state;
61
62 return (
63 <View
64 style={[styles.container, containerStyle]}
65 onLayout={this._onLayout}
66 >
67 <TouchableWithoutFeedback onPress={this.focus}>
68 <Animated.View
69 style={{
70 justifyContent: 'center',
71 padding: inputPadding,
72 transform: [
73 {
74 translateX: focusedAnim.interpolate({
75 inputRange: [0, 1],
76 outputRange: [-15 - iconSize, 0],
77 }),
78 },
79 ],
80 ...iconContainerStyle,
81 }}
82 >
83 <Icon name={iconName} color={iconColor} size={iconSize} />
84 </Animated.View>
85 </TouchableWithoutFeedback>
86 <TouchableWithoutFeedback onPress={this.focus}>
87 <Animated.View
88 style={{
89 position: 'absolute',
90 top: inputPadding,
91 left: 0,
92 transform: [
93 {
94 translateX: focusedAnim.interpolate({
95 inputRange: [0, 1],
96 outputRange: [inputPadding, 80],
97 }),
98 },
99 ],
100 opacity: focusedAnim.interpolate({
101 inputRange: [0, 1],
102 outputRange: [1, 0],
103 }),
104 ...labelContainerStyle,
105 }}
106 >
107 <Text style={[styles.label, labelStyle]}>
108 {label}
109 </Text>
110 </Animated.View>
111 </TouchableWithoutFeedback>
112 <TextInput
113 ref={this.input}
114 {...this.props}
115 style={[styles.textInput, inputStyle, {
116 paddingHorizontal: inputPadding,
117 }]}
118 value={value}
119 onBlur={this._onBlur}
120 onFocus={this._onFocus}
121 onChange={this._onChange}
122 underlineColorAndroid={'transparent'}
123 />
124 </View>
125 );
126 }
127}
128
129const styles = StyleSheet.create({
130 container: {
131 flex: 1,
132 flexDirection: 'row',
133 backgroundColor: 'white',
134 overflow: 'hidden',
135 },
136 label: {
137 fontSize: 18,
138 fontWeight: 'bold',
139 color: '#D2D2D2',
140 },
141 textInput: {
142 flex: 1,
143 paddingVertical: 0,
144 color: 'black',
145 fontSize: 18,
146 },
147});