Notification.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * 通知功能页面适配器
  3. * @邠心vbe on 2023/08/17
  4. */
  5. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  6. import React, { Component } from 'react';
  7. import { StyleSheet, BackHandler } from 'react-native';
  8. import { PageList } from '../Router';
  9. import Alerts from './Alerts';
  10. import Promotions from './Promotions';
  11. export default class Notification extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. refreshing: false
  16. };
  17. this.pageAdapter = [{
  18. title: $t('notification.tabAlerts'),
  19. name: "Alerts",
  20. component: Alerts
  21. }, {
  22. title: $t('notification.tabPromotions'),
  23. name: "Promotions",
  24. component: Promotions
  25. }]
  26. this.tabBarStyle = {
  27. style: styles.tabStyle,
  28. pressColor: rippleColor,
  29. scrollEnabled: false,
  30. indicatorStyle: styles.indicator,
  31. activeTintColor: colorLight,
  32. inactiveTintColor: "#E0E0E0",
  33. }
  34. this.isHide = false;
  35. }
  36. componentDidMount() {
  37. this.props.navigation.addListener('focus', () => {
  38. this.isHide = false;
  39. });
  40. this.props.navigation.addListener('blur', () => {
  41. this.isHide = true;
  42. });
  43. BackHandler.addEventListener('hardwareBackPress', this.backPage)
  44. }
  45. componentWillUnmount() {
  46. BackHandler.removeEventListener("hardwareBackPress", this.backPage)
  47. }
  48. backPage = () => {
  49. //const params = this.props.route.params;
  50. if (!this.isHide) {
  51. startPage(PageList.home);
  52. return true;
  53. }
  54. }
  55. onPullRefresh() {
  56. }
  57. render() {
  58. const Tab = createMaterialTopTabNavigator();
  59. return (
  60. <Tab.Navigator
  61. style={styles.container}
  62. tabBarOptions={this.tabBarStyle}
  63. lazy={false}
  64. lazyPreloadDistance={1}>
  65. { this.pageAdapter.map((item, index) =>
  66. <Tab.Screen
  67. key={index}
  68. name={item.name}
  69. component={item.component}
  70. options={{
  71. title: item.title
  72. }}
  73. />
  74. )}
  75. </Tab.Navigator>
  76. );
  77. }
  78. }
  79. const styles = StyleSheet.create({
  80. container: {
  81. flex: 1,
  82. backgroundColor: colorLight
  83. },
  84. tabStyle: {
  85. backgroundColor: colorPrimary
  86. },
  87. indicator: {
  88. backgroundColor: colorLight
  89. }
  90. })