forked from bogoslavskiy/rn-search-bar-animation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
139 lines (126 loc) · 3.52 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Created by Artem Bogoslavskiy on 7/5/18.
import React from 'react';
import { StyleSheet, Dimensions, Animated, View, Platform, StatusBar } from 'react-native';
import { TabView, TabBar, SceneMap } from 'react-native-tab-view';
import { SearchBarProvider } from './searchBarAnimation';
import SearchBar from './components/SearchBar';
import Tab from './tabs/Tab';
import SearchBarSuggestion from './components/SearchBarSuggestion';
import SearchBarLocationSuggestion from './components/SearchBarLocationSuggestion';
const initialLayout = {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height
};
export default class SeachScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
index: 0,
currentTab: 'tab1',
routes: [
{ key: 'tab1', title: 'Tab 1' },
{ key: 'tab2', title: 'Tab 2' }
],
};
}
_handleIndexChange = index => {
this.setState({
currentTab: this.state.routes[index].key,
index
});
}
_getLabelText = ({ route }) => route.title;
_renderHeader = (animation, canJumpToTab) => props => (
<SearchBar
animation={animation}
changeInputFocus={suggestionFocus =>
this.setState({suggestionFocus})
}
renderTabBar={() => (
<TabBar
onTabPress={({route}) => {
if(route.key != this.state.currentTab && canJumpToTab) {
animation.onTabPress(route);
}
}}
getLabelText={this._getLabelText}
indicatorStyle={styles.indicator}
style={styles.tabbar}
labelStyle={styles.label}
{...props}
/>
)}
/>
);
_renderScene = SceneMap({
tab1: Tab,
tab2: Tab
});
_renderSuggestion(animation) {
let focus = this.state.suggestionFocus;
if(focus) {
let styleAnimation = animation.getStyleSuggestion();
let Suggestion = (focus == 'location') ?
SearchBarLocationSuggestion :
SearchBarSuggestion;
return (
<Animated.View style={[initialLayout, styles.suggestionWrap, styleAnimation]}>
<Suggestion />
</Animated.View>
);
}
}
render() {
return (
<SearchBarProvider currentTab={this.state.currentTab}>
{(animation, { canJumpToTab }) =>
<View style={initialLayout}>
{Platform.OS === 'android' &&
<StatusBar
translucent={true}
backgroundColor="transparent"
/>
}
<TabView
style={styles.container}
navigationState={this.state}
renderScene={this._renderScene}
renderTabBar={this._renderHeader(animation, canJumpToTab)}
onIndexChange={this._handleIndexChange}
initialLayout={initialLayout}
swipeEnabled={false} // TODO ...
canJumpToTab={() => canJumpToTab}
useNativeDriver
/>
{this._renderSuggestion(animation)}
</View>
}
</SearchBarProvider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#edeef0'
},
tabbar: {
backgroundColor: '#fff',
elevation: 0
},
indicator: {
backgroundColor: '#45688e'
},
label: {
color: '#45688e',
margin: 0,
marginTop: 6,
marginBottom: 6,
fontWeight: '400'
},
suggestionWrap: {
position: 'absolute',
backgroundColor: '#fff',
zIndex: 3
}
});