UNPKG

@theoplayer/react-native-ui

Version:

A React Native UI for @theoplayer/react-native

56 lines (54 loc) 1.76 kB
import { Text } from 'react-native'; import React, { useContext } from 'react'; import { PlayerContext } from '../util/PlayerContext'; import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; /** * A static time label for the `react-native-theoplayer` UI. */ export function StaticTimeLabel(props) { const { style, showDuration, time, duration } = props; const context = useContext(PlayerContext); // An invalid duration if (showDuration && !isValidDuration(duration)) { return /*#__PURE__*/_jsx(_Fragment, {}); } // Live streams report an Infinity duration. if (showDuration && isLiveDuration(duration)) { return /*#__PURE__*/_jsx(Text, { style: [context.style.text, { color: context.style.colors.text }, style], children: context.locale.liveLabel }); } try { let currentTimeLabel = new Date(time).toISOString().substring(11, 19); let durationLabel = new Date(duration ?? 0).toISOString().substring(11, 19); if (durationLabel.startsWith('00:')) { // Don't render hours if not needed. currentTimeLabel = currentTimeLabel.slice(3); durationLabel = durationLabel.slice(3); } const label = showDuration ? `${currentTimeLabel} / ${durationLabel}` : currentTimeLabel; return /*#__PURE__*/_jsx(Text, { style: [context.style.text, { color: context.style.colors.text }, style], children: label }); } catch { return /*#__PURE__*/_jsx(_Fragment, {}); } } function isValidDuration(duration) { return duration !== undefined && !isNaN(duration) && duration > 0; } function isLiveDuration(duration) { return duration !== undefined && !isFinite(duration); } //# sourceMappingURL=StaticTimeLabel.js.map