UNPKG

@livetv-app/tvguide

Version:

An Android TV Live Channels-like Electronic Programme Guide for React DOM and React Native applications.

43 lines (42 loc) 3.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgrammeList = exports.ChannelList = void 0; const React = require("react"); const react_1 = require("react"); const react_native_1 = require("react-native"); const constants_1 = require("../constants"); const util_1 = require("../util"); const channel_row_1 = require("./channel-row"); const programme_row_1 = require("./programme-row"); const _ChannelList = function ChannelList(props) { if (props.scroller) return React.createElement(react_native_1.FlatList, { style: styles.container, contentContainerStyle: props.style, data: props.channels, renderItem: ({ item: channel, index }) => { var _a; return React.createElement(channel_row_1.default, { key: channel.id, channel: channel, programmes: props.programmes, first: index === 0, tvPreferredFocus: ((_a = props.tvPreferredFocus) === null || _a === void 0 ? void 0 : _a.id) === channel.id, showChannelLogos: props.showChannelLogos, onPress: props.onPressChannel ? () => { var _a; return (_a = props.onPressChannel) === null || _a === void 0 ? void 0 : _a.call(null, channel); } : undefined }); }, keyExtractor: item => item.id, getItemLayout: (data, index) => { const ITEM_HEIGHT = 65; if (index === 0) return { length: constants_1.SCALE * ITEM_HEIGHT, offset: 0, index }; return { length: constants_1.SCALE * (ITEM_HEIGHT + 1), offset: constants_1.SCALE * (((ITEM_HEIGHT + 1) * index) - 1), index }; }, initialScrollIndex: props.channels.findIndex(c => { var _a; return c.id === ((_a = props.tvPreferredFocus) === null || _a === void 0 ? void 0 : _a.id); }), removeClippedSubviews: true }); return React.createElement(react_native_1.View, { style: [styles.container, props.style] }, props.channels.map((channel, index) => { var _a; return React.createElement(channel_row_1.default, { key: channel.id, channel: channel, programmes: props.programmes, first: index === 0, tvPreferredFocus: ((_a = props.tvPreferredFocus) === null || _a === void 0 ? void 0 : _a.id) === channel.id, showChannelLogos: props.showChannelLogos, onPress: props.onPressChannel ? () => { var _a; return (_a = props.onPressChannel) === null || _a === void 0 ? void 0 : _a.call(null, channel); } : undefined }); })); }; exports.ChannelList = React.memo(_ChannelList); const _ProgrammeList = function ProgrammeList(props) { var _a; const programmes = react_1.useMemo(() => (props.channel ? props.programmes.filter(p => { var _a; return p.channel === ((_a = props.channel) === null || _a === void 0 ? void 0 : _a.id); }) : props.programmes).sort((p1, p2) => p1.start.getTime() > p2.start.getTime() ? 1 : p1.start.getTime() < p2.start.getTime() ? -1 : 0), [(_a = props.channel) === null || _a === void 0 ? void 0 : _a.id, props.programmes]); const tvPreferredFocus = react_1.useMemo(() => util_1.getProgrammeAtTime(new Date(), programmes), [programmes]); return React.createElement(react_native_1.View, { style: styles.container }, programmes.map((programme, index) => { var _a; return React.createElement(programme_row_1.default, { key: programme.id + '-' + programme.start.getTime(), programme: programme, first: index === 0, tvPreferredFocus: ((_a = (props.tvPreferredFocus === undefined ? tvPreferredFocus : props.tvPreferredFocus)) === null || _a === void 0 ? void 0 : _a.id) === programme.id, onPress: props.onPressProgramme ? () => { var _a; return (_a = props.onPressProgramme) === null || _a === void 0 ? void 0 : _a.call(null, programme); } : undefined }); })); }; exports.ProgrammeList = React.memo(_ProgrammeList); const styles = react_native_1.StyleSheet.create({ container: {}, });