mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 12:23:24 +00:00
feat: show remaining time in bottomcontrols when time is tapped
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { View } from "react-native";
|
import { useState } from "react";
|
||||||
|
import { TouchableOpacity, View } from "react-native";
|
||||||
|
|
||||||
import { usePlayerStore } from "~/stores/player/store";
|
import { usePlayerStore } from "~/stores/player/store";
|
||||||
import { Text } from "../ui/Text";
|
import { Text } from "../ui/Text";
|
||||||
@@ -8,6 +9,22 @@ import { mapMillisecondsToTime } from "./utils";
|
|||||||
|
|
||||||
export const BottomControls = () => {
|
export const BottomControls = () => {
|
||||||
const status = usePlayerStore((state) => state.status);
|
const status = usePlayerStore((state) => state.status);
|
||||||
|
const [showRemaining, setShowRemaining] = useState(false);
|
||||||
|
|
||||||
|
const toggleTimeDisplay = () => {
|
||||||
|
setShowRemaining(!showRemaining);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTimeDisplay = () => {
|
||||||
|
if (status?.isLoaded) {
|
||||||
|
if (showRemaining) {
|
||||||
|
const remainingTime =
|
||||||
|
(status.durationMillis ?? 0) - (status.positionMillis ?? 0);
|
||||||
|
return "-" + mapMillisecondsToTime(remainingTime);
|
||||||
|
}
|
||||||
|
return mapMillisecondsToTime(status.durationMillis ?? 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (status?.isLoaded) {
|
if (status?.isLoaded) {
|
||||||
return (
|
return (
|
||||||
@@ -18,9 +35,9 @@ export const BottomControls = () => {
|
|||||||
{mapMillisecondsToTime(status.positionMillis ?? 0)}
|
{mapMillisecondsToTime(status.positionMillis ?? 0)}
|
||||||
</Text>
|
</Text>
|
||||||
<ProgressBar />
|
<ProgressBar />
|
||||||
<Text className="font-bold">
|
<TouchableOpacity onPress={toggleTimeDisplay}>
|
||||||
{mapMillisecondsToTime(status.durationMillis ?? 0)}
|
<Text className="font-bold">{getTimeDisplay()}</Text>
|
||||||
</Text>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</Controls>
|
</Controls>
|
||||||
|
Reference in New Issue
Block a user