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

Commit bb1ea3f

Browse files
committed
Update defaults, add types, improve README, release new version
1 parent 7b32a8b commit bb1ea3f

File tree

7 files changed

+195
-11
lines changed

7 files changed

+195
-11
lines changed

README.md

Lines changed: 151 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,154 @@
11
# react-navigation-addon-search-layout
22

3-
Note: this currently depends on the Expo environment being present. I
4-
may fix this in the future, a PR is welcome though. It also only
5-
explicitly supports portrait mode, ymmv with landscape.
3+
A plain but perfectly acceptable search layout screen that looks good on
4+
iOS and Android.
65

7-
[Try it on Snack](https://snack.expo.io/HJXlZ7TuW)
6+
## Installation
7+
8+
```
9+
npm install react-navigation-addon-search-layout
10+
```
11+
12+
This requires that you have `react-native-vector-icons` installed in
13+
your project, it uses the `Ionicons` font family. If you use the Expo
14+
managed workflow, it will work out of the box as that comes preinstalled
15+
and is available through `@expo/vector-icons`'.
16+
17+
## Usage
18+
19+
Here's an example of how you can use this:
20+
21+
```js
22+
import * as React from 'react';
23+
import {
24+
Animated,
25+
Button,
26+
Platform,
27+
Text,
28+
StyleSheet,
29+
View,
30+
} from 'react-native';
31+
import {
32+
createAppContainer,
33+
createStackNavigator,
34+
StackViewTransitionConfigs,
35+
} from 'react-navigation';
36+
import { RectButton, BorderlessButton } from 'react-native-gesture-handler';
37+
import SearchLayout from 'react-navigation-addon-search-layout';
38+
import { Ionicons } from '@expo/vector-icons';
39+
40+
class HomeScreen extends React.Component {
41+
static navigationOptions = ({ navigation }) => ({
42+
title: 'Home',
43+
headerRight: (
44+
<BorderlessButton
45+
onPress={() => navigation.navigate('Search')}
46+
style={{ marginRight: 15 }}>
47+
<Ionicons
48+
name="md-search"
49+
size={Platform.OS === 'ios' ? 22 : 25}
50+
color={SearchLayout.DefaultTintColor}
51+
/>
52+
</BorderlessButton>
53+
),
54+
});
55+
56+
render() {
57+
return (
58+
<View style={styles.container}>
59+
<Text>Hello there!</Text>
60+
</View>
61+
);
62+
}
63+
}
64+
65+
class ResultScreen extends React.Component {
66+
static navigationOptions = {
67+
title: 'Result',
68+
};
69+
70+
render() {
71+
return (
72+
<View style={styles.container}>
73+
<Text>{this.props.navigation.getParam('text')} result!</Text>
74+
</View>
75+
);
76+
}
77+
}
78+
79+
class SearchScreen extends React.Component {
80+
static navigationOptions = {
81+
header: null,
82+
};
83+
84+
state = {
85+
searchText: null,
86+
};
87+
88+
_handleQueryChange = searchText => {
89+
this.setState({ searchText });
90+
};
91+
92+
_executeSearch = () => {
93+
alert('do search!');
94+
};
95+
96+
render() {
97+
let { searchText } = this.state;
98+
99+
return (
100+
<SearchLayout
101+
onChangeQuery={this._handleQueryChange}
102+
onSubmit={this._executeSearch}>
103+
{searchText ? (
104+
<RectButton
105+
style={{
106+
borderBottomWidth: StyleSheet.hairlineWidth,
107+
borderBottomColor: '#eee',
108+
paddingVertical: 20,
109+
paddingHorizontal: 15,
110+
}}
111+
onPress={() =>
112+
this.props.navigation.navigate('Result', {
113+
text: this.state.searchText,
114+
})
115+
}>
116+
<Text style={{ fontSize: 14 }}>{searchText}!</Text>
117+
</RectButton>
118+
) : null}
119+
</SearchLayout>
120+
);
121+
}
122+
}
123+
124+
let SearchStack = createStackNavigator(
125+
{
126+
Home: HomeScreen,
127+
Search: SearchScreen,
128+
},
129+
{
130+
transitionConfig: () => StackViewTransitionConfigs.NoAnimation,
131+
navigationOptions: {
132+
header: null,
133+
},
134+
defaultNavigationOptions: {
135+
gesturesEnabled: false,
136+
},
137+
}
138+
);
139+
140+
let MainStack = createStackNavigator({
141+
Feed: SearchStack,
142+
Result: ResultScreen,
143+
});
144+
145+
export default createAppContainer(MainStack);
146+
147+
const styles = StyleSheet.create({
148+
container: {
149+
flex: 1,
150+
alignItems: 'center',
151+
justifyContent: 'center',
152+
},
153+
});
154+
```

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
import SearchLayout from './src/SearchLayout';
2-
export default SearchLayout;
1+
export SearchLayout from './src/SearchLayout';

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "react-navigation-addon-search-layout",
3-
"version": "0.11.0",
3+
"version": "0.12.2",
44
"main": "index.js",
55
"license": "MIT",
6+
"types": "react-navigation-search-layout.d.ts",
67
"dependencies": {
78
"react-native-platform-touchable": "^1.1.1"
89
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
declare module 'react-navigation-addon-search-layout' {
2+
import * as React from 'react';
3+
4+
interface SearchLayoutProps {
5+
/** Callback that fires when the text in the search input is changed **/
6+
onChangeQuery: (query: string) => void;
7+
8+
/** Callback that fires when the user submits the input by pressing return **/
9+
onSubmit?: (query: string) => void;
10+
11+
/** Background color of the header that contains the search bar **/
12+
headerBackgroundColor?: string;
13+
14+
/** Tint color of the header that contains the search bar. Used to color the back buttoni on Android, the cancel button on iOS, and the color of and ripple around the clear button on Android **/
15+
headerTintColor?: string;
16+
17+
/** Color of the placeholder text that is visible when the user has not entered any input into the search box **/
18+
placeholderTextColor?: string;
19+
20+
/** Color of text that the user enters into the search box **/
21+
textColor?: string;
22+
23+
/** Underline color of the text input on Android **/
24+
searchInputUnderlineColorAndroid?: string;
25+
26+
/** Override headerTintColor for the cancel button / clear button **/
27+
searchInputTintColor?: string;
28+
29+
/** Alternative to using children to render the results **/
30+
renderResults?: () => React.ReactElement | null;
31+
}
32+
33+
export default class SearchLayout extends React.Component<SearchLayoutProps> {}
34+
}

src/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ let platformContainerStyles;
5858
if (Platform.OS === 'ios') {
5959
platformContainerStyles = {
6060
borderBottomWidth: StyleSheet.hairlineWidth,
61-
borderBottomColor: 'rgba(0, 0, 0, .3)',
61+
borderBottomColor: '#A7A7AA',
6262
};
6363
} else {
6464
platformContainerStyles = {

src/SearchBar.ios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export default class SearchBar extends React.PureComponent {
150150
fontSize: 17,
151151
color: this.props.tintColor || '#007AFF',
152152
}}>
153-
{this.props.cancelButtonText || 'Cancel'}}
153+
{this.props.cancelButtonText || 'Cancel'}
154154
</Text>
155155
</TouchableOpacity>
156156
</View>

src/SearchLayout.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { Platform, StyleSheet, Text, View } from 'react-native';
33
import SearchBar from './SearchBar';
44
import Header from './Header';
55

6+
const DEFAULT_TINT_COLOR = Platform.OS === 'ios' ? '#007AFF' : '#000';
7+
68
export default class SearchLayout extends React.Component {
79
static SearchBar = SearchBar;
810
static Header = Header;
11+
static DefaultTintColor = DEFAULT_TINT_COLOR;
912

1013
static defaultProps = {
1114
debounce: 500,
12-
headerBackgroundColor: Platform.OS === 'ios' ? '#f7f7f7' : '#fff',
13-
headerTintColor: '#000',
15+
headerBackgroundColor: '#fff',
16+
headerTintColor: DEFAULT_TINT_COLOR,
1417
};
1518

1619
state = {

0 commit comments

Comments
 (0)