import { View, Text, Image as NativeImage, TouchableOpacity, ScrollView, } from "react-native"; import React, { useState, useCallback } from "react"; 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"; 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"; export default function SpaceIntroduce({ navigation, route }) { usePreventScreenCapture(); const tailwind = useTailwind(); const insets = useSafeAreaInsets(); const headerHeight = useHeaderHeight(); const { showImageViewer } = useImageViewer(); 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(); }, []) ); const images = data?.streamer_ext?.album?.images?.map((image, index) => { if (index > 4) return; return image?.urls[0]; }); const imagesForImageViewer = images?.map((url) => ({ url })); //当空间价格为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 ; return ( {data?.streamer_ext?.name} {data?.streamer_ext?.user_id} {data?.zone_moment_count} setIsAddWechatModalVisible(true)} style={tailwind("flex flex-col items-center ml-auto")} > 查看微信 空间介绍 {data?.profile} { setShowVideo(true); }} style={tailwind("basis-1/3 p-0.5")} > {data?.streamer_ext?.album?.images?.map((item, index) => { if (index > 4) return; return ( { showImageViewer({ imageUrls: imagesForImageViewer, index: index, }); }} key={index} style={tailwind("basis-1/3 p-0.5")} > ); })} {data?.admission_price !== 0 && ( <> 付费须知 1、加入后,您可以查看空间内相关内容; 2、本空间由空间主人自行创建,加入空间前请确认相关风险,本平台不提供相关保证,请避免上当受骗; 3、虚拟商品一经售出不予退款,请确认阅读上述条款并无异议后进行购买; 4、本平台不提供违法及色情内容,如您发现空间内存在以上内容,请联系人工客服举报处理。 )} {data?.refund_status !== 1 && data?.refund_status !== 2 && ( 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]" )} > {data?.admission_price !== 0 && ( )} {data?.admission_price === 0 ? "免费加入" : `${data?.admission_price / 100}元立即加入`} )} {/* 查看微信Modal */} {data?.streamer_ext?.wechat_lock_type === 0 ? ( ) : ( )} {/* 查看视频Modal */} ); }