Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import React from 'react';
  2. import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
  3. import { MaterialIcons } from '@expo/vector-icons';
  4. import styleConst from './../constants/Style';
  5.  
  6. export default class extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. }
  10.  
  11. getActiveScreen = function() {
  12. const route = this.props.navigation.state;
  13. const activeScreen = route.routes[route.index];
  14. return activeScreen.routeName;
  15. };
  16.  
  17. render() {
  18. const { navigation } = this.props;
  19. const activeScreen = this.getActiveScreen();
  20.  
  21. return (
  22. <View style={$$.wrap}>
  23. <Tab
  24. iconName="person"
  25. title="Profile"
  26. activeScreen={activeScreen}
  27. navigation={navigation}
  28. />
  29. <Tab
  30. iconName="store"
  31. title="Pickup"
  32. activeScreen={activeScreen}
  33. navigation={navigation}
  34. />
  35. <Tab
  36. iconName="directions-bike"
  37. title="Delivery"
  38. activeScreen={activeScreen}
  39. navigation={navigation}
  40. />
  41. </View>
  42. );
  43. }
  44. }
  45.  
  46. const Tab = ({ iconName, title, activeScreen, navigation }) => {
  47. const isActive = title === activeScreen;
  48. return (
  49. <View style={$$.tab}>
  50. <TouchableOpacity onPress={() => navigation.navigate(title)}>
  51. <View style={$$.tabButton}>
  52. <MaterialIcons
  53. name={iconName}
  54. size={24}
  55. color={isActive ? 'blue' : 'grey'}
  56. />
  57. <Text style={$$.tabTitle}>{title}</Text>
  58. </View>
  59. </TouchableOpacity>
  60. </View>
  61. );
  62. };
  63.  
  64. const $$ = StyleSheet.create({
  65. wrap: {
  66. display: 'flex',
  67. flexDirection: 'row',
  68. },
  69. tab: {
  70. flex: 1,
  71. display: 'flex',
  72. alignItems: 'center',
  73. },
  74. tabButton: {
  75. display: 'flex',
  76. alignItems: 'center',
  77. paddingVertical: 2,
  78. },
  79. tabTitle: {
  80. fontSize: 13,
  81. },
  82. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement