tiefen_space_app/screeens/NoticeDetail/NoticeNav/index.jsx

135 lines
4.0 KiB
JavaScript

import {
View,
TouchableOpacity,
Image as NativeImage,
Text,
Animated,
useWindowDimensions,
} from "react-native";
import React, { useState, useRef, useCallback } from "react";
import { useTailwind } from "tailwind-rn";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { Badge } from "@rneui/themed";
import { TabView, SceneMap, TabBar } from "react-native-tab-view";
import MessageList from "../components/MessageList";
import MyModal from "../../../components/MyModal";
export default function NoticeNav({ navigation }) {
const [data, setData] = useState([]);
const [isReadModalVisible, setIsReadModalVisible] = useState(false);
const tailwind = useTailwind();
const insets = useSafeAreaInsets();
const mesListEl = useRef(null);
//tab组件相关
const layout = useWindowDimensions();
const [index, setIndex] = useState(0);
const [routes] = useState([{ key: "list", title: "消息" }]);
const renderScene = useCallback(
SceneMap({
list: () => <MessageList navigation={navigation} ref={mesListEl} />,
}),
[]
);
const handleReadAll = useCallback(() => {
mesListEl.current.readAllMsg([0, 1, 2, 3]);
}, []);
const renderIndicator = useCallback((props) => {
const { position, navigationState, getTabWidth } = props;
const inputRange = [0, 1];
const translateX = position.interpolate({
inputRange: inputRange,
outputRange: inputRange.map((x) => {
return x * getTabWidth(navigationState.index);
}),
});
return (
<Animated.View
style={{
width: `${100 / navigationState.routes.length}%`,
transform: [
{
translateX,
},
],
paddingBottom: 5,
...tailwind("flex flex-1 items-center justify-end"),
}}
>
<NativeImage
source={require("../../../assets/icon/others/tabindicator.png")}
/>
</Animated.View>
);
}, []);
const renderTabBar = useCallback(
(props) => (
<View style={tailwind("flex flex-row items-center")}>
<TabBar
{...props}
activeColor="#FFFFFF"
inactiveColor="#FFFFFF80"
style={tailwind("bg-transparent flex-1")}
labelStyle={tailwind("text-2xl font-medium")}
tabStyle={{ width: "auto" }}
renderIndicator={renderIndicator}
/>
<View style={tailwind("flex-row items-center")}>
<TouchableOpacity
style={tailwind(
"flex items-center justify-center w-9 h-9 mr-4 bg-[#FFFFFF1A] rounded-full"
)}
onPress={() => navigation.navigate("Search")}
>
<NativeImage
source={require("../../../assets/icon/32DP/search.png")}
/>
</TouchableOpacity>
<TouchableOpacity
style={tailwind(
"flex items-center justify-center w-9 h-9 mr-4 bg-[#FFFFFF1A] rounded-full"
)}
onPress={() => setIsReadModalVisible(true)}
>
<NativeImage
source={require("../../../assets/icon/32DP/remove.png")}
/>
</TouchableOpacity>
</View>
</View>
),
[]
);
return (
<View
style={{
paddingTop: insets.top,
paddingLeft: insets.left,
paddingRight: insets.right,
...tailwind("flex flex-1"),
}}
>
<TabView
navigationState={{ index, routes }}
swipeEnabled={true}
renderScene={renderScene}
renderTabBar={renderTabBar}
onIndexChange={setIndex}
initialLayout={{ width: layout.width }}
/>
<MyModal
visible={isReadModalVisible}
setVisible={setIsReadModalVisible}
title="提示"
content="是否确认清除所有未读消息?"
cancel={() => {
setIsReadModalVisible(false);
}}
confirm={() => {
setIsReadModalVisible(false);
handleReadAll();
}}
/>
</View>
);
}