NoticeScreen.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* eslint-disable no-use-before-define */
  2. import { StackScreenProps } from '@react-navigation/stack';
  3. import * as React from 'react';
  4. import { useFocusEffect, useNavigation } from '@react-navigation/native';
  5. import { Div, Button, Image, Text, Avatar } from 'react-native-magnus';
  6. import { ScrollView, FlatList } from 'react-native-gesture-handler';
  7. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  8. import Constants from 'expo-constants';
  9. import { useTranslation } from 'react-i18next';
  10. import useModel from 'flooks';
  11. import { useMount } from '@umijs/hooks';
  12. import IM from './model.ts';
  13. import User from '../flooks/User';
  14. import NoticeCom from './NoticeCom.tsx';
  15. const NoticeTab = createMaterialTopTabNavigator();
  16. export default function NoticeScreen({ navigation }: StackScreenProps) {
  17. const { t } = useTranslation();
  18. const webRef = React.useRef();
  19. const { initChat } = useModel(IM, []);
  20. useFocusEffect(
  21. React.useCallback(() => {
  22. initChat();
  23. }, [])
  24. );
  25. return (
  26. <Div bg="gray100" flex={1}>
  27. <Div bg="yellow500" pt={Constants.statusBarHeight + 11} pb={11}>
  28. <Text color="white" textAlign="center" fontSize="xl" fontWeight="bold">
  29. {t('xiao-xi-zhong-xin')}
  30. </Text>
  31. </Div>
  32. <NoticeTab.Navigator
  33. initialRouteName="Sys"
  34. style={{ flexGrow: 1 }}
  35. tabBarOptions={{
  36. inactiveTintColor: '#000',
  37. activeTintColor: '#FFC21C',
  38. indicatorStyle: { height: 0 },
  39. labelStyle: { fontSize: 15 },
  40. style: {
  41. backgroundColor: '#f2f2f2',
  42. elevation: 0,
  43. shadowOffset: {
  44. width: 0,
  45. height: 0,
  46. },
  47. shadowOpacity: 0,
  48. shadowRadius: 0,
  49. },
  50. }}
  51. >
  52. <NoticeTab.Screen
  53. name="Sys"
  54. component={SysNoticeScreen}
  55. options={{
  56. title: t('xi-tong-xiao-xi'),
  57. }}
  58. />
  59. <NoticeTab.Screen
  60. name="Chat"
  61. component={UserChatScreen}
  62. options={{
  63. title: t('yong-hu-xiao-xi'),
  64. }}
  65. />
  66. </NoticeTab.Navigator>
  67. </Div>
  68. );
  69. }
  70. function SysNoticeScreen({ navigation }) {
  71. const { sysNoticeList } = useModel(IM, ['sysNoticeList']);
  72. const { t } = useTranslation();
  73. return (
  74. <FlatList
  75. renderItem={({ item }) => {
  76. return (
  77. <NoticeCom
  78. info={item}
  79. type="email"
  80. onPress={() => {
  81. navigation.navigate('NoticeStack', {
  82. screen: 'EmailDetail',
  83. params: {
  84. emailId: item.id,
  85. },
  86. });
  87. }}
  88. />
  89. );
  90. }}
  91. data={sysNoticeList}
  92. keyExtractor={(item, index) => `email${index}`}
  93. ListEmptyComponent={() => {
  94. return (
  95. <Text color="gary200" fontSize="sm" textAlign="center" py={20}>
  96. {t('zan-wu-shu-ju')}
  97. </Text>
  98. );
  99. }}
  100. contentContainerStyle={{ flexGrow: 1, backgroundColor: '#fff' }}
  101. />
  102. );
  103. }
  104. function UserChatScreen({ navigation }) {
  105. const { chatList } = useModel(IM, ['chatList']);
  106. const { id } = useModel(User, ['id']);
  107. const { t } = useTranslation();
  108. return (
  109. <FlatList
  110. renderItem={({ item }) => {
  111. const isReceive = item.receiveUserId === id;
  112. const toUserId = isReceive ? item.sendUserId : item.receiveUserId;
  113. const toUserName = isReceive ? item.sendNickname : item.receiveNickname;
  114. return (
  115. <NoticeCom
  116. info={item}
  117. userId={id}
  118. type="user"
  119. toUserName={toUserName}
  120. onPress={() => {
  121. navigation.navigate('NoticeStack', {
  122. screen: 'Chat',
  123. params: {
  124. toUserId,
  125. toUserName,
  126. },
  127. });
  128. }}
  129. />
  130. );
  131. }}
  132. data={chatList}
  133. keyExtractor={(item, index) => `chat${index}`}
  134. contentContainerStyle={{ flexGrow: 1, backgroundColor: '#fff' }}
  135. ListEmptyComponent={() => {
  136. return (
  137. <Text color="gary200" fontSize="sm" textAlign="center" py={20}>
  138. {t('zan-wu-shu-ju')}
  139. </Text>
  140. );
  141. }}
  142. />
  143. );
  144. }