main_tab_navigation.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React, {Component} from 'react';
  2. import {StyleSheet, View, Text, TouchableOpacity} from 'react-native';
  3. import {NavigationContainer} from '@react-navigation/native';
  4. import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
  5. import home_navigation from './home_navigation';
  6. import personal_navigation from './personal_navigation';
  7. import {RetrieveData} from '../../data/storage';
  8. import message_list from '../../page/tax_message/message_list';
  9. import tax_navigation from './tax_navigation';
  10. function MyTabBar({state, descriptors, navigation}) {
  11. return (
  12. <View style={{flexDirection: 'row'}}>
  13. {state.routes.map((route, index) => {
  14. const {options} = descriptors[route.key];
  15. const label =
  16. options.tabBarLabel !== undefined
  17. ? options.tabBarLabel
  18. : options.title !== undefined
  19. ? options.title
  20. : route.name;
  21. const isFocused = state.index === index;
  22. const onPress = () => {
  23. const event = navigation.emit({
  24. type: 'tabPress',
  25. target: route.key,
  26. });
  27. if (!isFocused && !event.defaultPrevented) {
  28. navigation.navigate(route.name);
  29. }
  30. };
  31. const onLongPress = () => {
  32. navigation.emit({
  33. type: 'tabLongPress',
  34. target: route.key,
  35. });
  36. };
  37. return (
  38. <TouchableOpacity
  39. key={route.key}
  40. accessibilityRole="button"
  41. accessibilityStates={isFocused ? ['selected'] : []}
  42. accessibilityLabel={options.tabBarAccessibilityLabel}
  43. testID={options.tabBarTestID}
  44. onPress={onPress}
  45. onLongPress={onLongPress}
  46. style={{
  47. flex: 1,
  48. height: 50,
  49. flexDirection: 'row',
  50. justifyContent: 'center',
  51. alignItems: 'center',
  52. }}>
  53. <Text style={{color: isFocused ? '#673ab7' : '#222'}}>{label}</Text>
  54. </TouchableOpacity>
  55. );
  56. })}
  57. </View>
  58. );
  59. }
  60. const Tab = createBottomTabNavigator();
  61. export default class Main_tab_navigation extends Component {
  62. constructor(props) {
  63. super(props);
  64. this.state = {
  65. authority: '',
  66. };
  67. }
  68. render() {
  69. return (
  70. <NavigationContainer>
  71. <Tab.Navigator tabBar={(props) => <MyTabBar {...props} />}>
  72. <Tab.Screen
  73. name="home_navigation"
  74. component={home_navigation}
  75. options={{
  76. title: '首页',
  77. unmountOnBlur: true,
  78. // tabBarIcon: ({color, size}) => (
  79. // <MaterialCommunityIcons name="home" color={color} size={100} />
  80. // ),
  81. }}
  82. />
  83. <Tab.Screen
  84. name="tax_navigation"
  85. component={tax_navigation}
  86. options={{
  87. title: '消息',
  88. unmountOnBlur: true,
  89. // tabBarLabel: 'Home',
  90. // tabBarIcon: ({color, size}) => (
  91. // // <MaterialCommunityIcons name="home" color={color} size={size} />
  92. // <MaterialCommunityIcons name="account" color={color} size={26} />
  93. // ),
  94. }}
  95. // initialParams={this.state.authority}
  96. />
  97. <Tab.Screen
  98. name="personal_navigation"
  99. component={personal_navigation}
  100. options={{
  101. title: '个人中心',
  102. unmountOnBlur: true,
  103. // tabBarIcon: ({color, size}) => (
  104. // <MaterialCommunityIcons
  105. // name="home"
  106. // color={color}
  107. // size={26}
  108. // />
  109. // ),
  110. }}
  111. />
  112. </Tab.Navigator>
  113. </NavigationContainer>
  114. );
  115. }
  116. componentDidMount(): void {
  117. this.getAuthority();
  118. }
  119. getAuthority = async () => {
  120. let authority = await RetrieveData('authority');
  121. if (authority) {
  122. this.setState({
  123. authority: authority,
  124. });
  125. }
  126. };
  127. }