1 | import React from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import {
|
4 | Animated,
|
5 | Easing,
|
6 | Text,
|
7 | TextInput,
|
8 | TouchableWithoutFeedback,
|
9 | View,
|
10 | StyleSheet,
|
11 | } from 'react-native';
|
12 |
|
13 | import BaseInput from './BaseInput';
|
14 |
|
15 | export default class Kohana extends BaseInput {
|
16 | static propTypes = {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | iconClass: PropTypes.func.isRequired,
|
23 | |
24 |
|
25 |
|
26 | iconName: PropTypes.string.isRequired,
|
27 | |
28 |
|
29 |
|
30 | iconColor: PropTypes.string,
|
31 | |
32 |
|
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 |
|
129 | const 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 | });
|