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 | const LABEL_HEIGHT = 24;
|
14 | const PADDING = 16;
|
15 |
|
16 | export default class Sae extends BaseInput {
|
17 |
|
18 | static propTypes = {
|
19 | height: PropTypes.number,
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 | iconClass: PropTypes.func.isRequired,
|
26 | |
27 |
|
28 |
|
29 | iconName: PropTypes.string,
|
30 | |
31 |
|
32 |
|
33 |
|
34 | iconColor: PropTypes.string,
|
35 | };
|
36 |
|
37 | static defaultProps = {
|
38 | iconColor: 'white',
|
39 | height: 48,
|
40 | animationDuration: 300,
|
41 | iconName: 'pencil',
|
42 | };
|
43 |
|
44 | render() {
|
45 | const {
|
46 | iconClass,
|
47 | iconColor,
|
48 | iconName,
|
49 | label,
|
50 | style: containerStyle,
|
51 | height: inputHeight,
|
52 | inputStyle,
|
53 | labelStyle,
|
54 | } = this.props;
|
55 | const {
|
56 | width,
|
57 | focusedAnim,
|
58 | value,
|
59 | } = this.state;
|
60 | const AnimatedIcon = Animated.createAnimatedComponent(iconClass);
|
61 |
|
62 | return (
|
63 | <View
|
64 | style={[containerStyle, styles.container, {
|
65 | height: inputHeight + PADDING,
|
66 | }]}
|
67 | onLayout={this._onLayout}
|
68 | >
|
69 | <TouchableWithoutFeedback onPress={this._focus}>
|
70 | <Animated.View style={{
|
71 | position: 'absolute',
|
72 | bottom: focusedAnim.interpolate({
|
73 | inputRange: [0, 1],
|
74 | outputRange: [0, LABEL_HEIGHT + PADDING],
|
75 | }),
|
76 | }}>
|
77 | <Animated.Text style={[styles.label, labelStyle, {
|
78 | fontSize: focusedAnim.interpolate({
|
79 | inputRange: [0, 1],
|
80 | outputRange: [18, 12],
|
81 | }),
|
82 | }]}>
|
83 | {label}
|
84 | </Animated.Text>
|
85 | </Animated.View>
|
86 | </TouchableWithoutFeedback>
|
87 | <TextInput
|
88 | ref="input"
|
89 | {...this.props}
|
90 | style={[styles.textInput, inputStyle, {
|
91 | width,
|
92 | height: inputHeight,
|
93 | }]}
|
94 | value={value}
|
95 | onBlur={this._onBlur}
|
96 | onChange={this._onChange}
|
97 | onFocus={this._onFocus}
|
98 | underlineColorAndroid={'transparent'}
|
99 | />
|
100 | <AnimatedIcon
|
101 | name={iconName}
|
102 | color={iconColor}
|
103 | style={{
|
104 | position: 'absolute',
|
105 | bottom: 0,
|
106 | right: focusedAnim.interpolate({
|
107 | inputRange: [0, 1],
|
108 | outputRange: [0, width + PADDING],
|
109 | }),
|
110 | transform: [{
|
111 | rotate: focusedAnim.interpolate({
|
112 | inputRange: [0, 1],
|
113 | outputRange: ['0deg', '-90deg'],
|
114 | }),
|
115 | }],
|
116 | fontSize: 20,
|
117 | backgroundColor: 'transparent',
|
118 | }}
|
119 | />
|
120 | {}
|
121 | <Animated.View
|
122 | style={{
|
123 | position: 'absolute',
|
124 | bottom: 0,
|
125 | right: 0,
|
126 | height: 2,
|
127 | width: focusedAnim.interpolate({
|
128 | inputRange: [0, 1],
|
129 | outputRange: [0, width],
|
130 | }),
|
131 | backgroundColor: iconColor,
|
132 | }}
|
133 | />
|
134 | </View>
|
135 | );
|
136 | }
|
137 | }
|
138 |
|
139 | const styles = StyleSheet.create({
|
140 | container: {
|
141 | overflow: 'hidden',
|
142 | },
|
143 | label: {
|
144 | backgroundColor: 'transparent',
|
145 | fontFamily: 'Arial',
|
146 | fontWeight: 'bold',
|
147 | color: '#7771ab',
|
148 | },
|
149 | textInput: {
|
150 | position: 'absolute',
|
151 | bottom: 0,
|
152 | left: 0,
|
153 | paddingTop: PADDING / 2,
|
154 | paddingLeft: 0,
|
155 | color: 'white',
|
156 | fontSize: 18,
|
157 | },
|
158 | });
|