@tamagui/react-native-web-lite
Version:
React Native for Web
331 lines (328 loc) • 14.5 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import View from "../../../View";
import deepDiffer from "../deepDiffer";
import Platform from "../../../exports/Platform";
import { invariant, StyleSheet } from "@tamagui/react-native-web-internals";
import * as React from "react";
import VirtualizedList from "../VirtualizedList";
import { keyExtractor as defaultKeyExtractor } from "../VirtualizeUtils";
import memoizeOne from "memoize-one";
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;
})();
}
function removeClippedSubviewsOrDefault(removeClippedSubviews) {
return removeClippedSubviews ?? Platform.OS === "android";
}
function numColumnsOrDefault(numColumns) {
return numColumns ?? 1;
}
function isArrayLike(data) {
return typeof Object(data).length == "number";
}
var FlatList = /* @__PURE__ */function (_React_PureComponent) {
"use strict";
_inherits(FlatList2, _React_PureComponent);
function FlatList2(props) {
_class_call_check(this, FlatList2);
var _this;
return _this = _call_super(this, FlatList2, [props]), _define_property(_this, "_listRef", void 0), _define_property(_this, "_virtualizedListPairs", []), _define_property(_this, "_captureRef", function (ref) {
_this._listRef = ref;
}), _define_property(_this, "_getItem", function (data, index) {
var numColumns = numColumnsOrDefault(_this.props.numColumns);
if (numColumns > 1) {
for (var ret = [], kk = 0; kk < numColumns; kk++) {
var itemIndex = index * numColumns + kk;
if (itemIndex < data.length) {
var item = data[itemIndex];
ret.push(item);
}
}
return ret;
} else return data[index];
}), _define_property(_this, "_getItemCount", function (data) {
if (data != null && isArrayLike(data)) {
var numColumns = numColumnsOrDefault(_this.props.numColumns);
return numColumns > 1 ? Math.ceil(data.length / numColumns) : data.length;
} else return 0;
}), _define_property(_this, "_keyExtractor", function (items, index) {
var numColumns = numColumnsOrDefault(_this.props.numColumns),
_this_props_keyExtractor,
keyExtractor = (_this_props_keyExtractor = _this.props.keyExtractor) !== null && _this_props_keyExtractor !== void 0 ? _this_props_keyExtractor : defaultKeyExtractor;
return numColumns > 1 ? (invariant(Array.isArray(items), "FlatList: Encountered internal consistency error, expected each item to consist of an array with 1-%s columns; instead, received a single item.", numColumns), items.map(function (item, kk) {
return keyExtractor(item, index * numColumns + kk);
}).join(":")) : keyExtractor(items, index);
}), _define_property(_this, "_renderer", function (ListItemComponent, renderItem, columnWrapperStyle, numColumns, extraData) {
var cols = numColumnsOrDefault(numColumns),
render = function (props2) {
return ListItemComponent ? /* @__PURE__ */_jsx(ListItemComponent, {
...props2
}) : renderItem ? renderItem(props2) : null;
},
renderProp = function (info) {
if (cols > 1) {
var {
item,
index
} = info;
return invariant(Array.isArray(item), "Expected array of items with numColumns > 1"), /* @__PURE__ */_jsx(View, {
style: [styles.row, columnWrapperStyle],
children: item.map(function (it, kk) {
var element = render({
item: it,
index: index * cols + kk,
separators: info.separators
});
return element != null ? /* @__PURE__ */_jsx(React.Fragment, {
children: element
}, kk) : null;
})
});
} else return render(info);
};
return ListItemComponent ? {
ListItemComponent: renderProp
} : {
renderItem: renderProp
};
}),
// $FlowFixMe[missing-local-annot]
_define_property(_this, "_memoizedRenderer", memoizeOne(_this._renderer)), _this._checkProps(_this.props), _this.props.viewabilityConfigCallbackPairs ? _this._virtualizedListPairs = _this.props.viewabilityConfigCallbackPairs.map(function (pair) {
return {
viewabilityConfig: pair.viewabilityConfig,
onViewableItemsChanged: _this._createOnViewableItemsChanged(pair.onViewableItemsChanged)
};
}) : _this.props.onViewableItemsChanged && _this._virtualizedListPairs.push({
viewabilityConfig: _this.props.viewabilityConfig,
onViewableItemsChanged: _this._createOnViewableItemsChanged(_this.props.onViewableItemsChanged)
}), _this;
}
return _create_class(FlatList2, [{
/**
* Scrolls to the end of the content. May be janky without `getItemLayout` prop.
*/
key: "scrollToEnd",
value: function (params) {
this._listRef && this._listRef.scrollToEnd(params);
}
}, {
/**
* Scrolls to the item at the specified index such that it is positioned in the viewable area
* such that `viewPosition` 0 places it at the top, 1 at the bottom, and 0.5 centered in the
* middle. `viewOffset` is a fixed number of pixels to offset the final target position.
*
* Note: cannot scroll to locations outside the render window without specifying the
* `getItemLayout` prop.
*/
key: "scrollToIndex",
value: function (params) {
this._listRef && this._listRef.scrollToIndex(params);
}
}, {
/**
* Requires linear scan through data - use `scrollToIndex` instead if possible.
*
* Note: cannot scroll to locations outside the render window without specifying the
* `getItemLayout` prop.
*/
key: "scrollToItem",
value: function (params) {
this._listRef && this._listRef.scrollToItem(params);
}
}, {
/**
* Scroll to a specific content pixel offset in the list.
*
* Check out [scrollToOffset](docs/virtualizedlist.html#scrolltooffset) of VirtualizedList
*/
key: "scrollToOffset",
value: function (params) {
this._listRef && this._listRef.scrollToOffset(params);
}
}, {
/**
* Tells the list an interaction has occurred, which should trigger viewability calculations, e.g.
* if `waitForInteractions` is true and the user has not scrolled. This is typically called by
* taps on items or by navigation actions.
*/
key: "recordInteraction",
value: function () {
this._listRef && this._listRef.recordInteraction();
}
}, {
/**
* Displays the scroll indicators momentarily.
*
* @platform ios
*/
key: "flashScrollIndicators",
value: function () {
this._listRef && this._listRef.flashScrollIndicators();
}
}, {
/**
* Provides a handle to the underlying scroll responder.
*/
key: "getScrollResponder",
value: function () {
if (this._listRef) return this._listRef.getScrollResponder();
}
}, {
/**
* Provides a reference to the underlying host component
*/
key: "getNativeScrollRef",
value: function () {
if (this._listRef) return this._listRef.getScrollRef();
}
}, {
key: "getScrollableNode",
value: function () {
if (this._listRef) return this._listRef.getScrollableNode();
}
}, {
key: "componentDidUpdate",
value: function (prevProps) {
invariant(prevProps.numColumns === this.props.numColumns, "Changing numColumns on the fly is not supported. Change the key prop on FlatList when changing the number of columns to force a fresh render of the component."), invariant(prevProps.onViewableItemsChanged === this.props.onViewableItemsChanged, "Changing onViewableItemsChanged on the fly is not supported"), invariant(!deepDiffer(prevProps.viewabilityConfig, this.props.viewabilityConfig), "Changing viewabilityConfig on the fly is not supported"), invariant(prevProps.viewabilityConfigCallbackPairs === this.props.viewabilityConfigCallbackPairs, "Changing viewabilityConfigCallbackPairs on the fly is not supported"), this._checkProps(this.props);
}
}, {
key: "_checkProps",
value: function (props) {
var {
getItem,
getItemCount,
horizontal,
columnWrapperStyle,
onViewableItemsChanged,
viewabilityConfigCallbackPairs
} = props,
numColumns = numColumnsOrDefault(this.props.numColumns);
invariant(!getItem && !getItemCount, "FlatList does not support custom data formats."), numColumns > 1 ? invariant(!horizontal, "numColumns does not support horizontal.") : invariant(!columnWrapperStyle, "columnWrapperStyle not supported for single column lists"), invariant(!(onViewableItemsChanged && viewabilityConfigCallbackPairs), "FlatList does not support setting both onViewableItemsChanged and viewabilityConfigCallbackPairs.");
}
}, {
key: "_pushMultiColumnViewable",
value: function (arr, v) {
var numColumns = numColumnsOrDefault(this.props.numColumns),
_this_props_keyExtractor,
keyExtractor = (_this_props_keyExtractor = this.props.keyExtractor) !== null && _this_props_keyExtractor !== void 0 ? _this_props_keyExtractor : defaultKeyExtractor;
v.item.forEach(function (item, ii) {
invariant(v.index != null, "Missing index!");
var index = v.index * numColumns + ii;
arr.push({
...v,
item,
key: keyExtractor(item, index),
index
});
});
}
}, {
key: "_createOnViewableItemsChanged",
value: function (onViewableItemsChanged) {
var _this = this;
return function (info) {
var numColumns = numColumnsOrDefault(_this.props.numColumns);
if (onViewableItemsChanged) if (numColumns > 1) {
var changed = [],
viewableItems = [];
info.viewableItems.forEach(function (v) {
return _this._pushMultiColumnViewable(viewableItems, v);
}), info.changed.forEach(function (v) {
return _this._pushMultiColumnViewable(changed, v);
}), onViewableItemsChanged({
viewableItems,
changed
});
} else onViewableItemsChanged(info);
};
}
}, {
key: "render",
value: function () {
var {
numColumns,
columnWrapperStyle,
removeClippedSubviews: _removeClippedSubviews,
strictMode = !1,
...restProps
} = this.props,
renderer = strictMode ? this._memoizedRenderer : this._renderer;
return /* @__PURE__ */_jsx(VirtualizedList, {
...restProps,
getItem: this._getItem,
getItemCount: this._getItemCount,
keyExtractor: this._keyExtractor,
ref: this._captureRef,
viewabilityConfigCallbackPairs: this._virtualizedListPairs,
removeClippedSubviews: removeClippedSubviewsOrDefault(_removeClippedSubviews),
...renderer(this.props.ListItemComponent, this.props.renderItem, columnWrapperStyle, numColumns, this.props.extraData)
});
}
}]), FlatList2;
}(React.PureComponent),
styles = StyleSheet.create({
row: {
flexDirection: "row"
}
}),
FlatList_default = FlatList;
export { FlatList_default as default };
//# sourceMappingURL=index.native.js.map