import { View, Dimensions, TouchableOpacity, TouchableWithoutFeedback, Modal, Text, Alert, ScrollView, Platform, 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 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"; import { useImageViewer } from "../../context/ImageViewProvider"; const blurhash = "LcKUTa%gOYWBYRt6xuoJo~s8V@fk"; 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)} /> ), }); }, []); //动态是否需要blur const [blur, setBlur] = useState(true); const checkBlur = async () => { const account = await get("account"); const role = account.role; const isVip = account.is_a_member; if (role !== 0 || isVip === 1) { return setBlur(false); } return setBlur(true); }; //页面数据 const [data, setData] = useState({}); const [postsData, setPostsData] = useState([]); const [spaceData, setSpaceData] = 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); } }; const getPostsData = async () => { const apiUrl = process.env.EXPO_PUBLIC_API_URL; try { const base = await baseRequest(); const signature = await generateSignature({ mid: route.params.mid, ct_upper_bound: Math.floor(new Date().getTime() / 1000), offset: 0, limit: 100, ...base, }); const _response = await fetch( `${apiUrl}/api/moment/list_by_mid?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ mid: route.params.mid, ct_upper_bound: Math.floor(new Date().getTime() / 1000), offset: 0, limit: 100, ...base, }), } ); const _data = await _response.json(); if (_data.ret === -1) { Toast.show({ type: "error", text1: _data.msg, topOffset: 60, }); return; } setPostsData(_data.data.list); } catch (error) { console.error(error); } }; const getSpaceData = 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; } setSpaceData(_data.data.list[0]); } catch (error) { console.error(error); } }; getData(); checkBlur(); getPostsData(); getSpaceData(); }, []); //媒体展示组件 const MySwiper = () => { //控制视频modal可见性 const [videoVisible, setVideoVisible] = useState(false); const { showImageViewer } = useImageViewer(); 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)} > ) : ( { showImageViewer({ imageUrls: imagesForImageViewer, index: index - 1, }); }} > )} ) )} {/* 展示视频的modal */} ); }; //拉黑、举报组件 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} {/* 空间动态 */} {spaceData && spaceData?.previews?.images?.length > 0 && ( navigation.navigate("SpaceIntroduce", { mid: route.params.mid, }) : () => navigation.navigate("StreamerSpace", { mid: route.params.mid, }) } style={tailwind( "flex flex-row justify-between items-center" )} > 空间动态 查看{spaceData?.zone_moment_count}条 navigation.navigate("SpaceIntroduce", { mid: route.params.mid, }) : () => navigation.navigate("StreamerSpace", { mid: route.params.mid, }) } style={{ height: 100, gap: 4, ...tailwind("flex flex-row"), }} > {spaceData?.previews?.images?.map((item, index) => { if (index > 3) return; return ( ); })} )} {/* 动态 */} {!spaceData && postsData.length !== 0 && ( 动态({postsData.length}) navigation.navigate("StreamerPosts", { mid: route.params.mid, }) } > {postsData.map((item, index) => { if (index > 3) return; const mediaUrl = item.media_component.images.length !== 0 ? item.media_component.images[0].urls[0] : item.media_component.videos[0].cover_urls[0]; return ( {index === 3 && postsData.length > 4 && ( +{postsData.length - 4} )} ); })} )} {/* 平台 */} 来这找我玩 微信: 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 ? ( ) : ( )} ); }