tiefen_space_app/screeens/SpaceIntroduce/index.jsx

399 lines
13 KiB
React
Raw Normal View History

2024-03-21 18:25:31 +08:00
import {
View,
Text,
Image as NativeImage,
TouchableOpacity,
ScrollView,
} from "react-native";
2024-04-18 22:58:59 +08:00
import React, { useState, useCallback } from "react";
2024-03-21 18:25:31 +08:00
import { useTailwind } from "tailwind-rn";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import Toast from "react-native-toast-message";
import { Image } from "expo-image";
import { useHeaderHeight } from "@react-navigation/elements";
2024-04-18 22:58:59 +08:00
import baseRequest from "../../utils/baseRequest";
import { generateSignature } from "../../utils/crypto";
import GetWechatModal from "../../components/GetWechatModal";
import SubmitWechatModal from "../../components/SubmitWechatModal";
import VideoModal from "../../components/VideoModal";
import SpaceIntroduceSkeleton from "./skeleton";
import { usePreventScreenCapture } from "expo-screen-capture";
import { useFocusEffect } from "@react-navigation/native";
import { useImageViewer } from "../../context/ImageViewProvider";
2024-03-21 18:25:31 +08:00
export default function SpaceIntroduce({ navigation, route }) {
2024-04-18 22:58:59 +08:00
usePreventScreenCapture();
2024-03-21 18:25:31 +08:00
const tailwind = useTailwind();
const insets = useSafeAreaInsets();
const headerHeight = useHeaderHeight();
const { showImageViewer } = useImageViewer();
2024-04-18 22:58:59 +08:00
const [data, setData] = useState({});
const [isLoading, setIsloading] = useState(true);
const getData = async () => {
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
try {
const base = await baseRequest();
const signature = await generateSignature({
mid: route.params.mid,
...base,
});
const _response = await fetch(
`${apiUrl}/api/zone/list_by_mid?signature=${signature}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
mid: route.params.mid,
...base,
}),
}
);
const _data = await _response.json();
if (_data.ret === -1) {
Toast.show({
type: "error",
text1: _data.msg,
topOffset: 60,
});
return;
}
if (_data.data.list[0].visitor_role !== 4) {
navigation.replace("StreamerSpace", { mid: route.params.mid });
return;
}
setData({
..._data.data.list[0],
refund_enable: _data.data.refund_enable,
refund_status: _data.data.refund_status,
});
setIsloading(false);
} catch (error) {
console.error(error);
}
};
useFocusEffect(
useCallback(() => {
getData();
}, [])
);
2024-05-01 00:51:16 +08:00
const images = data?.streamer_ext?.album?.images
?.slice(0, 5)
?.map((image) => {
return image?.urls[0];
});
2024-04-22 22:04:58 +08:00
const imagesForImageViewer = images?.map((url) => ({ url }));
2024-04-18 22:58:59 +08:00
//当空间价格为0时直接加入空间
const handleJoinFreeSpace = async () => {
const apiUrl = process.env.EXPO_PUBLIC_API_URL;
try {
const base = await baseRequest();
const body = {
zid: data?.id,
product_id: "h5_zone_admission",
...base,
};
const signature = await generateSignature(body);
const _response = await fetch(
`${apiUrl}/api/zone/free_join?signature=${signature}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
}
);
const _data = await _response.json();
if (_data.ret === -1) {
Toast.show({
type: "error",
text1: _data.msg,
topOffset: 60,
});
return;
}
navigation.replace("StreamerSpace", { mid: route.params.mid });
} catch (error) {
console.error(error);
}
};
//点击查看微信按钮
const [isAddWechatModalVisible, setIsAddWechatModalVisible] = useState(false);
//是否展示视频Modal
const [showVideo, setShowVideo] = useState(false);
//加载初始骨架屏
if (isLoading) return <SpaceIntroduceSkeleton />;
2024-03-21 18:25:31 +08:00
return (
<View
style={{
paddingBottom: insets.bottom,
paddingLeft: insets.left,
paddingRight: insets.right,
...tailwind("flex-1"),
}}
>
<ScrollView>
<View style={tailwind("absolute top-0 left-0")}>
<Image
2024-04-18 22:58:59 +08:00
source={data?.streamer_ext?.cover?.images[0]?.urls[0]}
2024-03-21 18:25:31 +08:00
contentFit="cover"
2024-04-18 22:58:59 +08:00
transition={500}
2024-03-21 18:25:31 +08:00
cachePolicy="disk"
style={{
2024-05-01 00:51:16 +08:00
aspectRatio: "1/1",
2024-03-21 18:25:31 +08:00
...tailwind("w-full"),
}}
/>
<View
style={{
backgroundColor: "#000000B2",
...tailwind("absolute w-full h-full"),
}}
></View>
</View>
<View
style={{
marginTop: headerHeight,
...tailwind("flex flex-row items-center px-4 h-24"),
}}
>
<Image
style={tailwind(
"w-[4.6rem] h-[4.6rem] rounded-full border-2 border-white"
)}
2024-04-18 22:58:59 +08:00
source={data?.streamer_ext?.avatar?.images[0]?.urls[0]}
2024-03-21 18:25:31 +08:00
contentFit="cover"
2024-04-18 22:58:59 +08:00
transition={500}
2024-03-21 18:25:31 +08:00
cachePolicy="disk"
/>
<View style={tailwind("flex flex-col shrink mx-2 justify-between")}>
<Text
style={{ fontSize: 22, ...tailwind("text-white font-medium") }}
numberOfLines={1}
ellipsizeMode="tail"
>
2024-04-18 22:58:59 +08:00
{data?.streamer_ext?.name}
2024-03-21 18:25:31 +08:00
</Text>
2024-05-01 00:51:16 +08:00
<View style={tailwind("flex-row flex-nowrap mt-1.5")}>
2024-03-21 18:25:31 +08:00
<View
style={tailwind(
"flex-row items-center py-0.5 px-2 mr-2 bg-[#FFFFFF1A] rounded-full"
)}
>
<NativeImage
source={require("../../assets/icon/12DP/ID.png")}
/>
<Text style={tailwind("text-white text-xs font-medium ml-0.5")}>
2024-04-18 22:58:59 +08:00
{data?.streamer_ext?.user_id}
2024-03-21 18:25:31 +08:00
</Text>
</View>
</View>
</View>
<TouchableOpacity
2024-04-18 22:58:59 +08:00
onPress={() => setIsAddWechatModalVisible(true)}
2024-03-21 18:25:31 +08:00
style={tailwind("flex flex-col items-center ml-auto")}
>
<NativeImage
source={require("../../assets/icon/others/wechat_bg.png")}
/>
<Text style={tailwind("text-white text-xs font-medium mt-0.5")}>
查看微信
</Text>
</TouchableOpacity>
</View>
2024-05-01 00:51:16 +08:00
<View style={tailwind("flex flex-row flex-nowrap justify-around mt-2")}>
<View style={tailwind("flex flex-col items-center")}>
<Text style={tailwind("text-white text-2xl font-medium")}>
{data?.zone_moment_count}
</Text>
<Text style={tailwind("text-white text-sm font-medium")}>动态</Text>
</View>
<View style={tailwind("flex flex-col items-center")}>
<Text style={tailwind("text-white text-2xl font-medium")}>
{data?.image_count}
</Text>
<Text style={tailwind("text-white text-sm font-medium")}>照片</Text>
</View>
<View style={tailwind("flex flex-col items-center")}>
<Text style={tailwind("text-white text-2xl font-medium")}>
{data?.video_count}
</Text>
<Text style={tailwind("text-white text-sm font-medium")}>视频</Text>
</View>
</View>
2024-03-21 18:25:31 +08:00
<View
style={tailwind(
"flex flex-col w-full rounded-t-3xl bg-[#07050A] mt-4 p-4"
)}
>
<View style={tailwind("flex flex-col items-start")}>
<View>
2024-04-18 22:58:59 +08:00
<Text style={tailwind("text-white text-lg font-medium")}>
2024-03-21 18:25:31 +08:00
空间介绍
</Text>
<NativeImage
style={{ right: -5, bottom: 1, ...tailwind("absolute") }}
source={require("../../assets/icon/others/pinkline.png")}
/>
</View>
</View>
2024-04-18 22:58:59 +08:00
<Text style={tailwind("text-white text-base mt-3")}>
{data?.profile}
2024-03-21 18:25:31 +08:00
</Text>
<View style={tailwind("flex flex-row flex-wrap mt-2")}>
2024-04-18 22:58:59 +08:00
<TouchableOpacity
activeOpacity={1}
onPress={() => {
setShowVideo(true);
}}
style={tailwind("basis-1/3 p-0.5")}
>
2024-03-21 18:25:31 +08:00
<Image
style={{
aspectRatio: "1/1",
...tailwind("w-full rounded"),
}}
2024-04-18 22:58:59 +08:00
source={data?.streamer_ext?.shorts?.videos[0]?.cover_urls[0]}
2024-03-21 18:25:31 +08:00
contentFit="cover"
2024-04-18 22:58:59 +08:00
transition={500}
2024-03-21 18:25:31 +08:00
cachePolicy="disk"
/>
2024-04-18 22:58:59 +08:00
<View
style={tailwind(
"flex absolute w-full h-full left-0 top-0 z-10 justify-center items-center"
)}
>
<NativeImage
source={require("../../assets/icon/others/play.png")}
/>
</View>
</TouchableOpacity>
{data?.streamer_ext?.album?.images?.map((item, index) => {
if (index > 4) return;
return (
2024-04-22 22:04:58 +08:00
<TouchableOpacity
activeOpacity={1}
onPress={() => {
showImageViewer({
imageUrls: imagesForImageViewer,
index: index,
});
2024-04-22 22:04:58 +08:00
}}
key={index}
style={tailwind("basis-1/3 p-0.5")}
>
2024-04-18 22:58:59 +08:00
<Image
style={{
aspectRatio: "1/1",
...tailwind("w-full rounded"),
}}
source={item?.urls[0]}
contentFit="cover"
transition={500}
cachePolicy="disk"
/>
2024-04-22 22:04:58 +08:00
</TouchableOpacity>
2024-04-18 22:58:59 +08:00
);
})}
2024-03-21 18:25:31 +08:00
</View>
2024-04-18 22:58:59 +08:00
{data?.admission_price !== 0 && (
<>
<View style={tailwind("flex flex-col items-start mt-8")}>
<View>
<Text style={tailwind("text-white text-lg font-medium")}>
付费须知
</Text>
<NativeImage
style={{ right: -5, bottom: 1, ...tailwind("absolute") }}
source={require("../../assets/icon/others/pinkline.png")}
/>
</View>
</View>
<Text style={tailwind("text-white text-base mt-3")}>
1加入后您可以查看空间内相关内容
2024-03-21 18:25:31 +08:00
</Text>
2024-04-18 22:58:59 +08:00
<Text style={tailwind("text-white text-base mt-1")}>
2本空间由空间主人自行创建加入空间前请确认相关风险本平台不提供相关保证请避免上当受骗
</Text>
<Text style={tailwind("text-white text-base mt-1")}>
3虚拟商品一经售出不予退款请确认阅读上述条款并无异议后进行购买
</Text>
<Text style={tailwind("text-white text-base mt-1")}>
4本平台不提供违法及色情内容如您发现空间内存在以上内容请联系人工客服举报处理
</Text>
</>
)}
2024-03-21 18:25:31 +08:00
</View>
</ScrollView>
2024-04-18 22:58:59 +08:00
{data?.refund_status !== 1 && data?.refund_status !== 2 && (
<View
2024-03-21 18:25:31 +08:00
style={tailwind(
2024-04-18 22:58:59 +08:00
"flex flex-row h-[4.5rem] py-2 px-6 items-center justify-center border-t border-[#FFFFFF26]"
2024-03-21 18:25:31 +08:00
)}
>
2024-04-18 22:58:59 +08:00
<TouchableOpacity
onPress={
data?.admission_price === 0
? handleJoinFreeSpace
: () =>
navigation.navigate("WebWithoutHeader", {
uri:
process.env.EXPO_PUBLIC_WEB_URL +
"/zone/pay/" +
data?.id +
"/h5_zone_admission/0",
})
}
style={tailwind(
"flex flex-row items-center justify-center h-12 rounded-full px-10 bg-[#FF669E]"
)}
>
2024-04-22 22:04:58 +08:00
{data?.admission_price !== 0 && (
<NativeImage
style={tailwind("ml-2")}
source={require("../../assets/icon/others/money_pink.png")}
/>
)}
2024-04-18 22:58:59 +08:00
<Text style={tailwind("text-base text-white font-medium ml-2")}>
{data?.admission_price === 0
2024-04-22 22:04:58 +08:00
? "免费加入"
2024-04-18 22:58:59 +08:00
: `${data?.admission_price / 100}元立即加入`}
</Text>
<NativeImage source={require("../../assets/icon/32DP/link.png")} />
</TouchableOpacity>
</View>
)}
{/* 查看微信Modal */}
{data?.streamer_ext?.wechat_lock_type === 0 ? (
<GetWechatModal
visible={isAddWechatModalVisible}
setVisible={setIsAddWechatModalVisible}
streamerMid={route.params.mid}
/>
) : (
<SubmitWechatModal
visible={isAddWechatModalVisible}
setVisible={setIsAddWechatModalVisible}
streamerMid={route.params.mid}
/>
)}
{/* 查看视频Modal */}
<VideoModal
visible={showVideo}
setVisible={setShowVideo}
url={data?.streamer_ext?.shorts?.videos[0]?.urls[0]}
/>
2024-03-21 18:25:31 +08:00
</View>
);
}