|
@@ -4,7 +4,7 @@
|
|
|
*/
|
|
*/
|
|
|
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
|
|
import React, { Component } from 'react';
|
|
import React, { Component } from 'react';
|
|
|
-import { StyleSheet } from 'react-native';
|
|
|
|
|
|
|
+import { StyleSheet, View } from 'react-native';
|
|
|
import { PageList } from '../Router';
|
|
import { PageList } from '../Router';
|
|
|
import ListAlerts from './ListAlerts';
|
|
import ListAlerts from './ListAlerts';
|
|
|
import ListNews from './ListNews';
|
|
import ListNews from './ListNews';
|
|
@@ -21,13 +21,23 @@ export default class Notification extends Component {
|
|
|
super(props);
|
|
super(props);
|
|
|
this.state = {
|
|
this.state = {
|
|
|
refreshing: false,
|
|
refreshing: false,
|
|
|
- countInfo: {}
|
|
|
|
|
|
|
+ countInfo: {},
|
|
|
|
|
+ pageAdapter: []
|
|
|
};
|
|
};
|
|
|
- this.pageAdapter = [/*{
|
|
|
|
|
|
|
+ this.pageAdapterAll = [{
|
|
|
title: $t('notification.tabCampaign'),
|
|
title: $t('notification.tabCampaign'),
|
|
|
name: "Campaigns",
|
|
name: "Campaigns",
|
|
|
component: ListCampaign
|
|
component: ListCampaign
|
|
|
- }, */{
|
|
|
|
|
|
|
+ }, {
|
|
|
|
|
+ title: $t('notification.tabAlerts'),
|
|
|
|
|
+ name: "Alerts",
|
|
|
|
|
+ component: ListAlerts
|
|
|
|
|
+ }, {
|
|
|
|
|
+ title: AlertUtil.isPromotion ? $t('notification.tabPromotions') : $t("notification.tabArticles"),
|
|
|
|
|
+ name: "News",
|
|
|
|
|
+ component: ListNews
|
|
|
|
|
+ }]
|
|
|
|
|
+ this.pageAdapter = [{
|
|
|
title: $t('notification.tabAlerts'),
|
|
title: $t('notification.tabAlerts'),
|
|
|
name: "Alerts",
|
|
name: "Alerts",
|
|
|
component: ListAlerts
|
|
component: ListAlerts
|
|
@@ -48,7 +58,13 @@ export default class Notification extends Component {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
- utils.setBackClick([this.props?.route?.name, "Campaigns", "Alerts", "Promotions"], this.backPage)
|
|
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ pageAdapter: app.v3.showCampaigns ? this.pageAdapterAll : this.pageAdapter
|
|
|
|
|
+ }, () => {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.init();
|
|
|
|
|
+ }, 300);
|
|
|
|
|
+ });
|
|
|
this.props.navigation.addListener('focus', () => {
|
|
this.props.navigation.addListener('focus', () => {
|
|
|
if (this.isHide) {
|
|
if (this.isHide) {
|
|
|
this.isHide = false;
|
|
this.isHide = false;
|
|
@@ -58,11 +74,6 @@ export default class Notification extends Component {
|
|
|
this.props.navigation.addListener('blur', () => {
|
|
this.props.navigation.addListener('blur', () => {
|
|
|
this.isHide = true;
|
|
this.isHide = true;
|
|
|
});
|
|
});
|
|
|
- this.getTotalCount();
|
|
|
|
|
- //BackHandler.addEventListener('hardwareBackPress', this.backPage)
|
|
|
|
|
- AlertUtil.setOnRefreshListener(() => {
|
|
|
|
|
- this.getTotalCount();
|
|
|
|
|
- })
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
componentWillUnmount() {
|
|
@@ -70,6 +81,15 @@ export default class Notification extends Component {
|
|
|
//BackHandler.removeEventListener("hardwareBackPress", this.backPage)
|
|
//BackHandler.removeEventListener("hardwareBackPress", this.backPage)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ init() {
|
|
|
|
|
+ utils.setBackClick([this.props?.route?.name, "Campaigns", "Alerts", "Promotions"], this.backPage)
|
|
|
|
|
+ this.getTotalCount();
|
|
|
|
|
+ //BackHandler.addEventListener('hardwareBackPress', this.backPage)
|
|
|
|
|
+ AlertUtil.setOnRefreshListener(() => {
|
|
|
|
|
+ this.getTotalCount();
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
backPage = () => {
|
|
backPage = () => {
|
|
|
//const params = this.props.route.params;
|
|
//const params = this.props.route.params;
|
|
|
if (!this.isHide) {
|
|
if (!this.isHide) {
|
|
@@ -99,11 +119,19 @@ export default class Notification extends Component {
|
|
|
getBadgeText(index) {
|
|
getBadgeText(index) {
|
|
|
let count = 0;
|
|
let count = 0;
|
|
|
switch (index) {
|
|
switch (index) {
|
|
|
- /*case 0:
|
|
|
|
|
- count = this.state.countInfo?.campaignUnreadCount;
|
|
|
|
|
- break;*/
|
|
|
|
|
case 0:
|
|
case 0:
|
|
|
- count = this.state.countInfo?.alertUnreadCount;
|
|
|
|
|
|
|
+ if (app.v3.showCampaigns) {
|
|
|
|
|
+ count = this.state.countInfo?.campaignUnreadCount;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ count = this.state.countInfo?.alertUnreadCount;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ if (app.v3.showCampaigns) {
|
|
|
|
|
+ count = this.state.countInfo?.alertUnreadCount;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ count = this.state.countInfo?.newsUnreadCount;
|
|
|
|
|
+ }
|
|
|
break
|
|
break
|
|
|
case 2:
|
|
case 2:
|
|
|
count = this.state.countInfo?.newsUnreadCount;
|
|
count = this.state.countInfo?.newsUnreadCount;
|
|
@@ -118,29 +146,33 @@ export default class Notification extends Component {
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
const Tab = createMaterialTopTabNavigator();
|
|
const Tab = createMaterialTopTabNavigator();
|
|
|
- return (
|
|
|
|
|
- <Tab.Navigator
|
|
|
|
|
- style={styles.container}
|
|
|
|
|
- screenOptions={{
|
|
|
|
|
- lazy: false,
|
|
|
|
|
- lazyPreloadDistance: 1,
|
|
|
|
|
- ...this.tabBarStyle
|
|
|
|
|
- }}
|
|
|
|
|
- backBehavior={() => this.backPage()}>
|
|
|
|
|
- { this.pageAdapter.map((item, index) =>
|
|
|
|
|
- <Tab.Screen
|
|
|
|
|
- key={index}
|
|
|
|
|
- name={item.name}
|
|
|
|
|
- component={item.component}
|
|
|
|
|
- options={{
|
|
|
|
|
- title: item.title,
|
|
|
|
|
- tabBarAllowFontScaling: false,
|
|
|
|
|
- tabBarBadge: () => this.getBadgeText(index)
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- )}
|
|
|
|
|
- </Tab.Navigator>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ if (this.state.pageAdapter.length > 0) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <Tab.Navigator
|
|
|
|
|
+ style={styles.container}
|
|
|
|
|
+ screenOptions={{
|
|
|
|
|
+ lazy: false,
|
|
|
|
|
+ lazyPreloadDistance: 1,
|
|
|
|
|
+ ...this.tabBarStyle
|
|
|
|
|
+ }}
|
|
|
|
|
+ backBehavior={() => this.backPage()}>
|
|
|
|
|
+ { this.state.pageAdapter.map((item, index) =>
|
|
|
|
|
+ <Tab.Screen
|
|
|
|
|
+ key={index}
|
|
|
|
|
+ name={item.name}
|
|
|
|
|
+ component={item.component}
|
|
|
|
|
+ options={{
|
|
|
|
|
+ title: item.title,
|
|
|
|
|
+ tabBarAllowFontScaling: false,
|
|
|
|
|
+ tabBarBadge: () => this.getBadgeText(index)
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Tab.Navigator>
|
|
|
|
|
+ );
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return <View></View>
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|