1 | import React from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import {
|
4 | Animated,
|
5 | Text,
|
6 | TextInput,
|
7 | TouchableWithoutFeedback,
|
8 | View,
|
9 | StyleSheet,
|
10 | } from 'react-native';
|
11 |
|
12 | import BaseInput from './BaseInput';
|
13 |
|
14 | export default class Akira extends BaseInput {
|
15 | static propTypes = {
|
16 | |
17 |
|
18 |
|
19 | borderColor: PropTypes.string,
|
20 | labelHeight: PropTypes.number,
|
21 | inputPadding: PropTypes.number,
|
22 | height: PropTypes.number,
|
23 | };
|
24 |
|
25 | static defaultProps = {
|
26 | borderColor: '#7A7593',
|
27 | labelHeight: 24,
|
28 | inputPadding: 16,
|
29 | height: 48,
|
30 | animationDuration: 200,
|
31 | };
|
32 |
|
33 | render() {
|
34 | const {
|
35 | label,
|
36 | style: containerStyle,
|
37 | height: inputHeight,
|
38 | labelHeight,
|
39 | inputPadding,
|
40 | inputStyle,
|
41 | labelStyle,
|
42 | borderColor,
|
43 | } = this.props;
|
44 | const {
|
45 | width,
|
46 | focusedAnim,
|
47 | value,
|
48 | } = this.state;
|
49 |
|
50 | return (
|
51 | <View style={containerStyle} onLayout={this._onLayout}>
|
52 | <TouchableWithoutFeedback onPress={this.focus}>
|
53 | <Animated.View
|
54 | style={{
|
55 | width,
|
56 | height: labelHeight,
|
57 | transform: [
|
58 | {
|
59 | translateY: focusedAnim.interpolate({
|
60 | inputRange: [0, 1],
|
61 | outputRange: [labelHeight + inputPadding, 0],
|
62 | }),
|
63 | },
|
64 | ],
|
65 | }}
|
66 | >
|
67 | <Text style={[styles.label, labelStyle]}>
|
68 | {label}
|
69 | </Text>
|
70 | </Animated.View>
|
71 | </TouchableWithoutFeedback>
|
72 | <TextInput
|
73 | ref={this.input}
|
74 | {...this.props}
|
75 | style={[
|
76 | styles.textInput,
|
77 | inputStyle,
|
78 | {
|
79 | width,
|
80 | height: inputHeight,
|
81 | paddingHorizontal: inputPadding,
|
82 | },
|
83 | ]}
|
84 | value={value}
|
85 | onBlur={this._onBlur}
|
86 | onChange={this._onChange}
|
87 | onFocus={this._onFocus}
|
88 | underlineColorAndroid={'transparent'}
|
89 | />
|
90 | {}
|
91 | <Animated.View
|
92 | style={{
|
93 | position: 'absolute',
|
94 | left: 0,
|
95 | bottom: 0,
|
96 | height: inputHeight,
|
97 | width: focusedAnim.interpolate({
|
98 | inputRange: [0, 1],
|
99 | outputRange: [6, 1],
|
100 | }),
|
101 | backgroundColor: borderColor,
|
102 | }}
|
103 | />
|
104 | {}
|
105 | <Animated.View
|
106 | style={{
|
107 | position: 'absolute',
|
108 | top: labelHeight,
|
109 | width,
|
110 | height: focusedAnim.interpolate({
|
111 | inputRange: [0, 1],
|
112 | outputRange: [6, 1],
|
113 | }),
|
114 | backgroundColor: borderColor,
|
115 | }}
|
116 | />
|
117 | {}
|
118 | <Animated.View
|
119 | style={{
|
120 | position: 'absolute',
|
121 | right: 0,
|
122 | bottom: 0,
|
123 | height: inputHeight,
|
124 | width: focusedAnim.interpolate({
|
125 | inputRange: [0, 1],
|
126 | outputRange: [6, 1],
|
127 | }),
|
128 | backgroundColor: borderColor,
|
129 | }}
|
130 | />
|
131 | {}
|
132 | <Animated.View
|
133 | style={{
|
134 | position: 'absolute',
|
135 | bottom: 0,
|
136 | height: focusedAnim.interpolate({
|
137 | inputRange: [0, 1],
|
138 | outputRange: [6, 1],
|
139 | }),
|
140 | width,
|
141 | backgroundColor: borderColor,
|
142 | }}
|
143 | />
|
144 | </View>
|
145 | );
|
146 | }
|
147 | }
|
148 |
|
149 | const styles = StyleSheet.create({
|
150 | label: {
|
151 | backgroundColor: 'transparent',
|
152 | fontSize: 14,
|
153 | fontWeight: 'bold',
|
154 | color: '#cc6055',
|
155 | textAlign: 'center',
|
156 | },
|
157 | textInput: {
|
158 | padding: 0,
|
159 | color: 'black',
|
160 | fontSize: 18,
|
161 | textAlign: 'center',
|
162 | },
|
163 | });
|