Last active
May 27, 2019 22:00
-
-
Save wildseansy/9194f74e9ca8b2ce7ec11e8aa8fa45ac to your computer and use it in GitHub Desktop.
Pinned left nav tabs
This file contains 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, | |
View, | |
Text, | |
TouchableOpacity, | |
SafeAreaView | |
} from 'react-native'; | |
import { Ionicons } from '@expo/vector-icons'; | |
class Tab extends React.PureComponent { | |
render() { | |
const { | |
isSelected, | |
tabIcon, | |
tabName, | |
onPress | |
} = this.props; | |
const color = isSelected ? '#EEE' : 'blue'; | |
const textStyles = {color, fontSize: 32, fontWeight: isSelected ? 'bold' : 'normal'}; | |
const containerStyles = { | |
flexDirection: 'row', | |
alignItems: 'center', | |
backgroundColor: isSelected ? 'blue' : '#EEE', | |
padding: 12 | |
} | |
return ( | |
<TouchableOpacity style={containerStyles} onPress={onPress}> | |
<Ionicons name={tabIcon} size={50} color={color} style={{width: 66, textAlign: 'center'}} /> | |
<Text style={textStyles}>{tabName}</Text> | |
</TouchableOpacity> | |
) | |
} | |
} | |
class LeftTabs extends React.PureComponent { | |
render() { | |
const { | |
tabs, | |
selectedTab, | |
onTabPressed, | |
width | |
} = this.props; | |
return ( | |
<SafeAreaView style={[styles.box, {width}]}> | |
{ | |
tabs.map(({tabName, tabIcon}) => { | |
return ( | |
<Tab | |
onPress={() => onTabPressed(tabName)} | |
key={tabName} | |
tabName={tabName} | |
tabIcon={tabIcon} | |
isSelected={selectedTab === tabName} /> | |
) | |
}) | |
} | |
</SafeAreaView> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
box: { | |
flex: -1, | |
minWidth: 140, | |
backgroundColor: '#eee', | |
height: '100%' | |
}, | |
}); | |
export default LeftTabs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment