Created
July 8, 2018 19:15
-
-
Save bogoslavskiy/e2075c7efe19a3f7679ada37330cc89a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => props => ( | |
<SearchBar | |
animation={animation} | |
changeInputFocus={suggestionFocus => | |
this.setState({suggestionFocus}) | |
} | |
renderTabBar={() => ( | |
<TabBar | |
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) => | |
<View style={initialLayout}> | |
<TabView | |
style={styles.container} | |
navigationState={this.state} | |
renderScene={this._renderScene} | |
renderTabBar={this._renderHeader(animation)} | |
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 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment