tiefen_space_app/screeens/WechatWaitingToAdd/index.jsx

99 lines
2.6 KiB
React
Raw Normal View History

import {
View,
Dimensions,
Animated,
useWindowDimensions,
Image as NativeImage,
} from "react-native";
import React, { useState, useCallback } from "react";
2023-12-29 00:27:44 +08:00
import { useTailwind } from "tailwind-rn";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import AlreadyAddWechat from "./AlreadyAddWechat";
import HaveNotAddWechat from "./HaveNotAddWechat";
import { TabView, SceneMap, TabBar } from "react-native-tab-view";
2023-12-29 00:27:44 +08:00
export default function WechatWaitingToAdd({ navigation, route }) {
const tailwind = useTailwind();
const insets = useSafeAreaInsets();
//tab组件相关
const layout = useWindowDimensions();
const [index, setIndex] = useState(route.params?.tab ? route.params?.tab : 0);
const [routes] = useState([
{ key: "haveNotAddWechat", title: "待添加" },
{ key: "alreadyAddWechat", title: "已完成" },
]);
const renderScene = useCallback(
SceneMap({
haveNotAddWechat: () => <HaveNotAddWechat />,
alreadyAddWechat: () => <AlreadyAddWechat />,
}),
[]
);
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: 12,
...tailwind("flex flex-1 items-center justify-end"),
}}
>
<NativeImage
source={require("../../assets/icon/others/pinkline.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-lg font-medium")}
renderIndicator={renderIndicator}
/>
</View>
),
[]
);
2023-12-29 00:27:44 +08:00
return (
<View
style={{
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 }}
/>
2023-12-29 00:27:44 +08:00
</View>
);
}