@livetv-app/tvguide
Version:
An Android TV Live Channels-like Electronic Programme Guide for React DOM and React Native applications.
82 lines (81 loc) • 4.14 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.styles = exports.TimeList = exports.Time = exports.TimeCell = void 0;
const React = require("react");
const react_1 = require("react");
const react_native_1 = require("react-native");
const util_1 = require("../util");
const constants_1 = require("../constants");
const channel_row_native_1 = require("./channel-row.native");
const _TimeCell = function TimeCell(props) {
// The current time, to the half-hour
const now = util_1.useCurrentTime(1800000);
const isStartPositionToday = Math.floor(props.start.getTime() / 86400000) ===
Math.floor(now.getTime() / 86400000);
return React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.cell, channel_row_native_1.styles.main, exports.styles.main] }, isStartPositionToday ?
React.createElement(Time, { format: util_1.formatTime, style: exports.styles.mainText }) :
React.createElement(Time, { time: props.start, format: util_1.formatDay, style: [exports.styles.mainText, exports.styles.mainTextNotToday] }));
};
exports.TimeCell = React.memo(_TimeCell);
function Time(props) {
var _a;
const now = util_1.useCurrentTime(props.interval);
const time = (_a = props.time) !== null && _a !== void 0 ? _a : now;
return React.createElement(react_native_1.Text, { style: props.style }, props.format ? props.format.call(null, time) : time.toString());
}
exports.Time = Time;
const _TimeList = function TimeList(props) {
// Current time, to one minute
const now = util_1.useCurrentTime(60000);
const [width, setWidth] = react_1.useState(react_native_1.Dimensions.get('window').width);
const leftPosition = props.start;
const cell_count = width / constants_1.SCALE / constants_1.CELL_WIDTH;
const cells = [];
for (let i = 0; i < cell_count; i++) {
const time = new Date(leftPosition.getTime() + (constants_1.CELL_LENGTH * i));
cells.push(React.createElement(react_native_1.View, { key: time.getTime(), style: [channel_row_native_1.styles.cell, exports.styles.time] },
React.createElement(react_native_1.Text, { style: exports.styles.timeText }, util_1.formatTimeShort(time))));
}
const nowindicator_position = now.getTime() - leftPosition.getTime();
const nowindicator_cells = nowindicator_position / constants_1.CELL_LENGTH;
const nowindicator = nowindicator_cells * constants_1.CELL_WIDTH;
return React.createElement(react_native_1.View, { style: exports.styles.timeRow, onLayout: e => { var _a; return (setWidth(e.nativeEvent.layout.width), (_a = props.onResize) === null || _a === void 0 ? void 0 : _a.call(null, e.nativeEvent.layout.width)); } },
React.createElement(react_native_1.View, { style: channel_row_native_1.styles.scrollContainer },
React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.scroller, exports.styles.timeHeader] }, cells)),
nowindicator >= 0 && width >= nowindicator ? React.createElement(React.Fragment, null,
React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.nowIndicator, exports.styles.nowIndicator, { left: constants_1.SCALE * nowindicator }] }),
React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.nowIndicator, { left: constants_1.SCALE * nowindicator }] })) : null);
};
exports.TimeList = React.memo(_TimeList);
exports.styles = react_native_1.StyleSheet.create({
timeHeader: {
overflow: 'hidden',
},
main: {},
mainText: {
color: '#e1f5fe',
fontSize: constants_1.SCALE * 14,
},
mainTextNotToday: {
color: '#ffffff',
},
timeRow: {
flex: 1,
},
time: {
width: constants_1.SCALE * constants_1.CELL_WIDTH,
paddingLeft: constants_1.SCALE * 10,
paddingRight: 0,
},
timeText: {
color: '#eeeeee',
fontSize: constants_1.SCALE * 14,
},
nowIndicator: {
width: 8,
height: 8,
marginTop: -4,
marginLeft: -3,
borderRadius: 4,
},
});