Skip to content

Commit f062777

Browse files
committed
Refactor code
1 parent efbd556 commit f062777

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

lib/MaterialSearchBar.js

+37-31
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,37 @@ type State = {
2525

2626
class MaterialSearchBar extends React.Component<Props, State> {
2727
_textInput: TextInput
28-
static defaultProps = {}
28+
29+
static defaultProps = {
30+
containerStyle: {
31+
flexDirection: 'row',
32+
alignItems: 'center',
33+
backgroundColor: 'white',
34+
elevation: 8,
35+
paddingHorizontal: 12
36+
},
37+
styleInput: {
38+
flex: 1,
39+
height: 56,
40+
color: 'black',
41+
fontSize: 20,
42+
fontFamily: 'Roboto'
43+
},
44+
placeholderTextColor: 'grey'
45+
}
46+
47+
static propTypes = {
48+
/** Override the inline-styles of the root element */
49+
containerStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
50+
/** Override the inline-styles of the style input */
51+
styleInput: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
52+
/** The displayed search icon on the right of the input text */
53+
searchIcon: PropTypes.element,
54+
/** The displayed close icon on the right of the input text */
55+
closeIcon: PropTypes.element,
56+
/** A function to execute when field's value is changed */
57+
onChangeText: PropTypes.func.isRequired
58+
}
2959

3060
constructor(props: Props) {
3161
super(props)
@@ -42,7 +72,10 @@ class MaterialSearchBar extends React.Component<Props, State> {
4272
})
4373
}
4474

45-
doAnimation = () => {
75+
/**
76+
* Starts a sequenced animation on close/search button
77+
*/
78+
startAnimation = () => {
4679
Animated.sequence([
4780
Animated.timing(this.state.scale, {
4881
toValue: 1.2,
@@ -66,13 +99,13 @@ class MaterialSearchBar extends React.Component<Props, State> {
6699
}
67100

68101
if (this.state.value.length === 0) {
69-
this.doAnimation()
102+
this.startAnimation()
70103
}
71104
}
72105

73106
componentWillUpdate(nextProps: Props, nextState: State) {
74107
if (nextState.value.length === 0) {
75-
this.doAnimation()
108+
this.startAnimation()
76109
}
77110
}
78111

@@ -118,31 +151,4 @@ class MaterialSearchBar extends React.Component<Props, State> {
118151
}
119152
}
120153

121-
MaterialSearchBar.defaultProps = {
122-
containerStyle: {
123-
flexDirection: 'row',
124-
alignItems: 'center',
125-
backgroundColor: 'white',
126-
elevation: 8,
127-
paddingHorizontal: 12
128-
},
129-
styleInput: {
130-
flex: 1,
131-
height: 56,
132-
color: 'black',
133-
fontSize: 20,
134-
fontFamily: 'Roboto'
135-
},
136-
placeholderTextColor: 'grey'
137-
}
138-
139-
MaterialSearchBar.propTypes = {
140-
/** Override the inline-styles of the root element. */
141-
containerStyle: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
142-
styleInput: PropTypes.oneOfType([PropTypes.number, PropTypes.object]),
143-
searchIcon: PropTypes.element,
144-
closeIcon: PropTypes.element,
145-
onChangeText: PropTypes.func.isRequired
146-
}
147-
148154
export default MaterialSearchBar

0 commit comments

Comments
 (0)