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

Commit 02338e8

Browse files
committed
Initial commit
0 parents  commit 02338e8

File tree

7 files changed

+465
-0
lines changed

7 files changed

+465
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# react-navigation-addon-search-layout
2+
3+
More documentation coming..
4+
5+
[Try it on Snack](https://snack.expo.io/BkkFRMa_Z)

index.js

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

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "react-navigation-addon-search-layout",
3+
"version": "0.5.1",
4+
"main": "index.js",
5+
"license": "MIT"
6+
}

src/Header.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import React from 'react';
2+
import { Animated, Platform, StyleSheet, View } from 'react-native';
3+
import { withNavigation, HeaderBackButton } from 'react-navigation';
4+
5+
const APPBAR_HEIGHT = Platform.OS === 'ios' ? 50 : 56;
6+
const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? 20 : 0;
7+
const TITLE_OFFSET = Platform.OS === 'ios' ? 70 : 56;
8+
9+
@withNavigation
10+
export default class Header extends React.PureComponent {
11+
static HEIGHT = APPBAR_HEIGHT + STATUSBAR_HEIGHT;
12+
13+
_navigateBack = () => {
14+
this.props.navigation.goBack(null);
15+
};
16+
17+
_maybeRenderBackButton = () => {
18+
if (!this.props.backButton) {
19+
return;
20+
}
21+
22+
return (
23+
<HeaderBackButton
24+
onPress={this._navigateBack}
25+
pressColorAndroid={this.props.tintColor || '#fff'}
26+
tintColor={this.props.tintColor}
27+
title={this.props.backButtonTitle || null}
28+
truncatedTitle={this.props.backButtonTruncatedTitle || null}
29+
titleStyle={this.props.backButtonTitleStyle || null}
30+
/>
31+
);
32+
};
33+
34+
render() {
35+
let headerStyle = {};
36+
if (this.props.backgroundColor) {
37+
headerStyle.backgroundColor = this.props.backgroundColor;
38+
}
39+
40+
return (
41+
<Animated.View style={[styles.container, headerStyle]}>
42+
<View style={styles.appBar}>
43+
<View style={[StyleSheet.absoluteFill, styles.header]}>
44+
{this._maybeRenderBackButton()}
45+
{this.props.children}
46+
</View>
47+
</View>
48+
</Animated.View>
49+
);
50+
}
51+
}
52+
53+
let platformContainerStyles;
54+
if (Platform.OS === 'ios') {
55+
platformContainerStyles = {
56+
borderBottomWidth: StyleSheet.hairlineWidth,
57+
borderBottomColor: 'rgba(0, 0, 0, .3)',
58+
};
59+
} else {
60+
platformContainerStyles = {
61+
shadowColor: 'black',
62+
shadowOpacity: 0.1,
63+
shadowRadius: StyleSheet.hairlineWidth,
64+
shadowOffset: {
65+
height: StyleSheet.hairlineWidth,
66+
},
67+
elevation: 4,
68+
};
69+
}
70+
71+
const styles = StyleSheet.create({
72+
container: {
73+
paddingTop: STATUSBAR_HEIGHT,
74+
backgroundColor: Platform.OS === 'ios' ? '#F7F7F7' : '#FFF',
75+
height: STATUSBAR_HEIGHT + APPBAR_HEIGHT,
76+
...platformContainerStyles,
77+
},
78+
appBar: {
79+
flex: 1,
80+
},
81+
header: {
82+
flexDirection: 'row',
83+
},
84+
item: {
85+
justifyContent: 'center',
86+
alignItems: 'center',
87+
backgroundColor: 'transparent',
88+
},
89+
title: {
90+
bottom: 0,
91+
left: TITLE_OFFSET,
92+
right: TITLE_OFFSET,
93+
top: 0,
94+
position: 'absolute',
95+
alignItems: Platform.OS === 'ios' ? 'center' : 'flex-start',
96+
},
97+
left: {
98+
left: 0,
99+
bottom: 0,
100+
top: 0,
101+
position: 'absolute',
102+
},
103+
right: {
104+
right: 0,
105+
bottom: 0,
106+
top: 0,
107+
position: 'absolute',
108+
},
109+
});

src/SearchBar.android.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import { NativeModules, StyleSheet, TextInput, View } from 'react-native';
3+
import { withNavigation } from 'react-navigation';
4+
5+
@withNavigation
6+
export default class SearchBar extends React.PureComponent {
7+
componentDidMount() {
8+
requestAnimationFrame(() => {
9+
this._textInput.focus();
10+
});
11+
}
12+
13+
state = {
14+
text: '',
15+
};
16+
17+
render() {
18+
let searchInputStyle = {};
19+
if (this.props.tintColor) {
20+
searchInputStyle.color = this.props.tintColor;
21+
}
22+
23+
return (
24+
<View style={styles.container}>
25+
<TextInput
26+
ref={view => {
27+
this._textInput = view;
28+
}}
29+
placeholder="Search"
30+
placeholderStyle={styles.searchPlaceholderText}
31+
value={this.state.text}
32+
autoCapitalize="none"
33+
autoCorrect={false}
34+
underlineColorAndroid={this.props.underlineColorAndroid || '#ccc'}
35+
onSubmitEditing={this._handleSubmit}
36+
onChangeText={this._handleChangeText}
37+
style={[styles.searchInput, searchInputStyle]}
38+
/>
39+
</View>
40+
);
41+
}
42+
43+
_handleChangeText = text => {
44+
this.setState({ text });
45+
this.props.onChangeQuery && this.props.onChangeQuery(text);
46+
};
47+
48+
_handleSubmit = () => {
49+
let { text } = this.state;
50+
this.props.onSubmit && this.props.onSubmit(text);
51+
this._textInput.blur();
52+
};
53+
}
54+
55+
const styles = StyleSheet.create({
56+
container: {
57+
flex: 1,
58+
flexDirection: 'row',
59+
},
60+
searchPlaceholderText: {
61+
color: '#fff',
62+
},
63+
searchInput: {
64+
flex: 1,
65+
fontSize: 18,
66+
marginBottom: 2,
67+
paddingLeft: 5,
68+
marginRight: 5,
69+
},
70+
});

0 commit comments

Comments
 (0)