@tamagui/react-native-web-lite
Version:
React Native for Web
315 lines (314 loc) • 14.6 kB
JavaScript
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
mod
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var VirtualizedList_exports = {};
__export(VirtualizedList_exports, {
default: () => VirtualizedList_default
});
module.exports = __toCommonJS(VirtualizedList_exports);
var import_jsx_runtime = require("react/jsx-runtime"), import_react_native_web_internals = require("@tamagui/react-native-web-internals"), import_ScrollView = __toESM(require("../../../ScrollView")), import_RefreshControl = __toESM(require("../../../RefreshControl")), import_Batchinator = __toESM(require("../Batchinator")), import_ChildListCollection = __toESM(require("./ChildListCollection")), import_FillRateHelper = __toESM(require("../FillRateHelper")), import_StateSafePureComponent = __toESM(require("./StateSafePureComponent")), import_ViewabilityHelper = __toESM(require("../ViewabilityHelper")), import_VirtualizedListCellRenderer = __toESM(require("./VirtualizedListCellRenderer")), import_VirtualizedListContext = require("./VirtualizedListContext");
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 __DEV__ = process.env.NODE_ENV !== "production";
function horizontalOrDefault(horizontal) {
return horizontal ?? !1;
}
function scrollEventThrottleOrDefault(scrollEventThrottle) {
return scrollEventThrottle ?? 50;
}
var VirtualizedList = /* @__PURE__ */ function(StateSafePureComponent2) {
"use strict";
_inherits(VirtualizedList2, StateSafePureComponent2);
function VirtualizedList2(props) {
_class_call_check(this, VirtualizedList2);
var _this;
_this = _call_super(this, VirtualizedList2, [
props
]), _define_property(_this, "_captureRef", function(ref) {
_this._scrollRef = ref;
}), _define_property(_this, "_onContentSizeChange", function(width, height) {
}), // Handle content size changes
_define_property(_this, "_onLayout", function(event) {
}), // Handle layout changes
_define_property(_this, "_onScroll", function(event) {
}), _this._nestedChildLists = new import_ChildListCollection.default(), _this._viewabilityTuples = [], _this._scrollMetrics = {
contentLength: 0,
dOffset: 0,
dt: 10,
offset: 0,
timestamp: 0,
velocity: 0,
visibleLength: 0
}, _this._highestMeasuredFrameIndex = 0, _this._headerLength = 0, _this._footerLength = 0, _this._averageCellLength = 0, _this._hasWarned = {}, _this._fillRateHelper = new import_FillRateHelper.default(_this._getFrameMetrics);
var _this_props_updateCellsBatchingPeriod;
return _this._updateCellsToRenderBatcher = new import_Batchinator.default(_this._updateCellsToRender, (_this_props_updateCellsBatchingPeriod = _this.props.updateCellsBatchingPeriod) !== null && _this_props_updateCellsBatchingPeriod !== void 0 ? _this_props_updateCellsBatchingPeriod : 50), _this.props.viewabilityConfig && _this.props.onViewableItemsChanged && _this._viewabilityTuples.push({
viewabilityHelper: new import_ViewabilityHelper.default(_this.props.viewabilityConfig),
onViewableItemsChanged: _this.props.onViewableItemsChanged
}), _this;
}
return _create_class(VirtualizedList2, [
{
key: "scrollToEnd",
value: function(params) {
var animated = params ? params.animated : !0, veryLast = this.props.getItemCount(this.props.data) - 1;
if (!(veryLast < 0)) {
var frame = this.__getFrameMetricsApprox(veryLast, this.props), offset = Math.max(0, frame.offset + frame.length + this._footerLength - this._scrollMetrics.visibleLength);
if (this._scrollRef != null) {
if (this._scrollRef.scrollTo == null) {
console.warn("No scrollTo method provided. This may be because you have two nested VirtualizedLists with the same orientation, or because you are using a custom component that does not implement scrollTo.");
return;
}
this._scrollRef.scrollTo(horizontalOrDefault(this.props.horizontal) ? {
x: offset,
animated
} : {
y: offset,
animated
});
}
}
}
},
{
key: "scrollToIndex",
value: function(params) {
var { data, horizontal, getItemCount, getItemLayout, onScrollToIndexFailed } = this.props, { animated, index, viewOffset, viewPosition } = params;
if ((0, import_react_native_web_internals.invariant)(index >= 0, `scrollToIndex out of range: requested index ${index} but minimum is 0`), (0, import_react_native_web_internals.invariant)(getItemCount(data) >= 1, `scrollToIndex out of range: item length ${getItemCount(data)} but minimum is 1`), (0, import_react_native_web_internals.invariant)(index < getItemCount(data), `scrollToIndex out of range: requested index ${index} is out of 0 to ${getItemCount(data) - 1}`), !getItemLayout && index > this._highestMeasuredFrameIndex) {
(0, import_react_native_web_internals.invariant)(!!onScrollToIndexFailed, "scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed, otherwise there is no way to know the location of offscreen indices or handle failures."), onScrollToIndexFailed({
averageItemLength: this._averageCellLength,
highestMeasuredFrameIndex: this._highestMeasuredFrameIndex,
index
});
return;
}
var frame = this.__getFrameMetricsApprox(Math.floor(index), this.props), offset = Math.max(0, this._getOffsetApprox(index, this.props) - (viewPosition || 0) * (this._scrollMetrics.visibleLength - frame.length)) - (viewOffset || 0);
this._scrollRef != null && this._scrollRef.scrollTo(horizontalOrDefault(horizontal) ? {
x: offset,
animated
} : {
y: offset,
animated
});
}
},
{
key: "scrollToItem",
value: function(params) {
var { data, getItem, getItemCount, horizontal, onScrollToIndexFailed } = this.props, { animated, item, viewPosition, viewOffset } = params, index = this.props.data.indexOf(item);
if (index !== -1)
this.scrollToIndex({
animated,
index,
viewOffset,
viewPosition
});
else
for (var itemCount = getItemCount(data), i = 0; i < itemCount; i++)
if (getItem(data, i) === item) {
this.scrollToIndex({
animated,
index: i,
viewOffset,
viewPosition
});
break;
}
}
},
{
key: "scrollToOffset",
value: function(params) {
var { animated, offset } = params;
this._scrollRef != null && this._scrollRef.scrollTo(horizontalOrDefault(this.props.horizontal) ? {
x: offset,
animated
} : {
y: offset,
animated
});
}
},
{
key: "recordInteraction",
value: function() {
this._nestedChildLists.forEach(function(childList) {
childList.recordInteraction();
}), this._viewabilityTuples.forEach(function(viewabilityTuple) {
viewabilityTuple.viewabilityHelper.recordInteraction();
});
}
},
{
key: "flashScrollIndicators",
value: function() {
this._scrollRef && this._scrollRef.flashScrollIndicators && this._scrollRef.flashScrollIndicators();
}
},
{
key: "getScrollResponder",
value: function() {
if (this._scrollRef && this._scrollRef.getScrollResponder)
return this._scrollRef.getScrollResponder();
}
},
{
key: "getScrollableNode",
value: function() {
if (this._scrollRef && this._scrollRef.getScrollableNode)
return this._scrollRef.getScrollableNode();
}
},
{
key: "getScrollRef",
value: function() {
return this._scrollRef;
}
},
{
key: "setNativeProps",
value: function(props) {
this._scrollRef && this._scrollRef.setNativeProps(props);
}
},
{
key: "render",
value: function() {
var { ListEmptyComponent, ListFooterComponent, ListHeaderComponent, data, debug, disableVirtualization, getItem, getItemCount, getItemLayout, horizontal, keyExtractor, numColumns, onEndReached, onEndReachedThreshold, onLayout, onRefresh, onScroll, onScrollBeginDrag, onScrollEndDrag, onMomentumScrollBegin, onMomentumScrollEnd, onStartReached, onStartReachedThreshold, onViewableItemsChanged, refreshing, removeClippedSubviews, renderItem, viewabilityConfig, viewabilityConfigCallbackPairs, ...restProps } = this.props, itemCount = getItemCount(data);
return itemCount === 0 ? ListEmptyComponent ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ListEmptyComponent, {}) : null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ScrollView.default, {
...restProps,
ref: this._captureRef,
onContentSizeChange: this._onContentSizeChange,
onLayout: this._onLayout,
onScroll: this._onScroll,
refreshControl: onRefresh && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RefreshControl.default, {
refreshing,
onRefresh
}),
scrollEventThrottle: scrollEventThrottleOrDefault(this.props.scrollEventThrottle),
removeClippedSubviews,
children: this._renderChildren()
});
}
},
{
key: "_renderChildren",
value: function() {
for (var { data, getItem, getItemCount, renderItem } = this.props, items = [], i = 0; i < getItemCount(data); i++) {
var item = getItem(data, i);
items.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_VirtualizedListCellRenderer.default, {
cellKey: String(i),
index: i,
item,
renderItem
}, this.props.keyExtractor ? this.props.keyExtractor(item, i) : i));
}
return items;
}
},
{
// Handle scroll events
key: "__getFrameMetricsApprox",
value: function(index, props) {
var frame = {
length: this._averageCellLength,
offset: this._averageCellLength * index
};
return frame;
}
},
{
key: "_getOffsetApprox",
value: function(index, props) {
return this.__getFrameMetricsApprox(index, props).offset;
}
}
]), VirtualizedList2;
}(import_StateSafePureComponent.default);
_define_property(VirtualizedList, "contextType", import_VirtualizedListContext.VirtualizedListContext);
var VirtualizedList_default = VirtualizedList;
//# sourceMappingURL=index.js.map