IO-1165 Add video playback support.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { Video } from "expo-av";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import {
|
||||
FlatList,
|
||||
@@ -11,15 +10,8 @@ import {
|
||||
import env from "../../env";
|
||||
import { DetermineFileType } from "../../util/document-upload.utility";
|
||||
import MediaCacheOverlay from "../media-cache-overlay/media-cache-overlay.component";
|
||||
|
||||
export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
const [previewVisible, setPreviewVisible] = useState(false);
|
||||
const [videoUri, setVideoUri] = useState(null);
|
||||
const [status, setStatus] = React.useState({});
|
||||
console.log(
|
||||
"🚀 ~ file: job-documents.component.jsx ~ line 19 ~ status",
|
||||
status
|
||||
);
|
||||
|
||||
const [imgIndex, setImgIndex] = useState(0);
|
||||
const onRefresh = async () => {
|
||||
@@ -30,9 +22,12 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
() =>
|
||||
job.documents.map((doc) => {
|
||||
return {
|
||||
source: {
|
||||
uri: GenerateSrcUrl(doc),
|
||||
},
|
||||
videoUrl:
|
||||
DetermineFileType(doc.type) === "video" && GenerateSrcUrl(doc),
|
||||
source:
|
||||
DetermineFileType(doc.type) === "video"
|
||||
? { uri: GenerateThumbUrl(doc) }
|
||||
: { uri: GenerateSrcUrl(doc) },
|
||||
};
|
||||
}),
|
||||
[job.documents]
|
||||
@@ -50,16 +45,10 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
keyExtractor={(item) => item.id}
|
||||
renderItem={(object) => (
|
||||
<TouchableOpacity
|
||||
style={{ flex: 1 / 4, aspectRatio: 1 }}
|
||||
onPress={() => {
|
||||
if (DetermineFileType(object.item.type) === "image") {
|
||||
//If image
|
||||
setImgIndex(object.index);
|
||||
setPreviewVisible(true);
|
||||
} else {
|
||||
//If Video
|
||||
setVideoUri(GenerateSrcUrl(object.item));
|
||||
}
|
||||
style={{ flex: 1 / 4, aspectRatio: 1, margin: 4 }}
|
||||
onPress={async () => {
|
||||
setImgIndex(object.index);
|
||||
setPreviewVisible(true);
|
||||
}}
|
||||
>
|
||||
<Image
|
||||
@@ -74,18 +63,7 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
)}
|
||||
/>
|
||||
<Text>{job.documents.length}</Text>
|
||||
<Video
|
||||
source={
|
||||
videoUri
|
||||
? {
|
||||
uri: videoUri,
|
||||
}
|
||||
: null
|
||||
}
|
||||
useNativeControls
|
||||
isLooping
|
||||
onPlaybackStatusUpdate={(status) => setStatus(() => status)}
|
||||
/>
|
||||
|
||||
<MediaCacheOverlay
|
||||
photos={fullphotos}
|
||||
imgIndex={imgIndex}
|
||||
@@ -99,7 +77,7 @@ export default function JobDocumentsComponent({ job, loading, refetch }) {
|
||||
|
||||
export const GenerateSrcUrl = (value) => {
|
||||
let extension = value.extension;
|
||||
if (extension && extension.includes("heic")) extension = "jpg";
|
||||
if (extension && extension.toLowerCase().includes("heic")) extension = "jpg";
|
||||
|
||||
return `${env.REACT_APP_CLOUDINARY_ENDPOINT}/${DetermineFileType(
|
||||
value.type
|
||||
|
||||
Reference in New Issue
Block a user