Notification.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. import app from '../../../app.json';
  12. import utils from '../../utils/utils';
  13. export default class Notification extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. refreshing: false
  18. };
  19. this.pageAdapter = [{
  20. title: $t('notification.tabPromotions'),
  21. name: "Promotions",
  22. component: Promotions
  23. }, {
  24. title: $t('notification.tabAlerts'),
  25. name: "Alerts",
  26. component: Alerts
  27. }]
  28. this.tabBarStyle = {
  29. tabBarStyle: styles.tabStyle,
  30. tabBarPressColor: rippleColor,
  31. tabBarScrollEnabled: false,
  32. tabBarIndicatorStyle: styles.indicator,
  33. tabBarActiveTintColor: app.isWhitelabel ? textPrimary : colorLight,
  34. tabBarInactiveTintColor: app.isWhitelabel ? textSecondary : "#E0E0E0"
  35. }
  36. this.isHide = false;
  37. }
  38. componentDidMount() {
  39. utils.setBackClick([this.props?.route?.name, "Alerts", "Promotions"], this.backPage)
  40. this.props.navigation.addListener('focus', () => {
  41. this.isHide = false;
  42. });
  43. this.props.navigation.addListener('blur', () => {
  44. this.isHide = true;
  45. });
  46. //BackHandler.addEventListener('hardwareBackPress', this.backPage)
  47. }
  48. componentWillUnmount() {
  49. //BackHandler.removeEventListener("hardwareBackPress", this.backPage)
  50. }
  51. backPage = () => {
  52. //const params = this.props.route.params;
  53. if (!this.isHide) {
  54. startPage(PageList.home);
  55. return true;
  56. }
  57. }
  58. render() {
  59. const Tab = createMaterialTopTabNavigator();
  60. return (
  61. <Tab.Navigator
  62. style={styles.container}
  63. screenOptions={{
  64. lazy: false,
  65. lazyPreloadDistance: 1,
  66. ...this.tabBarStyle
  67. }}
  68. backBehavior={() => this.backPage()}>
  69. { this.pageAdapter.map((item, index) =>
  70. <Tab.Screen
  71. key={index}
  72. name={item.name}
  73. component={item.component}
  74. options={{
  75. title: item.title,
  76. tabBarAllowFontScaling: false
  77. }}
  78. />
  79. )}
  80. </Tab.Navigator>
  81. );
  82. }
  83. }
  84. const styles = StyleSheet.create({
  85. container: {
  86. flex: 1,
  87. backgroundColor: colorLight
  88. },
  89. tabStyle: {
  90. backgroundColor: app.isWhitelabel ? colorLight : colorPrimary
  91. },
  92. indicator: {
  93. backgroundColor: app.isWhitelabel ? colorPrimary : colorLight
  94. }
  95. })