Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 33d3701

Browse files
committed
Add more props and a X to clear on android
1 parent 842fa27 commit 33d3701

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "react-navigation-addon-search-layout",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"main": "index.js",
5-
"license": "MIT"
5+
"license": "MIT",
6+
"dependencies": {
7+
"react-native-platform-touchable": "^1.1.1"
8+
}
69
}

src/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ if (Platform.OS === 'ios') {
7070

7171
const styles = StyleSheet.create({
7272
container: {
73+
backgroundColor: '#fff',
7374
paddingTop: STATUSBAR_HEIGHT,
74-
backgroundColor: Platform.OS === 'ios' ? '#F7F7F7' : '#FFF',
7575
height: STATUSBAR_HEIGHT + APPBAR_HEIGHT,
7676
...platformContainerStyles,
7777
},

src/SearchBar.android.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React from 'react';
22
import { NativeModules, StyleSheet, TextInput, View } from 'react-native';
33
import { withNavigation } from 'react-navigation';
4+
import Touchable from 'react-native-platform-touchable';
5+
6+
import { Icon } from 'expo';
47

58
@withNavigation
69
export default class SearchBar extends React.PureComponent {
@@ -16,8 +19,8 @@ export default class SearchBar extends React.PureComponent {
1619

1720
render() {
1821
let searchInputStyle = {};
19-
if (this.props.tintColor) {
20-
searchInputStyle.color = this.props.tintColor;
22+
if (this.props.textColor) {
23+
searchInputStyle.color = this.props.textColor;
2124
}
2225

2326
return (
@@ -31,15 +34,35 @@ export default class SearchBar extends React.PureComponent {
3134
value={this.state.text}
3235
autoCapitalize="none"
3336
autoCorrect={false}
37+
selectionColor={this.props.selectionColor}
3438
underlineColorAndroid={this.props.underlineColorAndroid || '#ccc'}
3539
onSubmitEditing={this._handleSubmit}
3640
onChangeText={this._handleChangeText}
3741
style={[styles.searchInput, searchInputStyle]}
3842
/>
43+
<View
44+
style={{ width: 50, alignItems: 'center', justifyContent: 'center' }}>
45+
{this.state.text
46+
? <Touchable
47+
onPress={this._handleClear}
48+
hitSlop={{top: 15, left: 10, right: 15, bottom: 15}}
49+
style={{ padding: 5 }}
50+
background={Touchable.Ripple(this.props.tintColor, true)}>
51+
<Icon.Ionicons
52+
name="md-close"
53+
size={25}
54+
color={this.props.tintColor}
55+
/>
56+
</Touchable>
57+
: null}
58+
</View>
3959
</View>
4060
);
4161
}
4262

63+
_handleClear = () => {
64+
this.setState({ text: '' });
65+
};
4366
_handleChangeText = text => {
4467
this.setState({ text });
4568
this.props.onChangeQuery && this.props.onChangeQuery(text);

src/SearchBar.ios.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class PlaceholderButtonSearchBar extends React.PureComponent {
4242
editable={false}
4343
placeholder="Search"
4444
placeholderTextColor={this.props.placeholderTextColor || '#ccc'}
45+
selectionColor={this.props.selectionColor}
4546
style={styles.searchInput}
4647
/>
4748

@@ -103,6 +104,10 @@ export default class SearchBar extends React.PureComponent {
103104

104105
render() {
105106
let { inputWidth, showCancelButton } = this.state;
107+
let searchInputStyle = {};
108+
if (this.props.textColor) {
109+
searchInputStyle.color = this.props.textColor;
110+
}
106111

107112
return (
108113
<View style={styles.container}>
@@ -120,7 +125,7 @@ export default class SearchBar extends React.PureComponent {
120125
placeholder="Search"
121126
placeholderTextColor={this.props.placeholderTextColor || '#ccc'}
122127
onSubmitEditing={this._handleSubmit}
123-
style={styles.searchInput}
128+
style={[styles.searchInput, searchInputStyle]}
124129
/>
125130

126131
<SearchIcon />

src/SearchLayout.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export default class SearchLayout extends React.Component {
1313

1414
static defaultProps = {
1515
debounce: 500,
16+
headerBackgroundColor: Platform.OS === 'ios' ? '#f7f7f7' : '#fff',
17+
headerTintColor: '#000',
1618
};
1719

1820
state = {
@@ -40,7 +42,12 @@ export default class SearchLayout extends React.Component {
4042
onChangeQuery={this._handleChangeQuery}
4143
onSubmit={this._handleSubmit}
4244
placeholderTextColor={this.props.searchInputPlaceholderTextColor}
43-
underlineColorAndroid={this.props.searchInputUnderlineColorAndroid}
45+
textColor={this.props.searchInputTextColor}
46+
selectionColor={this.props.searchInputSelectionColor}
47+
underlineColorAndroid={
48+
this.props.searchInputUnderlineColorAndroid ||
49+
this.props.headerBackgroundColor
50+
}
4451
tintColor={
4552
this.props.searchInputTintColor || this.props.headerTintColor
4653
}

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
react-native-platform-touchable@^1.1.1:
6+
version "1.1.1"
7+
resolved "https://registry.yarnpkg.com/react-native-platform-touchable/-/react-native-platform-touchable-1.1.1.tgz#fde4acc65eea585d28b164d0c3716a42129a68e4"

0 commit comments

Comments
 (0)