// Metro module 315 (f316). import _classCallCheck from "./_classCallCheck"; import _createClass from "./_createClass"; import Module38 from "./Module38"; import * as _elementsThatOverlapOffsets from "./elementsThatOverlapOffsets"; let env326 = {}; const ListMetricsAggregator = function ListMetricsAggregator() { _classCallCheck(this, ListMetricsAggregator); this._averageCellLength = 0; this._cellMetrics = new Map(); this._highestMeasuredCellIndex = 0; this._measuredCellsLength = 0; this._measuredCellsCount = 0; this._orientation = { horizontal: false, rtl: false }; }; export default _createClass(ListMetricsAggregator, [{ key: "notifyCellLayout", value: function notifyCellLayout({ cellIndex, cellKey, orientation, layout }) { this._invalidateIfOrientationChanged(orientation); const r6 = { index: cellIndex, length: this._selectLength(layout), isMounted: true, offset: this.flowRelativeOffset(layout) }; const r17 = this._cellMetrics.get(cellKey); if (r17 && r6.offset === r17.offset && r6.length === r17.length) { r17.isMounted = true; return false; } if (r17) { this._measuredCellsLength = this._measuredCellsLength + (r6.length - r17.length); } else { this._measuredCellsLength = this._measuredCellsLength + r6.length; this._measuredCellsCount = this._measuredCellsCount + 1; } this._averageCellLength = this._measuredCellsLength / this._measuredCellsCount; this._cellMetrics.set(cellKey, r6); this._highestMeasuredCellIndex = Math.max(this._highestMeasuredCellIndex, cellIndex); return true; } }, { key: "notifyCellUnmounted", value: function notifyCellUnmounted(a0) { const r5 = this._cellMetrics.get(a0); if (r5) { r5.isMounted = false; } } }, { key: "notifyListContentLayout", value: function notifyListContentLayout({ orientation, layout }) { this._invalidateIfOrientationChanged(orientation); this._contentLength = this._selectLength(layout); } }, { key: "getAverageCellLength", value: function getAverageCellLength() { return this._averageCellLength; } }, { key: "getHighestMeasuredCellIndex", value: function getHighestMeasuredCellIndex() { return this._highestMeasuredCellIndex; } }, { key: "getCellMetricsApprox", value: function getCellMetricsApprox(a0, a1) { const cellMetrics = this.getCellMetrics(a0, a1); if (cellMetrics && cellMetrics.index === a0) { return cellMetrics; } const highestMeasuredCellIndex = this.getHighestMeasuredCellIndex(); const r1 = highestMeasuredCellIndex < a0; let offset = void 0; if (r1) { const cellMetrics2 = this.getCellMetrics(highestMeasuredCellIndex, a1); offset = cellMetrics2 ? cellMetrics2.offset + cellMetrics2.length + this._averageCellLength * (a0 - highestMeasuredCellIndex - 1) : void 0; } if (offset == null) { offset = this._averageCellLength * a0; } const { data, getItemCount } = a1; Module38(a0 >= 0 && a0 < getItemCount(data), "Tried to get frame for out of range index " + a0); return { length: this._averageCellLength, offset, index: a0, isMounted: false }; } }, { key: "getCellMetrics", value: function getCellMetrics(a0, a1) { const { data, getItem, getItemCount, getItemLayout } = a1; Module38(a0 >= 0 && a0 < getItemCount(data), "Tried to get metrics for out of range cell index " + a0); let keyExtractor = a1.keyExtractor; if (keyExtractor == null) { keyExtractor = _elementsThatOverlapOffsets.keyExtractor; } const r29 = this._cellMetrics.get(keyExtractor(getItem(data, a0), a0)); if (r29 && r29.index === a0) { return r29; } if (getItemLayout) { const r31 = getItemLayout(data, a0); return { index: a0, length: r31.length, offset: r31.offset, isMounted: true }; } return null; } }, { key: "getCellOffsetApprox", value: function getCellOffsetApprox(a0, a1) { const isInteger = Number.isInteger(a0); const getCellMetricsApprox2 = this.getCellMetricsApprox; if (isInteger) { return getCellMetricsApprox2.call(this, a0, a1).offset; } const r11 = getCellMetricsApprox2.call(this, Math.floor(a0), a1); return r11.offset + (a0 - Math.floor(a0)) * r11.length; } }, { key: "getContentLength", value: function getContentLength() { let _contentLength = this._contentLength; if (_contentLength == null) { _contentLength = 0; } return _contentLength; } }, { key: "hasContentLength", value: function hasContentLength() { return this._contentLength != null; } }, { key: "flowRelativeOffset", value: function flowRelativeOffset(a0, a1) { const _orientation = this._orientation; const { horizontal, rtl } = _orientation; if (horizontal && rtl) { const r10 = a1 == null ? this._contentLength : a1; Module38(r10 != null, "ListMetricsAggregator must be notified of list content layout before resolving offsets"); return r10 - (this._selectOffset(a0) + this._selectLength(a0)); } return this._selectOffset(a0); } }, { key: "cartesianOffset", value: function cartesianOffset(a0) { const _orientation = this._orientation; const { horizontal, rtl } = _orientation; let r7 = a0; if (horizontal) { r7 = a0; if (rtl) { Module38(this._contentLength != null, "ListMetricsAggregator must be notified of list content layout before resolving offsets"); r7 = this._contentLength - a0; } } return r7; } }, { key: "_invalidateIfOrientationChanged", value: function _invalidateIfOrientationChanged(a0) { if (a0.rtl !== this._orientation.rtl) { this._cellMetrics.clear(); } if (a0.horizontal !== this._orientation.horizontal) { this._averageCellLength = 0; this._highestMeasuredCellIndex = 0; this._measuredCellsLength = 0; this._measuredCellsCount = 0; } this._orientation = a0; } }, { key: "_selectLength", value: function _selectLength(a0) { const width = a0.width; let height = a0.height; if (this._orientation.horizontal) { height = width; } return height; } }, { key: "_selectOffset", value: function _selectOffset(a0) { const r1 = a0.x; let r3 = a0.y; if (this._orientation.horizontal) { r3 = r1; } return r3; } }]);