UNPKG

@theoplayer/react-native-ui

Version:

A React Native UI for @theoplayer/react-native

63 lines (60 loc) 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StaticTimeLabel = StaticTimeLabel; var _reactNative = require("react-native"); var _react = _interopRequireWildcard(require("react")); var _PlayerContext = require("../util/PlayerContext"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } /** * A static time label for the `react-native-theoplayer` UI. */ function StaticTimeLabel(props) { const { style, showDuration, time, duration } = props; const context = (0, _react.useContext)(_PlayerContext.PlayerContext); // An invalid duration if (showDuration && !isValidDuration(duration)) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {}); } // Live streams report an Infinity duration. if (showDuration && isLiveDuration(duration)) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.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__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [context.style.text, { color: context.style.colors.text }, style], children: label }); } catch { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {}); } } function isValidDuration(duration) { return duration !== undefined && !isNaN(duration) && duration > 0; } function isLiveDuration(duration) { return duration !== undefined && !isFinite(duration); } //# sourceMappingURL=StaticTimeLabel.js.map