@theoplayer/react-native-ui
Version:
A React Native UI for @theoplayer/react-native
65 lines (64 loc) • 2.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GoToLiveButton = GoToLiveButton;
var _react = _interopRequireWildcard(require("react"));
var _PlayerContext = require("../util/PlayerContext");
var _ActionButton = require("./actionbutton/ActionButton");
var _barrel = require("../../hooks/barrel");
var _LiveUtils = require("../util/LiveUtils");
var _reactNative = require("react-native");
var _TestIDs = require("../../utils/TestIDs");
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); }
/**
* The default go to live button for the `react-native-theoplayer` UI.
*/
function GoToLiveButton(props) {
const context = (0, _react.useContext)(_PlayerContext.PlayerContext);
const {
style,
textStyle,
atLiveColor = context.style.colors.liveIndicatorAtLiveEdge,
behindLiveColor = context.style.colors.liveIndicatorBehindLiveEdge
} = props;
const duration = (0, _barrel.useDuration)();
const currentTime = (0, _barrel.useCurrentTime)();
const seekable = (0, _barrel.useSeekable)();
const goToLive = (0, _react.useCallback)(() => {
context.player.currentTime = Infinity;
}, [context.player]);
const liveIndicatorColor = (0, _LiveUtils.isAtLive)(duration, currentTime, seekable) ? atLiveColor : behindLiveColor;
if (isNaN(duration) || !(0, _LiveUtils.isLiveDuration)(duration)) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
}
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton.ActionButton, {
style: [props.style, {
justifyContent: 'center',
aspectRatio: 1.5
}, style],
testID: props.testID ?? _TestIDs.TestIDs.GO_TO_LIVE_BUTTON,
onPress: goToLive,
touchable: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
style: {
flexDirection: 'row',
alignItems: 'center'
},
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [context.style.text, {
color: liveIndicatorColor,
marginRight: 6
}],
children: "\u25CF"
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
style: [context.style.text, {
color: context.style.colors.text
}, textStyle],
children: context.locale.liveLabel
})]
})
});
}
//# sourceMappingURL=GoToLiveButton.js.map