UNPKG

2.76 kBJavaScriptView Raw
1import React, { PropTypes, Component } from 'react';
2import {
3 Animated,
4 TextInput,
5 TouchableWithoutFeedback,
6 View,
7 StyleSheet,
8} from 'react-native';
9
10import BaseInput from './BaseInput';
11
12export default class Hideo extends BaseInput {
13
14 static propTypes = {
15 /*
16 * this is applied as background color of icon
17 */
18 iconBackgroundColor: PropTypes.string,
19
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 * Passed to react-native-vector-icons library as name prop
28 */
29 iconName: PropTypes.string.isRequired,
30 /*
31 * Passed to react-native-vector-icons library as color prop
32 */
33 iconColor: PropTypes.string,
34 };
35
36 static defaultProps = {
37 iconColor: 'white',
38 iconBackgroundColor: '#899dda',
39 height: 48,
40 animationDuration: 200,
41 };
42
43 render() {
44 const {
45 iconClass,
46 iconColor,
47 iconName,
48 iconBackgroundColor,
49 style: containerStyle,
50 inputStyle,
51 height: inputHeight,
52 } = this.props;
53 const {
54 focusedAnim,
55 value,
56 } = this.state;
57 const AnimatedIcon = Animated.createAnimatedComponent(iconClass);
58
59 return (
60 <View style={[containerStyle, styles.container]} onLayout={this._onLayout}>
61 <TouchableWithoutFeedback onPress={this._focus}>
62 <Animated.View style={{
63 backgroundColor: iconBackgroundColor,
64 justifyContent: 'center',
65 alignItems: 'center',
66 height: inputHeight,
67 width: focusedAnim.interpolate({
68 inputRange: [0, 1],
69 outputRange: [60, 40],
70 }),
71 }}>
72 <AnimatedIcon
73 name={iconName}
74 color={iconColor}
75 style={{
76 fontSize: focusedAnim.interpolate({
77 inputRange: [0, 1],
78 outputRange: [25, 15],
79 }),
80 }}
81 />
82 </Animated.View>
83 </TouchableWithoutFeedback>
84 <TextInput
85 ref="input"
86 {...this.props}
87 style={[styles.textInput, inputStyle]}
88 value={value}
89 onBlur={this._onBlur}
90 onChange={this._onChange}
91 onFocus={this._onFocus}
92 underlineColorAndroid={'transparent'}
93 />
94 </View>
95 );
96 }
97}
98
99const styles = StyleSheet.create({
100 container: {
101 flex: 1,
102 flexDirection: 'row',
103 },
104 textInput: {
105 flex: 1,
106 paddingHorizontal: 16,
107 paddingVertical: 0,
108 color: 'black',
109 backgroundColor: 'white',
110 fontSize: 18,
111 },
112});