1
1
import React , { PureComponent } from 'react' ;
2
2
import autoBindReact from 'auto-bind/react' ;
3
- import _ from 'lodash' ;
4
3
import PropTypes from 'prop-types' ;
5
4
import { TextInput as RNTextInput } from 'react-native' ;
6
5
@@ -10,16 +9,6 @@ import { connectStyle } from '@shoutem/theme';
10
9
import { Caption } from './Text' ;
11
10
import { View } from './View' ;
12
11
13
- // Style properties defined in theme which would case a warning if passed to a components style prop
14
- const omittedStyleProperties = [
15
- 'errorBorder' ,
16
- 'placeholderTextColor' ,
17
- 'selectionColor' ,
18
- 'underlineColorAndroid' ,
19
- 'withBorder' ,
20
- 'withoutBorder' ,
21
- ] ;
22
-
23
12
class TextInput extends PureComponent {
24
13
constructor ( props ) {
25
14
super ( props ) ;
@@ -40,23 +29,40 @@ class TextInput extends PureComponent {
40
29
}
41
30
42
31
render ( ) {
43
- const { errorMessage, highlightOnFocus, style } = this . props ;
32
+ const {
33
+ errorMessage,
34
+ highlightOnFocus,
35
+ style,
36
+ ...otherProps
37
+ } = this . props ;
44
38
const { isFocused } = this . state ;
45
39
40
+ const {
41
+ errorBorderColor,
42
+ placeholderTextColor,
43
+ selectionColor,
44
+ underlineColorAndroid,
45
+ withBorder,
46
+ withoutBorder,
47
+ ...otherStyle
48
+ } = style ;
49
+
50
+ const hasBorder = ( isFocused && highlightOnFocus ) || ! ! errorMessage ;
51
+
46
52
return (
47
53
< View >
48
54
< RNTextInput
49
- { ..._ . omit ( this . props , 'style' ) }
55
+ { ...otherProps }
50
56
onBlur = { this . handleBlur }
51
57
onFocus = { this . handleFocus }
52
58
placeholderTextColor = { style . placeholderTextColor }
53
59
selectionColor = { style . selectionColor }
54
60
underlineColorAndroid = { style . underlineColorAndroid }
55
- style = { [
56
- _ . omit ( style , omittedStyleProperties ) ,
57
- ( isFocused && highlightOnFocus ) ? style . withBorder : style . withoutBorder ,
58
- ! ! errorMessage && style . errorBorder ,
59
- ] }
61
+ style = { {
62
+ ... otherStyle ,
63
+ ... ( hasBorder ? style . withBorder : style . withoutBorder ) ,
64
+ ... ( ! ! errorMessage ? style . errorBorderColor : { } ) ,
65
+ } }
60
66
/>
61
67
{ ! ! errorMessage &&
62
68
< Caption styleName = "form-error sm-gutter-top" >
0 commit comments