选中媒体后,增加处理中的状态显示

This commit is contained in:
yezian 2024-10-09 19:12:04 +08:00
parent f3bb0733a1
commit 89f1a077d9
1 changed files with 40 additions and 14 deletions

View File

@ -1,7 +1,13 @@
import { View, TouchableOpacity, Image } from "react-native";
import {
View,
TouchableOpacity,
Image,
ActivityIndicator,
Text,
} from "react-native";
import React, { useState, useEffect, useCallback } from "react";
import { useTailwind } from "tailwind-rn";
import { Icon } from "@rneui/themed";
import { Icon, Overlay } from "@rneui/themed";
import Toast from "react-native-toast-message";
import { DraggableGrid } from "react-native-draggable-grid";
import { useImageViewer } from "../../context/ImageViewProvider";
@ -32,6 +38,8 @@ export default function MediaPicker({
const [showVideo, setShowVideo] = useState(false);
const [videoUrl, setVideoUrl] = useState("");
const [isOverlayVisible, setIsOverlayVisible] = useState(false);
//
const generateThumbnail = useCallback(async (uri) => {
try {
@ -60,24 +68,28 @@ export default function MediaPicker({
});
if (!result.canceled) {
for (let i = 0; i < result.assets.length; i++) {
if (result.assets[i].duration > 0) {
const videoCover = await generateThumbnail(result.assets[i].uri);
result.assets[i].cover = videoCover.uri;
}
}
setNewAssets(result.assets);
}
};
//newAssetsassets
useEffect(() => {
const temAssets = newAssets.map((item) => ({
...item,
key: Date.now().toString(36) + Math.random().toString(36),
}));
set_Assets([..._assets, ...temAssets]);
setAssets([..._assets, ...temAssets]);
const handleAssets = async () => {
let temAssets = newAssets;
for (let i = 0; i < temAssets.length; i++) {
temAssets[i].key = Date.now().toString(36) + Math.random().toString(36);
if (temAssets[i].duration > 0) {
const videoCover = await generateThumbnail(temAssets[i].uri);
temAssets[i].cover = videoCover.uri;
}
}
set_Assets([..._assets, ...temAssets]);
setAssets([..._assets, ...temAssets]);
setIsOverlayVisible(false);
};
if (newAssets.length === 0) return;
setIsOverlayVisible(true);
handleAssets();
}, [newAssets]);
//
@ -186,6 +198,20 @@ export default function MediaPicker({
}}
/>
<Picker />
<Overlay
isVisible={isOverlayVisible}
backdropStyle={tailwind("bg-[#00000080]")}
overlayStyle={tailwind("bg-[#17161A] p-4")}
>
<ActivityIndicator size="large" />
<Text
style={tailwind(
"mt-2 text-center text-[#FFFFFF40] text-sm font-bold"
)}
>
正在处理
</Text>
</Overlay>
<VideoModal
visible={showVideo}
setVisible={setShowVideo}