UNPKG

@tamagui/react-native-web-lite

Version:
205 lines (202 loc) 8.22 kB
import { jsx as _jsx } from "react/jsx-runtime"; import VirtualizedList from "../VirtualizedList"; import * as React from "react"; function _assert_this_initialized(self) { if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return self; } function _call_super(_this, derived, args) { return derived = _get_prototype_of(derived), _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args)); } function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } function _create_class(Constructor, protoProps, staticProps) { return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; } function _define_property(obj, key, value) { return key in obj ? Object.defineProperty(obj, key, { value, enumerable: !0, configurable: !0, writable: !0 }) : obj[key] = value, obj; } function _get_prototype_of(o) { return _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function (o2) { return o2.__proto__ || Object.getPrototypeOf(o2); }, _get_prototype_of(o); } function _inherits(subClass, superClass) { if (typeof superClass != "function" && superClass !== null) throw new TypeError("Super expression must either be null or a function"); subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: !0, configurable: !0 } }), superClass && _set_prototype_of(subClass, superClass); } function _possible_constructor_return(self, call) { return call && (_type_of(call) === "object" || typeof call == "function") ? call : _assert_this_initialized(self); } function _set_prototype_of(o, p) { return _set_prototype_of = Object.setPrototypeOf || function (o2, p2) { return o2.__proto__ = p2, o2; }, _set_prototype_of(o, p); } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj; } function _is_native_reflect_construct() { try { var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch {} return (_is_native_reflect_construct = function () { return !!result; })(); } var defaultProps = { data: [], key: null, renderItem: null, ItemSeparatorComponent: null, keyExtractor: null }, VirtualizedSectionList = /* @__PURE__ */function (_React_PureComponent) { "use strict"; _inherits(VirtualizedSectionList2, _React_PureComponent); function VirtualizedSectionList2() { _class_call_check(this, VirtualizedSectionList2); var _this; return _this = _call_super(this, VirtualizedSectionList2, arguments), _define_property(_this, "_keyExtractor", function (item, index) { var keyExtractor = _this.props.keyExtractor || _this._defaultKeyExtractor; return keyExtractor(item, index); }), _define_property(_this, "_defaultKeyExtractor", function (item, index) { return item.key != null ? item.key : String(index); }), _define_property(_this, "_captureRef", function (ref) { _this._listRef = ref; }), _define_property(_this, "_renderItem", function (itemCount) { return function (param) { var { item, index } = param; if (index === 0 || index === itemCount - 1) return null; var renderItem = _this.props.renderItem || _this._defaultRenderItem; return renderItem({ item, index, section: item }); }; }), _define_property(_this, "_defaultRenderItem", function (param) { var { item } = param; return null; }), _define_property(_this, "_onViewableItemsChanged", function (info) { _this.props.onViewableItemsChanged && _this.props.onViewableItemsChanged(info); }), _this; } return _create_class(VirtualizedSectionList2, [{ key: "scrollToLocation", value: function (params) { for (var index = params.itemIndex, i = 0; i < params.sectionIndex; i++) index += this.props.getItemCount(this.props.sections[i].data) + 2; var viewOffset = params.viewOffset || 0; if (this._listRef != null) { if (params.itemIndex > 0 && this.props.stickySectionHeadersEnabled) { var frame = this._listRef.__getFrameMetricsApprox(index - params.itemIndex, this._listRef.props); viewOffset += frame.length; } var toIndexParams = { ...params, viewOffset, index }; this._listRef.scrollToIndex(toIndexParams); } } }, { key: "getListRef", value: function () { return this._listRef; } }, { key: "render", value: function () { var _this = this, { ItemSeparatorComponent, SectionSeparatorComponent, renderItem: _renderItem, renderSectionFooter, renderSectionHeader, sections: _sections, stickySectionHeadersEnabled, ...passThroughProps } = this.props, listHeaderOffset = this.props.ListHeaderComponent ? 1 : 0, stickyHeaderIndices = this.props.stickySectionHeadersEnabled ? [] : void 0, itemCount = 0, _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0; try { for (var _iterator = this.props.sections[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) { var section = _step.value; stickyHeaderIndices?.push(itemCount + listHeaderOffset), itemCount += 2, itemCount += this.props.getItemCount(section.data); } } catch (err) { _didIteratorError = !0, _iteratorError = err; } finally { try { !_iteratorNormalCompletion && _iterator.return != null && _iterator.return(); } finally { if (_didIteratorError) throw _iteratorError; } } var renderItem = this._renderItem(itemCount); return /* @__PURE__ */_jsx(VirtualizedList, { ...passThroughProps, keyExtractor: this._keyExtractor, stickyHeaderIndices, renderItem, data: this.props.sections, getItem: function (sections, index) { return _this._getItem(_this.props, sections, index); }, getItemCount: function () { return itemCount; }, onViewableItemsChanged: this.props.onViewableItemsChanged ? this._onViewableItemsChanged : void 0, ref: this._captureRef }); } }, { key: "_getItem", value: function (props, sections, index) { if (!sections) return null; for (var itemIdx = index - 1, i = 0; i < sections.length; i++) { var section = sections[i], sectionData = section.data, itemCount = props.getItemCount(sectionData); if (itemIdx === -1 || itemIdx === itemCount) return section; if (itemIdx < itemCount) return props.getItem(sectionData, itemIdx); itemIdx -= itemCount + 2; } return null; } }]), VirtualizedSectionList2; }(React.PureComponent); VirtualizedSectionList.defaultProps = defaultProps; var VirtualizedSectionList_default = VirtualizedSectionList; export { VirtualizedSectionList_default as default }; //# sourceMappingURL=index.native.js.map