IO-1165 Add video playback support.
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import React from "react";
|
||||
import { Modal, SafeAreaView, TouchableOpacity, View } from "react-native";
|
||||
import { Video } from "expo-av";
|
||||
import React, { useState } from "react";
|
||||
import {
|
||||
Dimensions,
|
||||
Modal,
|
||||
SafeAreaView,
|
||||
TouchableOpacity,
|
||||
} from "react-native";
|
||||
import Gallery from "react-native-image-gallery";
|
||||
|
||||
export default function MediaCacheOverlay({
|
||||
photos,
|
||||
previewVisible,
|
||||
@@ -9,6 +16,11 @@ export default function MediaCacheOverlay({
|
||||
imgIndex,
|
||||
setImgIndex,
|
||||
}) {
|
||||
const [currentIndex, setcurrentIndex] = useState(0);
|
||||
const [dragging, setDragging] = useState(false);
|
||||
|
||||
const videoRef = React.useRef(null);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
onDismiss={() => setPreviewVisible(false)}
|
||||
@@ -17,7 +29,14 @@ export default function MediaCacheOverlay({
|
||||
transparent={false}
|
||||
>
|
||||
<SafeAreaView style={{ flex: 1, backgroundColor: "black" }}>
|
||||
<Gallery initialPage={imgIndex} images={photos} />
|
||||
<Gallery
|
||||
initialPage={imgIndex}
|
||||
images={photos}
|
||||
onPageScroll={({ position }) => setcurrentIndex(position)}
|
||||
onPageScrollStateChanged={(state) =>
|
||||
state === "idle" ? setDragging(false) : setDragging(true)
|
||||
}
|
||||
/>
|
||||
<TouchableOpacity
|
||||
style={{ position: "absolute" }}
|
||||
onPress={() => setPreviewVisible(false)}
|
||||
@@ -29,7 +48,29 @@ export default function MediaCacheOverlay({
|
||||
style={{ margin: 20 }}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
{!dragging && photos[currentIndex] && photos[currentIndex].videoUrl && (
|
||||
<TouchableOpacity
|
||||
style={{
|
||||
position: "absolute",
|
||||
left: Dimensions.get("window").width / 2 - 32,
|
||||
top: Dimensions.get("window").height / 2 - 32,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
onPress={async () => {
|
||||
await videoRef.current.loadAsync(
|
||||
{ uri: photos[currentIndex].videoUrl },
|
||||
{},
|
||||
false
|
||||
);
|
||||
videoRef.current.presentFullscreenPlayer();
|
||||
}}
|
||||
>
|
||||
<Ionicons name="play" size={64} color="white" />
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
<Video ref={videoRef} useNativeControls />
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user