|
1 | 1 | /* @flow */ |
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | | -import React, {Text, View, TextInput } from 'react-native'; |
| 4 | +import React, {Text, View, TextInput, PixelRatio } from 'react-native'; |
5 | 5 | import NativeBaseComponent from '../Base/NativeBaseComponent'; |
6 | 6 | import Icon from 'react-native-vector-icons/Ionicons'; |
7 | 7 | import _ from 'lodash'; |
8 | 8 | import computeProps from '../../Utils/computeProps'; |
9 | | -import Input from './Input' |
| 9 | +import Input from './Input'; |
| 10 | +import InputLabel from './InputLabel'; |
10 | 11 |
|
11 | 12 |
|
12 | 13 | export default class IconInput extends NativeBaseComponent { |
13 | 14 |
|
14 | | - getInitialStyle() { |
15 | | - return { |
16 | | - textInput: { |
17 | | - height: 40, |
18 | | - backgroundColor: 'transparent', |
19 | | - }, |
20 | | - outerBorder: { |
21 | | - position:'relative', |
22 | | - borderColor: 'white', |
23 | | - borderWidth: 1 / PixelRatio.get(), |
24 | | - borderTopWidth: 0, |
25 | | - borderRightWidth: 0, |
26 | | - borderLeftWidth: 0, |
27 | | - margin: 15, |
28 | | - marginTop: 5 |
29 | | - }, |
30 | | - darkborder: { |
31 | | - borderColor: '#000', |
32 | | - }, |
33 | | - lightborder: { |
34 | | - borderColor: '#fff', |
35 | | - }, |
36 | | - underline: { |
37 | | - position:'relative', |
38 | | - borderWidth: 1 / PixelRatio.get(), |
39 | | - borderTopWidth: 0, |
40 | | - borderRightWidth: 0, |
41 | | - borderLeftWidth: 0, |
42 | | - margin: 15, |
43 | | - marginTop: 5 |
44 | | - }, |
45 | | - |
46 | | - bordered: { |
47 | | - position:'relative', |
48 | | - borderWidth: 1 / PixelRatio.get(), |
49 | | - margin: 15, |
50 | | - marginTop: 5 |
51 | | - }, |
52 | | - |
53 | | - rounded: { |
54 | | - position:'relative', |
55 | | - borderWidth: 1 / PixelRatio.get(), |
56 | | - borderRadius: 30, |
57 | | - margin: 15, |
58 | | - marginTop: 5 |
59 | | - } |
60 | | - } |
| 15 | + getInitialStyle() { |
| 16 | + return { |
| 17 | + textInput: { |
| 18 | + height: 40, |
| 19 | + backgroundColor: 'transparent', |
| 20 | + }, |
| 21 | + outerBorder: { |
| 22 | + position:'relative', |
| 23 | + borderColor: 'white', |
| 24 | + borderWidth: 1 / PixelRatio.get(), |
| 25 | + borderTopWidth: 0, |
| 26 | + borderRightWidth: 0, |
| 27 | + borderLeftWidth: 0, |
| 28 | + margin: 15, |
| 29 | + marginTop: 5 |
| 30 | + }, |
| 31 | + darkborder: { |
| 32 | + borderColor: '#000', |
| 33 | + }, |
| 34 | + lightborder: { |
| 35 | + borderColor: '#fff', |
| 36 | + }, |
| 37 | + underline: { |
| 38 | + position:'relative', |
| 39 | + borderWidth: 1 / PixelRatio.get(), |
| 40 | + borderTopWidth: 0, |
| 41 | + borderRightWidth: 0, |
| 42 | + borderLeftWidth: 0, |
| 43 | + margin: 15, |
| 44 | + marginTop: 5 |
| 45 | + }, |
| 46 | + |
| 47 | + bordered: { |
| 48 | + position:'relative', |
| 49 | + borderWidth: 1 / PixelRatio.get(), |
| 50 | + margin: 15, |
| 51 | + marginTop: 5 |
| 52 | + }, |
| 53 | + |
| 54 | + rounded: { |
| 55 | + position:'relative', |
| 56 | + borderWidth: 1 / PixelRatio.get(), |
| 57 | + borderRadius: 30, |
| 58 | + margin: 15, |
| 59 | + marginTop: 5 |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + prepareRootProps() { |
| 65 | + |
| 66 | + var type = { |
| 67 | + paddingLeft: (this.props.borderType === 'rounded' && !this.props.children.type == Icon) ? 15 : |
| 68 | + (this.props.children.type == Icon) ? this.getTheme().inputPaddingLeftIcon : this.getTheme().inputPaddingLeft |
| 69 | + } |
| 70 | + |
| 71 | + |
| 72 | + var addedProps = _.merge(this.getInitialStyle().textInput,type); |
| 73 | + |
| 74 | + var defaultProps = { |
| 75 | + style: addedProps |
| 76 | + } |
| 77 | + |
| 78 | + console.log("input style", computeProps(this.props, defaultProps)); |
| 79 | + |
| 80 | + return computeProps(this.props, defaultProps); |
| 81 | + |
| 82 | + } |
| 83 | + renderLabel() { |
| 84 | + if(!Array.isArray(this.props.children) && this.props.children.type == InputLabel) |
| 85 | + return this.props.children; |
| 86 | + |
| 87 | + else |
| 88 | + return _.find(this.props.children, function(item) { |
| 89 | + if(item && item.type == InputLabel) { |
| 90 | + return true; |
| 91 | + } |
| 92 | + }); |
| 93 | + } |
| 94 | + |
| 95 | + renderIcon() { |
| 96 | + if(!Array.isArray(this.props.children) && this.props.children.type == Icon) |
| 97 | + return this.props.children; |
| 98 | + |
| 99 | + else |
| 100 | + return _.find(this.props.children, function(item) { |
| 101 | + if(item && item.type == Icon) { |
| 102 | + return true; |
| 103 | + } |
| 104 | + }); |
| 105 | + } |
| 106 | + |
| 107 | + renderInput() { |
| 108 | + if(!Array.isArray(this.props.children) && this.props.children.type == Input) { |
| 109 | + console.log(11111); |
| 110 | + var inputProps = {}; |
| 111 | + |
| 112 | + inputProps = computeProps(this.props, this.props.children.props); |
| 113 | + |
| 114 | + return <Input {...inputProps}/> |
61 | 115 | } |
62 | 116 |
|
63 | | - prepareRootProps() { |
64 | | - |
65 | | - var type = { |
66 | | - paddingLeft: (this.props.borderType === 'rounded' && !this.props.children.type == Icon) ? 15 : |
67 | | - (this.props.children.type == Icon) ? inputPaddingLeftIcon : inputPaddingLeft |
68 | | - } |
69 | | - |
70 | | - |
71 | | - var addedProps = _.merge(this.getInitialStyle().textInput,type); |
72 | | - |
73 | | - var defaultProps = { |
74 | | - style: addedProps |
75 | | - } |
76 | | - |
77 | | - console.log("input style", computeProps(this.props, defaultProps)); |
78 | | - |
79 | | - return computeProps(this.props, defaultProps); |
80 | | - |
81 | | - } |
82 | | - renderLabel() { |
83 | | - if(!Array.isArray(this.props.children) && this.props.children.type == Text) |
84 | | - return this.props.children; |
85 | | - |
86 | | - else |
87 | | - return _.find(this.props.children, function(item) { |
88 | | - if(item && item.type == Text) { |
89 | | - return true; |
90 | | - } |
91 | | - }); |
92 | | - } |
93 | | - |
94 | | - renderIcon() { |
95 | | - if(!Array.isArray(this.props.children) && this.props.children.type == Icon) |
96 | | - return this.props.children; |
97 | | - |
98 | | - else |
99 | | - return _.find(this.props.children, function(item) { |
100 | | - if(item && item.type == Icon) { |
101 | | - return true; |
102 | | - } |
103 | | - }); |
104 | | - } |
105 | | - |
106 | | - renderInput() { |
107 | | - if(!Array.isArray(this.props.children) && this.props.children.type == Input) { |
108 | | - var inputProps = {}; |
109 | | - |
110 | | - inputProps = computeProps(this.props, this.props.children.props); |
111 | | - |
112 | | - return <Input {...inputProps}/> |
113 | | - } |
114 | | - |
115 | | - else { |
116 | | - var inp = _.find(this.props.children, function(item) { |
117 | | - if(item && item.type == Input) { |
118 | | - return true; |
119 | | - } |
120 | | - }); |
121 | | - |
122 | | - var inputProps = {}; |
123 | | - |
124 | | - inputProps = computeProps(this.props, inp.props); |
125 | | - |
126 | | - return <Input {...inputProps}/> |
127 | | - } |
| 117 | + else { |
| 118 | + console.log(2222); |
| 119 | + var inp = _.find(this.props.children, function(item) { |
| 120 | + if(item && item.type == Input) { |
| 121 | + return true; |
| 122 | + } |
| 123 | + }); |
| 124 | + console.log(this.props.children, "awaw909000990909"); |
| 125 | + |
| 126 | + var inputProps = {}; |
| 127 | + |
| 128 | + if(inp) |
| 129 | + inputProps = computeProps(this.props, inp.props); |
| 130 | + else |
| 131 | + inputProps = this.props; |
| 132 | + |
| 133 | + return <Input {...inputProps}/> |
128 | 134 | } |
| 135 | + } |
129 | 136 |
|
130 | | - render() { |
131 | | - return ( |
132 | | - <View {...this.prepareRootProps()} style={[(this.props.borderType === 'regular') ? this.getInitialStyle().bordered : (this.props.borderType === 'rounded') ? this.getInitialStyle().rounded : this.getInitialStyle().underline]} > |
| 137 | + render() { |
| 138 | + return ( |
| 139 | + <View {...this.prepareRootProps()} style={[(this.props.borderType === 'regular') ? this.getInitialStyle().bordered : (this.props.borderType === 'rounded') ? this.getInitialStyle().rounded : this.getInitialStyle().underline]} > |
133 | 140 |
|
134 | | - {this.renderIcon()} |
135 | | - {this.renderLabel()} |
136 | | - {this.renderInput()} |
137 | | - </View> |
138 | | - ); |
| 141 | + {this.renderIcon()} |
| 142 | + {this.renderLabel()} |
| 143 | + {this.renderInput()} |
| 144 | + </View> |
| 145 | + ); |
139 | 146 | } |
140 | 147 |
|
141 | 148 | } |
|
0 commit comments