@livetv-app/tvguide
Version:
An Android TV Live Channels-like Electronic Programme Guide for React DOM and React Native applications.
151 lines (150 loc) • 8.33 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.styles = exports.EmptyProgrammeRow = exports.handleProgrammeAction = exports.ProgrammeAction = void 0;
const React = require("react");
const react_native_1 = require("react-native");
const react_native_tvfocus_1 = require("react-native-tvfocus");
const util_1 = require("../util");
const constants_1 = require("../constants");
const header_native_1 = require("./header.native");
const channel_row_native_1 = require("./channel-row.native");
const _ProgrammeRow = function ProgrammeRow(props) {
var _a;
// Current time, to one day
const today = util_1.useCurrentTime(86400000);
const name = util_1.useLocalised(props.programme.name);
const desc = util_1.useLocalised(props.programme.description);
const et = util_1.formatEpisodeText(props.programme);
const isStartToday = Math.floor(props.programme.start.getTime() / 86400000) ===
Math.floor(today.getTime() / 86400000);
const isEndSameDay = Math.floor(props.programme.start.getTime() / 86400000) ===
Math.floor(props.programme.end.getTime() / 86400000);
const showActions = !react_native_1.Platform.isTV;
const actionstext = util_1.useLocalised(props.programme.actions_text);
return React.createElement(react_native_1.View, { style: channel_row_native_1.styles.row },
React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.cell, channel_row_native_1.styles.main] }),
React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.rowNotFirst, channel_row_native_1.styles.cell, exports.styles.programme] },
React.createElement(react_native_1.View, { style: exports.styles.programmeDetail },
React.createElement(react_native_1.View, { style: exports.styles.programmeDetailTop },
React.createElement(react_native_1.Text, { style: [channel_row_native_1.styles.programmeName, exports.styles.programmeName] }, name),
et ?
React.createElement(react_native_1.Text, { style: [
channel_row_native_1.styles.programmeDescriptionText,
channel_row_native_1.styles.programmeEpisodeText,
exports.styles.programmeEpisodeText,
] }, et)
: null,
desc ?
React.createElement(react_native_1.Text, { style: [channel_row_native_1.styles.programmeDescriptionText, exports.styles.programmeDescriptionText] }, desc)
: null),
React.createElement(react_native_1.View, { style: exports.styles.programmeDetailBottom },
React.createElement(react_native_1.Text, { style: exports.styles.programmeTime },
React.createElement(header_native_1.Time, { time: props.programme.start, format: isStartToday ? util_1.formatTimeShort : util_1.formatTime }),
' - ',
React.createElement(header_native_1.Time, { time: props.programme.end, format: isEndSameDay ? util_1.formatTimeShort : util_1.formatTime })),
showActions && ((_a = props.programme.actions) === null || _a === void 0 ? void 0 : _a.length) ? React.createElement(react_native_1.View, { style: exports.styles.programmeActions }, props.programme.actions.map((a, i) => React.createElement(ProgrammeActionComponent, { key: i, programme: props.programme, action: a }))) : actionstext ? React.createElement(react_native_1.View, { style: exports.styles.programmeActions },
React.createElement(react_native_1.View, { style: exports.styles.programmeAction },
React.createElement(react_native_1.Text, { style: exports.styles.programmeActionText }, actionstext))) : null)),
props.programme.icon ? React.createElement(react_native_1.View, { style: exports.styles.programmeIcon },
React.createElement(react_native_1.Image, { source: { uri: props.programme.icon, height: constants_1.SCALE * 120, width: constants_1.SCALE * 200 },
// style={{flex: 1}}
resizeMode: "cover" })) : null));
};
const ProgrammeRow = React.memo(_ProgrammeRow);
exports.default = ProgrammeRow;
function ProgrammeActionComponent(props) {
const name = util_1.useLocalised(props.action.name);
return React.createElement(react_native_1.View, { style: exports.styles.programmeAction },
React.createElement(react_native_tvfocus_1.TouchableOpacity, { isTVSelectable: false, onPress: e => handleProgrammeAction(props.programme, props.action, e) },
React.createElement(react_native_1.Text, { style: exports.styles.programmeActionText }, name)));
}
exports.ProgrammeAction = ProgrammeActionComponent;
function handleProgrammeAction(programme, action, event) {
return __awaiter(this, void 0, void 0, function* () {
for (const url of action.urls) {
try {
if (!(yield react_native_1.Linking.canOpenURL(url)))
continue;
}
catch (err) { }
yield react_native_1.Linking.openURL(url);
break;
}
});
}
exports.handleProgrammeAction = handleProgrammeAction;
function EmptyProgrammeRow() {
return React.createElement(react_native_1.View, { style: channel_row_native_1.styles.row },
React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.cell, channel_row_native_1.styles.main] }),
React.createElement(react_native_1.View, { style: [channel_row_native_1.styles.rowNotFirst, channel_row_native_1.styles.cell, exports.styles.programme, exports.styles.emptyProgramme] },
React.createElement(react_native_1.View, { style: exports.styles.programmeDetail },
React.createElement(react_native_1.Text, { style: [channel_row_native_1.styles.emptyProgrammeText, exports.styles.emptyProgrammeText] }, "No information"))));
}
exports.EmptyProgrammeRow = EmptyProgrammeRow;
exports.styles = react_native_1.StyleSheet.create({
programme: {
flex: 1,
backgroundColor: '#607d8ba0',
minHeight: constants_1.SCALE * 111,
paddingHorizontal: 0,
paddingVertical: 0,
flexDirection: 'row',
},
programmeDetail: {
flex: 1,
paddingHorizontal: constants_1.SCALE * 20,
paddingVertical: constants_1.SCALE * 15,
justifyContent: 'space-between',
},
programmeDetailTop: {
flex: 1,
},
programmeName: {
fontSize: constants_1.SCALE * 16,
marginBottom: constants_1.SCALE * 2,
},
programmeEpisodeText: {
fontSize: constants_1.SCALE * 14,
},
programmeDescriptionText: {
fontSize: constants_1.SCALE * 14,
},
programmeDetailBottom: {
marginTop: constants_1.SCALE * 10,
flexDirection: 'row',
},
programmeTime: {
flex: 1,
fontSize: constants_1.SCALE * 13,
color: '#eeeeee',
},
programmeActions: {
marginLeft: constants_1.SCALE * 5,
},
programmeAction: {
marginLeft: constants_1.SCALE * 10,
},
programmeActionText: {
color: '#eeeeee',
fontSize: constants_1.SCALE * 14,
},
programmeIcon: {
flexDirection: 'column',
justifyContent: 'center',
},
emptyProgramme: {},
emptyProgrammeText: {
fontStyle: 'normal',
fontSize: constants_1.SCALE * 16,
alignSelf: 'flex-start',
},
});