Notification.js 2.5 KB

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