Notification.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. style: styles.tabStyle,
  29. pressColor: rippleColor,
  30. scrollEnabled: false,
  31. indicatorStyle: styles.indicator,
  32. activeTintColor: app.isWhitelabel ? textPrimary : colorLight,
  33. inactiveTintColor: 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. tabBarOptions={this.tabBarStyle}
  64. lazy={false}
  65. lazyPreloadDistance={1}>
  66. { this.pageAdapter.map((item, index) =>
  67. <Tab.Screen
  68. key={index}
  69. name={item.name}
  70. component={item.component}
  71. options={{
  72. title: item.title
  73. }}
  74. />
  75. )}
  76. </Tab.Navigator>
  77. );
  78. }
  79. }
  80. const styles = StyleSheet.create({
  81. container: {
  82. flex: 1,
  83. backgroundColor: colorLight
  84. },
  85. tabStyle: {
  86. backgroundColor: app.isWhitelabel ? colorLight : colorPrimary
  87. },
  88. indicator: {
  89. backgroundColor: app.isWhitelabel ? colorPrimary : colorLight
  90. }
  91. })