UNPKG

@tamagui/react-native-web-lite

Version:
228 lines (225 loc) 8.93 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import View from "../../../View"; import { StyleSheet, invariant } from "@tamagui/react-native-web-internals"; import { VirtualizedListCellContextProvider } from "./VirtualizedListContext.native.js"; 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 CellRenderer = /* @__PURE__ */function (_React_Component) { "use strict"; _inherits(CellRenderer2, _React_Component); function CellRenderer2() { _class_call_check(this, CellRenderer2); var _this; return _this = _call_super(this, CellRenderer2, arguments), _define_property(_this, "state", { separatorProps: { highlighted: !1, leadingItem: _this.props.item } }), // TODO: consider factoring separator stuff out of VirtualizedList into FlatList since it's not // reused by SectionList and we can keep VirtualizedList simpler. // $FlowFixMe[missing-local-annot] _define_property(_this, "_separators", { highlight: function () { var _this_props_onUpdateSeparators, _this_props, { cellKey, prevCellKey } = _this.props; (_this_props_onUpdateSeparators = (_this_props = _this.props).onUpdateSeparators) === null || _this_props_onUpdateSeparators === void 0 || _this_props_onUpdateSeparators.call(_this_props, [cellKey, prevCellKey], { highlighted: !0 }); }, unhighlight: function () { var _this_props_onUpdateSeparators, _this_props, { cellKey, prevCellKey } = _this.props; (_this_props_onUpdateSeparators = (_this_props = _this.props).onUpdateSeparators) === null || _this_props_onUpdateSeparators === void 0 || _this_props_onUpdateSeparators.call(_this_props, [cellKey, prevCellKey], { highlighted: !1 }); }, updateProps: function (select, newProps) { var _this_props_onUpdateSeparators, _this_props, { cellKey, prevCellKey } = _this.props; (_this_props_onUpdateSeparators = (_this_props = _this.props).onUpdateSeparators) === null || _this_props_onUpdateSeparators === void 0 || _this_props_onUpdateSeparators.call(_this_props, [select === "leading" ? prevCellKey : cellKey], newProps); } }), _define_property(_this, "_onLayout", function (nativeEvent) { var _this_props_onCellLayout, _this_props; (_this_props_onCellLayout = (_this_props = _this.props).onCellLayout) === null || _this_props_onCellLayout === void 0 || _this_props_onCellLayout.call(_this_props, nativeEvent, _this.props.cellKey, _this.props.index); }), _this; } return _create_class(CellRenderer2, [{ key: "updateSeparatorProps", value: function (newProps) { this.setState(function (state) { return { separatorProps: { ...state.separatorProps, ...newProps } }; }); } }, { key: "componentWillUnmount", value: function () { var _this_props_onUnmount, _this_props; (_this_props_onUnmount = (_this_props = this.props).onUnmount) === null || _this_props_onUnmount === void 0 || _this_props_onUnmount.call(_this_props, this.props.cellKey); } }, { key: "_renderElement", value: function (renderItem, ListItemComponent, item, index) { if (renderItem && ListItemComponent && console.warn("VirtualizedList: Both ListItemComponent and renderItem props are present. ListItemComponent will take precedence over renderItem."), ListItemComponent) return /* @__PURE__ */React.createElement(ListItemComponent, { item, index, separators: this._separators }); if (renderItem) return renderItem({ item, index, separators: this._separators }); invariant(!1, "VirtualizedList: Either ListItemComponent or renderItem props are required but none were found."); } }, { key: "render", value: function () { var { CellRendererComponent, ItemSeparatorComponent, ListItemComponent, cellKey, horizontal, item, index, inversionStyle, onCellFocusCapture, onCellLayout, renderItem } = this.props, element = this._renderElement(renderItem, ListItemComponent, item, index), itemSeparator = /* @__PURE__ */React.isValidElement(ItemSeparatorComponent) ? // $FlowFixMe[incompatible-type] ItemSeparatorComponent : // $FlowFixMe[incompatible-type] ItemSeparatorComponent && /* @__PURE__ */_jsx(ItemSeparatorComponent, { ...this.state.separatorProps }), cellStyle = inversionStyle ? horizontal ? [styles.rowReverse, inversionStyle] : [styles.columnReverse, inversionStyle] : horizontal ? [styles.row, inversionStyle] : inversionStyle, result = CellRendererComponent ? /* @__PURE__ */_jsxs(CellRendererComponent, { cellKey, index, item, style: cellStyle, onFocusCapture: onCellFocusCapture, ...(onCellLayout && { onLayout: this._onLayout }), children: [element, itemSeparator] }) : /* @__PURE__ */_jsxs(View, { style: cellStyle, onFocusCapture: onCellFocusCapture, ...(onCellLayout && { onLayout: this._onLayout }), children: [element, itemSeparator] }); return /* @__PURE__ */_jsx(VirtualizedListCellContextProvider, { cellKey: this.props.cellKey, children: result }); } }], [{ key: "getDerivedStateFromProps", value: function (props, prevState) { return { separatorProps: { ...prevState.separatorProps, leadingItem: props.item } }; } }]), CellRenderer2; }(React.Component); var styles = StyleSheet.create({ row: { flexDirection: "row" }, rowReverse: { flexDirection: "row-reverse" }, columnReverse: { flexDirection: "column-reverse" } }); export { CellRenderer as default }; //# sourceMappingURL=VirtualizedListCellRenderer.native.js.map