@theoplayer/react-native-ui
Version:
A React Native UI for @theoplayer/react-native
57 lines (55 loc) • 2.49 kB
JavaScript
;
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 _LiveUtils = require("../util/LiveUtils");
var _TimeUtils = require("../util/TimeUtils");
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,
seekable
} = props;
const context = (0, _react.useContext)(_PlayerContext.PlayerContext);
// An invalid duration
if (showDuration && !isValidDuration(duration)) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
}
const isLive = (0, _LiveUtils.isLiveDuration)(duration);
const atLive = (0, _LiveUtils.isAtLive)(duration, time, seekable);
if (isLive && atLive) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
}
const endTime = duration && isFinite(duration) ? duration : seekable && seekable.length > 0 ? seekable[seekable.length - 1].end : NaN;
let timeOnLabel = time;
if (isLive) {
timeOnLabel = -((endTime || 0) - time);
}
let text;
if (showDuration && !isLive) {
text = `${(0, _TimeUtils.formatTime)(timeOnLabel, endTime, isLive)} / ${(0, _TimeUtils.formatTime)(endTime)}`;
} else {
text = (0, _TimeUtils.formatTime)(timeOnLabel, endTime, isLive);
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [context.style.text, {
color: context.style.colors.text
}, style],
children: `${text}`
});
}
function isValidDuration(duration) {
return duration !== undefined && !isNaN(duration) && duration > 0;
}
//# sourceMappingURL=StaticTimeLabel.js.map