删除ios保存图片功能;切换账号后若身份有变化重新渲染动态页面

This commit is contained in:
yezian 2024-03-23 15:28:01 +08:00
parent 0db205bb1e
commit dbcd874261
4 changed files with 57 additions and 52 deletions

View File

@ -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 checkRole = useCallback(async () => {
const account = await get("account");
const role = account.role;
const isVip = account.is_a_member;
if (role !== 0 || isVip === 1) {
setIsVip(true);
}
};
checkRole();
if (role !== 0 || isVip === 1) return true;
return false;
}, []);
const MenusComponent = useCallback(
@ -73,23 +67,24 @@ export default function ImageViewer({
>
<View style={tailwind("flex flex-1 flex-row items-center px-4")}>
<TouchableOpacity
onPress={
isVip
? saveToLocal
: () => {
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")}
>
<Icon type="ionicon" name="image" size={30} color="white" />
<Text
style={tailwind("text-sm text-[#FFFFFF80] font-medium mt-1")}
>
{isSaved ? "已保存" : "保存(会员特权)"}
保存(会员特权)
</Text>
</TouchableOpacity>
<TouchableOpacity
@ -113,12 +108,13 @@ export default function ImageViewer({
</TouchableOpacity>
</Modal>
),
[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,7 +134,9 @@ export default function ImageViewer({
onSwipeDown={() => setIsVisible(false)}
enableSwipeDown
backgroundColor="#07050A"
renderFooter={(index) => (
renderFooter={
Platform.OS === "android"
? (index) => (
<TouchableOpacity
onPress={() => hanldSaveImage(index)}
style={{
@ -160,12 +157,13 @@ export default function ImageViewer({
/>
)}
</TouchableOpacity>
)}
)
: () => <></>
}
onSave={async (url) => {
const isSuccess = await saveImage(url);
setIsSaved(isSuccess);
}}
saveToLocalByLongPress={true}
saveToLocalByLongPress={Platform.OS === "android"}
menus={MenusComponent}
loadingRender={() => <ActivityIndicator size="large" />}
/>

View File

@ -193,7 +193,7 @@ export default function FeedPosts({ blur }) {
useEffect(() => {
getVipPrice();
getData(2);
}, []);
}, [blur]);
const tailwind = useTailwind();
const renderItem = ({ item }) => <Post isBlur={blur} data={item} />;

View File

@ -174,7 +174,7 @@ export default function FollowPosts({ blur }) {
//mids
useEffect(() => {
getData("top");
}, [followMids, currentTime]);
}, [followMids, currentTime, blur]);
const tailwind = useTailwind();
const renderItem = ({ item }) => <Post isBlur={blur} data={item} />;

View File

@ -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);
}