Skip to content

Commit 8af7551

Browse files
satya164ferrannp
authored andcommitted
fix: fix searchbar styles (callstack#110)
1 parent d117bb9 commit 8af7551

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

example/src/ExampleList.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import PaperExample from './PaperExample';
1313
import RippleExample from './RippleExample';
1414
import RadioButtonExample from './RadioButtonExample';
1515
import TextExample from './TextExample';
16-
import SearchExample from './SearchExample';
16+
import SearchBarExample from './SearchBarExample';
1717

1818
export const examples = {
1919
button: ButtonExample,
@@ -25,7 +25,7 @@ export const examples = {
2525
ripple: RippleExample,
2626
radio: RadioButtonExample,
2727
text: TextExample,
28-
search: SearchExample,
28+
searchbar: SearchBarExample,
2929
};
3030

3131
const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });

example/src/SearchExample.js renamed to example/src/SearchBarExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { Component } from 'react';
44
import { SearchBar } from 'react-native-paper';
55

66
export default class SearchExample extends Component {
7-
static title = 'Search';
7+
static title = 'Searchbar';
88

99
state = {
1010
query: '',

src/components/SearchBar.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import React, { Component } from 'react';
44
import PropTypes from 'prop-types';
55
import { StyleSheet, TextInput } from 'react-native';
66
import color from 'color';
7-
87
import withTheme from '../core/withTheme';
98
import Icon from './Icon';
109
import TouchableRipple from './TouchableRipple';
1110
import Paper from './Paper';
11+
import { white } from '../styles/colors';
1212
import type { Theme } from '../types/Theme';
1313

1414
type Props = {
1515
placeholder?: string,
1616
value: string,
1717
onChangeText: (query: string) => void,
1818
theme: Theme,
19+
style?: any,
1920
};
2021

2122
/**
@@ -36,38 +37,49 @@ class SearchBar extends Component<void, Props, void> {
3637
*/
3738
onChangeText: PropTypes.func.isRequired,
3839
theme: PropTypes.object.isRequired,
40+
style: Paper.propTypes.style,
3941
};
4042

4143
_handleClearPress = () => {
4244
this.props.onChangeText('');
4345
};
4446

4547
render() {
46-
const { placeholder, value, theme } = this.props;
48+
const { placeholder, value, theme, style, ...rest } = this.props;
49+
const { colors, roundness } = theme;
50+
const textColor = colors.text;
51+
const iconColor = color(textColor).alpha(0.54).rgbaString();
52+
const rippleColor = color(textColor).alpha(0.32).rgbaString();
4753

4854
return (
49-
<Paper elevation={4} style={styles.container}>
55+
<Paper
56+
elevation={4}
57+
style={[{ borderRadius: roundness }, styles.container, style]}
58+
>
5059
<Icon
51-
style={[styles.iconWrapper, styles.icon]}
60+
style={[styles.icon, { color: iconColor }]}
5261
name="search"
5362
size={24}
5463
/>
5564
<TextInput
56-
style={styles.input}
65+
style={[styles.input, { color: textColor }]}
5766
placeholder={placeholder || ''}
58-
value={value}
59-
placeholderTextColor={theme.colors.placeholder}
67+
placeholderTextColor={colors.placeholder}
6068
underlineColorAndroid="transparent"
61-
onChangeText={this.props.onChangeText}
6269
returnKeyType="search"
70+
{...rest}
6371
/>
6472
{value
6573
? <TouchableRipple
6674
borderless
75+
rippleColor={rippleColor}
6776
onPress={this._handleClearPress}
68-
style={styles.iconWrapper}
6977
>
70-
<Icon style={styles.icon} name="close" size={24} />
78+
<Icon
79+
style={[styles.icon, { color: iconColor }]}
80+
name="close"
81+
size={24}
82+
/>
7183
</TouchableRipple>
7284
: null}
7385
</Paper>
@@ -78,19 +90,16 @@ class SearchBar extends Component<void, Props, void> {
7890
const styles = StyleSheet.create({
7991
container: {
8092
flexDirection: 'row',
81-
justifyContent: 'center',
8293
alignItems: 'center',
83-
margin: 8,
94+
backgroundColor: white,
95+
margin: 4,
8496
},
8597
input: {
8698
flex: 1,
8799
fontSize: 18,
88100
},
89-
iconWrapper: {
90-
padding: 16,
91-
},
92101
icon: {
93-
color: color('black').alpha(0.54).rgbaString(),
102+
margin: 12,
94103
},
95104
});
96105

0 commit comments

Comments
 (0)