diff --git a/components/ImageViewer/index.jsx b/components/ImageViewer/index.jsx index 0abc1d3..fd1d4ec 100644 --- a/components/ImageViewer/index.jsx +++ b/components/ImageViewer/index.jsx @@ -4,6 +4,7 @@ import { Modal, TouchableOpacity, ActivityIndicator, + Platform, } from "react-native"; import React, { useState, useCallback, useEffect } from "react"; import { ImageViewer as OriginImageViewer } from "react-native-image-zoom-viewer"; @@ -32,19 +33,12 @@ export default function ImageViewer({ const navigation = useNavigation(); - const [isSaved, setIsSaved] = useState(false); - const [isVip, setIsVip] = useState(false); - - useEffect(() => { - const checkRole = async () => { - const account = await get("account"); - const role = account.role; - const isVip = account.is_a_member; - if (role !== 0 || isVip === 1) { - setIsVip(true); - } - }; - checkRole(); + const checkRole = useCallback(async () => { + const account = await get("account"); + const role = account.role; + const isVip = account.is_a_member; + if (role !== 0 || isVip === 1) return true; + return false; }, []); const MenusComponent = useCallback( @@ -73,23 +67,24 @@ export default function ImageViewer({ > { - setIsVisible(false); - navigation.navigate("WebWithoutHeader", { - uri: process.env.EXPO_PUBLIC_WEB_URL + "/vip", - }); - } - } + onPress={async () => { + const isVip = await checkRole(); + if (isVip) { + saveToLocal(); + return; + } + setIsVisible(false); + navigation.navigate("WebWithoutHeader", { + uri: process.env.EXPO_PUBLIC_WEB_URL + "/vip", + }); + }} style={tailwind("flex flex-col items-center px-4")} > - {isSaved ? "已保存" : "保存(会员特权)"} + 保存(会员特权) ), - [isSaved, isVip] + [] ); const [isVipModalVisible, setIsVipModalVisible] = useState(false); const [isSaving, setIsSaving] = useState(false); const hanldSaveImage = async (index) => { + const isVip = await checkRole(); if (!isVip) { setIsVipModalVisible(true); return; @@ -126,7 +122,6 @@ export default function ImageViewer({ if (isSaving) return; setIsSaving(true); const isSuccess = await saveImage(imageUrls[index].url); - setIsSaved(isSuccess); setIsSaving(false); }; @@ -139,33 +134,36 @@ export default function ImageViewer({ onSwipeDown={() => setIsVisible(false)} enableSwipeDown backgroundColor="#07050A" - renderFooter={(index) => ( - hanldSaveImage(index)} - style={{ - marginLeft: 20, - marginBottom: insets.bottom, - ...tailwind( - "flex justify-center items-center w-12 h-12 bg-[#FFFFFF1A] rounded-full" - ), - }} - > - {isSaving && } - {!isSaving && ( - - )} - - )} + renderFooter={ + Platform.OS === "android" + ? (index) => ( + hanldSaveImage(index)} + style={{ + marginLeft: 20, + marginBottom: insets.bottom, + ...tailwind( + "flex justify-center items-center w-12 h-12 bg-[#FFFFFF1A] rounded-full" + ), + }} + > + {isSaving && } + {!isSaving && ( + + )} + + ) + : () => <> + } onSave={async (url) => { const isSuccess = await saveImage(url); - setIsSaved(isSuccess); }} - saveToLocalByLongPress={true} + saveToLocalByLongPress={Platform.OS === "android"} menus={MenusComponent} loadingRender={() => } /> diff --git a/screeens/Posts/FeedPosts/index.jsx b/screeens/Posts/FeedPosts/index.jsx index 9ed2c7c..ba23d70 100644 --- a/screeens/Posts/FeedPosts/index.jsx +++ b/screeens/Posts/FeedPosts/index.jsx @@ -193,7 +193,7 @@ export default function FeedPosts({ blur }) { useEffect(() => { getVipPrice(); getData(2); - }, []); + }, [blur]); const tailwind = useTailwind(); const renderItem = ({ item }) => ; diff --git a/screeens/Posts/FollowPosts/index.jsx b/screeens/Posts/FollowPosts/index.jsx index 0329772..8c42abf 100644 --- a/screeens/Posts/FollowPosts/index.jsx +++ b/screeens/Posts/FollowPosts/index.jsx @@ -174,7 +174,7 @@ export default function FollowPosts({ blur }) { //当关注的主播mids改变,获取新数据 useEffect(() => { getData("top"); - }, [followMids, currentTime]); + }, [followMids, currentTime, blur]); const tailwind = useTailwind(); const renderItem = ({ item }) => ; diff --git a/screeens/Posts/index.jsx b/screeens/Posts/index.jsx index 54f2394..21fab8c 100644 --- a/screeens/Posts/index.jsx +++ b/screeens/Posts/index.jsx @@ -80,8 +80,15 @@ export default function Posts({ navigation }) { const isVip = accountData.data.account.is_a_member; if (role !== 0 || isVip === 1) { setBlur(false); + } else { + setBlur(true); } await save("account", accountData.data.account); + if (role === 3) { + setIsStreamer(true); + } else { + setIsStreamer(false); + } } catch (error) { console.error(error); }