import { View, Dimensions, TouchableOpacity, TouchableWithoutFeedback, Modal, ActivityIndicator, Text, Alert, ScrollView, Image as NativeImage, } from "react-native"; import React, { useState, useEffect } from "react"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useTailwind } from "tailwind-rn"; import { Image } from "expo-image"; import ImageViewer from "react-native-image-zoom-viewer"; import Swiper from "react-native-swiper"; import { Divider, Icon } from "@rneui/themed"; import VideoModal from "../../components/VideoModal"; import { useHeaderHeight } from "@react-navigation/elements"; import * as Clipboard from "expo-clipboard"; import * as Linking from "expo-linking"; import GetWechatModal from "../../components/GetWechatModal"; import SubmitWechatModal from "../../components/SubmitWechatModal"; import Toast from "react-native-toast-message"; import baseRequest from "../../utils/baseRequest"; import { follow, unfollow, checkRelation, block } from "../../utils/relation"; import { get } from "../../utils/storeInfo"; import StreamerProfileSkeleton from "./skeleton"; import { generateSignature } from "../../utils/crypto"; import Svg, { Path } from "react-native-svg"; export default function StreamerProfile({ navigation, route }) { const screenWidth = Dimensions.get("window").width; const tailwind = useTailwind(); const insets = useSafeAreaInsets(); const headerHeight = useHeaderHeight(); //设置header右侧按钮功能 useEffect(() => { navigation.setOptions({ headerRight: () => ( setNavModal(true)} /> ), }); }, []); //页面数据 const [data, setData] = useState({}); const [isLoading, setIsloading] = useState(true); useEffect(() => { 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 detailResponse = await fetch( `${apiUrl}/api/streamer/list_ext_by_mid?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ mid: route.params.mid, ...base, }), } ); const detailData = await detailResponse.json(); if (detailData.ret === -1) { Toast.show({ type: "error", text1: detailData.msg, topOffset: 60, }); return; } //获取当前所有平台 const signature2 = await generateSignature({ ...base, }); const allPlatformsResponse = await fetch( `${apiUrl}/api/platform/list?signature=${signature2}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, }), } ); const allPlatformsData = await allPlatformsResponse.json(); if (allPlatformsData.ret === -1) { Toast.show({ type: "error", text1: allPlatformsData.msg, topOffset: 60, }); return; } //获取主播当前所有平台 const signature3 = await generateSignature({ mid: route.params.mid, ...base, }); const streamerPlatformResponse = await fetch( `${apiUrl}/api/streamer_link/list_by_mid?signature=${signature3}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ mid: route.params.mid, ...base, }), } ); const streamerPlatformData = await streamerPlatformResponse.json(); if (streamerPlatformData.ret === -1) { Toast.show({ type: "error", text1: streamerPlatformData.msg, topOffset: 60, }); return; } const platformsWithIcon = streamerPlatformData.data.list.map((item) => { return { ...item, link_icon: allPlatformsData.data[item.link_no]?.icon, }; }); setData({ ...detailData.data.streamer_ext, wechat_lock_type: detailData.data.wechat_lock_type, platforms: platformsWithIcon, }); setIsloading(false); } catch (error) { console.error(error); } }; getData(); }, []); //媒体展示组件 const MySwiper = () => { //控制视频modal可见性 const [videoVisible, setVideoVisible] = useState(false); //控制图片modal可见性 const [imagesVisible, setImagesVisible] = useState(false); //控制图片modal中打开的图片索引 const [imageIndex, setImageIndex] = useState(""); const images = data?.album?.images?.map((image) => image?.urls[0]); const imagesForImageViewer = images?.map((url) => ({ url })); return ( <> {data?.album !== undefined && data?.cover !== undefined && [...data?.cover?.images, ...data?.album?.images].map( (item, index) => ( {index === 0 ? ( setVideoVisible(true)} > ) : ( { setImageIndex(index - 1); setImagesVisible(true); }} > )} ) )} {/* 展示视频的modal */} {/* 展示图片的modal */} setImagesVisible(false)}> setImagesVisible(false)} index={imageIndex} loadingRender={() => } /> ); }; //拉黑、举报组件 const [navModal, setNavModal] = useState(false); const NavbarRightModal = () => { const handleFeedback = () => { navigation.navigate("MessageDetail", { mid: 1 }); setNavModal(false); }; const handleBlock = async () => { const account = await get("account"); const subMid = account.mid; const objMid = route.params.mid; await block(subMid, objMid); setNavModal(false); }; return ( setNavModal(false)}> 拉黑 举报 ); }; // 平台列表 const PlatformList = ({ item }) => { return ( {item?.link_name}: {item?.nickname} { await Clipboard.setStringAsync(item.url); Alert.alert(null, "复制成功"); }} style={tailwind("flex-row items-center")} > 复制 Linking.openURL(item.url)} style={tailwind("flex-row items-center ml-4")} > 前往 ); }; //点击关注按钮 const [isFollowed, setIsFollowed] = useState(false); const handleFollow = async () => { const account = await get("account"); if (isFollowed) { await unfollow(account.mid, data?.mid); setIsFollowed(!isFollowed); } else { await follow(account.mid, data?.mid); setIsFollowed(!isFollowed); } }; //加载页面时检查关注状态 useEffect(() => { const getRelationData = async () => { const account = await get("account"); const subMid = account.mid; const objMid = route.params.mid; const temIsFollowed = await checkRelation(subMid, objMid, 0); setIsFollowed(temIsFollowed); }; getRelationData(); }, []); //点击私聊 const handleSendMessage = () => { navigation.navigate("MessageDetail", { mid: route.params.mid, }); }; //点击查看微信按钮 const [isAddWechatModalVisible, setIsAddWechatModalVisible] = useState(false); //加载初始骨架屏 if (isLoading) return ; return ( {/* 媒体展示、在线状态 */} {/* 昵称、认证 */} {data?.name} {/* tag*/} {data?.tag !== undefined && data?.tag.map((item, index) => { if (index > 2) return; return ( {item} ); })} {/* 标签 */} {data?.user_id} {`全网粉丝 : ${data?.fans}万`} {data?.age && ( {data?.gender === 1 ? ( ) : ( )} {data?.age}岁 )} {data?.height && ( {`${data?.height}cm`} )} {data?.weight && ( {`${data?.weight}kg`} )} {data?.constellation && ( {data?.constellation} )} {data?.city && ( {data?.city} )} {/* 个性签名 */} 个性签名 {data?.bio} {/* 平台 */} 来这找我玩 微信: setIsAddWechatModalVisible(true)} style={tailwind("text-sm text-[#3B69B8] ml-1")} numberOfLines={1} ellipsizeMode="tail" > 点击查看 {data?.platforms?.map((item) => ( ))} {/* 关注、私聊、查看微信 */} {isFollowed ? "已关注" : "关注"} 私聊 setIsAddWechatModalVisible(true)} style={tailwind( "flex-row flex-1 bg-[#FF669E] items-center justify-center h-10 rounded-full" )} > 添加微信 {/* 拉黑、举报Modal */} {/* 查看微信Modal */} {data?.wechat_lock_type === 0 ? ( ) : ( )} ); }