NoticeScreen.tsx 4.8 KB

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