@react-native-macos/virtualized-lists 0.78.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,609 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow
8
+ * @format
9
+ */
10
+
11
+ import type {ViewToken} from './ViewabilityHelper';
12
+
13
+ import VirtualizedList from './VirtualizedList';
14
+ import {keyExtractor as defaultKeyExtractor} from './VirtualizeUtils';
15
+ import invariant from 'invariant';
16
+ import * as React from 'react';
17
+ type Item = any;
18
+
19
+ export type SectionBase<SectionItemT> = {
20
+ /**
21
+ * The data for rendering items in this section.
22
+ */
23
+ data: $ReadOnlyArray<SectionItemT>,
24
+ /**
25
+ * Optional key to keep track of section re-ordering. If you don't plan on re-ordering sections,
26
+ * the array index will be used by default.
27
+ */
28
+ key?: string,
29
+ // Optional props will override list-wide props just for this section.
30
+ renderItem?: ?(info: {
31
+ item: SectionItemT,
32
+ index: number,
33
+ section: SectionBase<SectionItemT>,
34
+ separators: {
35
+ highlight: () => void,
36
+ unhighlight: () => void,
37
+ updateProps: (select: 'leading' | 'trailing', newProps: Object) => void,
38
+ ...
39
+ },
40
+ ...
41
+ }) => null | React.MixedElement,
42
+ ItemSeparatorComponent?: ?React.ComponentType<any>,
43
+ keyExtractor?: (item: SectionItemT, index?: ?number) => string,
44
+ ...
45
+ };
46
+
47
+ type RequiredProps<SectionT: SectionBase<any>> = {|
48
+ sections: $ReadOnlyArray<SectionT>,
49
+ |};
50
+
51
+ type OptionalProps<SectionT: SectionBase<any>> = {|
52
+ /**
53
+ * Default renderer for every item in every section.
54
+ */
55
+ renderItem?: (info: {
56
+ item: Item,
57
+ index: number,
58
+ section: SectionT,
59
+ separators: {
60
+ highlight: () => void,
61
+ unhighlight: () => void,
62
+ updateProps: (select: 'leading' | 'trailing', newProps: Object) => void,
63
+ ...
64
+ },
65
+ ...
66
+ }) => null | React.Node,
67
+ /**
68
+ * Rendered at the top of each section. These stick to the top of the `ScrollView` by default on
69
+ * iOS. See `stickySectionHeadersEnabled`.
70
+ */
71
+ renderSectionHeader?: ?(info: {section: SectionT, ...}) => null | React.Node,
72
+ /**
73
+ * Rendered at the bottom of each section.
74
+ */
75
+ renderSectionFooter?: ?(info: {section: SectionT, ...}) => null | React.Node,
76
+ /**
77
+ * Rendered at the top and bottom of each section (note this is different from
78
+ * `ItemSeparatorComponent` which is only rendered between items). These are intended to separate
79
+ * sections from the headers above and below and typically have the same highlight response as
80
+ * `ItemSeparatorComponent`. Also receives `highlighted`, `[leading/trailing][Item/Separator]`,
81
+ * and any custom props from `separators.updateProps`.
82
+ */
83
+ SectionSeparatorComponent?: ?React.ComponentType<any>,
84
+ /**
85
+ * Makes section headers stick to the top of the screen until the next one pushes it off. Only
86
+ * enabled by default on iOS because that is the platform standard there.
87
+ */
88
+ stickySectionHeadersEnabled?: boolean,
89
+ onEndReached?: ?({distanceFromEnd: number, ...}) => void,
90
+ |};
91
+
92
+ type VirtualizedListProps = React.ElementConfig<typeof VirtualizedList>;
93
+
94
+ export type Props<SectionT> = {|
95
+ ...RequiredProps<SectionT>,
96
+ ...OptionalProps<SectionT>,
97
+ ...$Diff<
98
+ VirtualizedListProps,
99
+ {
100
+ renderItem: $PropertyType<VirtualizedListProps, 'renderItem'>,
101
+ data: $PropertyType<VirtualizedListProps, 'data'>,
102
+ ...
103
+ },
104
+ >,
105
+ |};
106
+ export type ScrollToLocationParamsType = {|
107
+ animated?: ?boolean,
108
+ itemIndex: number,
109
+ sectionIndex: number,
110
+ viewOffset?: number,
111
+ viewPosition?: number,
112
+ |};
113
+
114
+ type State = {childProps: VirtualizedListProps, ...};
115
+
116
+ /**
117
+ * Right now this just flattens everything into one list and uses VirtualizedList under the
118
+ * hood. The only operation that might not scale well is concatting the data arrays of all the
119
+ * sections when new props are received, which should be plenty fast for up to ~10,000 items.
120
+ */
121
+ class VirtualizedSectionList<
122
+ SectionT: SectionBase<any>,
123
+ > extends React.PureComponent<Props<SectionT>, State> {
124
+ scrollToLocation(params: ScrollToLocationParamsType) {
125
+ let index = params.itemIndex;
126
+ for (let i = 0; i < params.sectionIndex; i++) {
127
+ index += this.props.getItemCount(this.props.sections[i].data) + 2;
128
+ }
129
+ let viewOffset = params.viewOffset || 0;
130
+ if (this._listRef == null) {
131
+ return;
132
+ }
133
+ const listRef = this._listRef;
134
+ if (params.itemIndex > 0 && this.props.stickySectionHeadersEnabled) {
135
+ const frame = listRef
136
+ .__getListMetrics()
137
+ .getCellMetricsApprox(index - params.itemIndex, listRef.props);
138
+ viewOffset += frame.length;
139
+ }
140
+ const toIndexParams = {
141
+ ...params,
142
+ viewOffset,
143
+ index,
144
+ };
145
+ // $FlowFixMe[incompatible-use]
146
+ this._listRef.scrollToIndex(toIndexParams);
147
+ }
148
+
149
+ getListRef(): ?VirtualizedList {
150
+ return this._listRef;
151
+ }
152
+
153
+ render(): React.Node {
154
+ const {
155
+ ItemSeparatorComponent, // don't pass through, rendered with renderItem
156
+ SectionSeparatorComponent,
157
+ renderItem: _renderItem,
158
+ renderSectionFooter,
159
+ renderSectionHeader,
160
+ sections: _sections,
161
+ stickySectionHeadersEnabled,
162
+ ...passThroughProps
163
+ } = this.props;
164
+
165
+ const listHeaderOffset = this.props.ListHeaderComponent ? 1 : 0;
166
+
167
+ const stickyHeaderIndices = this.props.stickySectionHeadersEnabled
168
+ ? ([]: Array<number>)
169
+ : undefined;
170
+
171
+ let itemCount = 0;
172
+ for (const section of this.props.sections) {
173
+ // Track the section header indices
174
+ if (stickyHeaderIndices != null) {
175
+ stickyHeaderIndices.push(itemCount + listHeaderOffset);
176
+ }
177
+
178
+ // Add two for the section header and footer.
179
+ itemCount += 2;
180
+ itemCount += this.props.getItemCount(section.data);
181
+ }
182
+ const renderItem = this._renderItem(itemCount);
183
+
184
+ return (
185
+ <VirtualizedList
186
+ {...passThroughProps}
187
+ keyExtractor={this._keyExtractor}
188
+ stickyHeaderIndices={stickyHeaderIndices}
189
+ renderItem={renderItem}
190
+ data={this.props.sections}
191
+ getItem={(sections, index) =>
192
+ this._getItem(this.props, sections, index)
193
+ }
194
+ getItemCount={() => itemCount}
195
+ onViewableItemsChanged={
196
+ this.props.onViewableItemsChanged
197
+ ? this._onViewableItemsChanged
198
+ : undefined
199
+ }
200
+ ref={this._captureRef}
201
+ />
202
+ );
203
+ }
204
+
205
+ _getItem(
206
+ props: Props<SectionT>,
207
+ sections: ?$ReadOnlyArray<Item>,
208
+ index: number,
209
+ ): ?Item {
210
+ if (!sections) {
211
+ return null;
212
+ }
213
+ let itemIdx = index - 1;
214
+ for (let i = 0; i < sections.length; i++) {
215
+ const section = sections[i];
216
+ const sectionData = section.data;
217
+ const itemCount = props.getItemCount(sectionData);
218
+ if (itemIdx === -1 || itemIdx === itemCount) {
219
+ // We intend for there to be overflow by one on both ends of the list.
220
+ // This will be for headers and footers. When returning a header or footer
221
+ // item the section itself is the item.
222
+ return section;
223
+ } else if (itemIdx < itemCount) {
224
+ // If we are in the bounds of the list's data then return the item.
225
+ return props.getItem(sectionData, itemIdx);
226
+ } else {
227
+ itemIdx -= itemCount + 2; // Add two for the header and footer
228
+ }
229
+ }
230
+ return null;
231
+ }
232
+
233
+ // $FlowFixMe[missing-local-annot]
234
+ _keyExtractor = (item: Item, index: number) => {
235
+ const info = this._subExtractor(index);
236
+ return (info && info.key) || String(index);
237
+ };
238
+
239
+ _subExtractor(index: number): ?{
240
+ section: SectionT,
241
+ // Key of the section or combined key for section + item
242
+ key: string,
243
+ // Relative index within the section
244
+ index: ?number,
245
+ // True if this is the section header
246
+ header?: ?boolean,
247
+ leadingItem?: ?Item,
248
+ leadingSection?: ?SectionT,
249
+ trailingItem?: ?Item,
250
+ trailingSection?: ?SectionT,
251
+ ...
252
+ } {
253
+ let itemIndex = index;
254
+ const {getItem, getItemCount, keyExtractor, sections} = this.props;
255
+ for (let i = 0; i < sections.length; i++) {
256
+ const section = sections[i];
257
+ const sectionData = section.data;
258
+ const key = section.key || String(i);
259
+ itemIndex -= 1; // The section adds an item for the header
260
+ if (itemIndex >= getItemCount(sectionData) + 1) {
261
+ itemIndex -= getItemCount(sectionData) + 1; // The section adds an item for the footer.
262
+ } else if (itemIndex === -1) {
263
+ return {
264
+ section,
265
+ key: key + ':header',
266
+ index: null,
267
+ header: true,
268
+ trailingSection: sections[i + 1],
269
+ };
270
+ } else if (itemIndex === getItemCount(sectionData)) {
271
+ return {
272
+ section,
273
+ key: key + ':footer',
274
+ index: null,
275
+ header: false,
276
+ trailingSection: sections[i + 1],
277
+ };
278
+ } else {
279
+ const extractor =
280
+ section.keyExtractor || keyExtractor || defaultKeyExtractor;
281
+ return {
282
+ section,
283
+ key:
284
+ key + ':' + extractor(getItem(sectionData, itemIndex), itemIndex),
285
+ index: itemIndex,
286
+ leadingItem: getItem(sectionData, itemIndex - 1),
287
+ leadingSection: sections[i - 1],
288
+ trailingItem: getItem(sectionData, itemIndex + 1),
289
+ trailingSection: sections[i + 1],
290
+ };
291
+ }
292
+ }
293
+ }
294
+
295
+ _convertViewable = (viewable: ViewToken): ?ViewToken => {
296
+ invariant(viewable.index != null, 'Received a broken ViewToken');
297
+ const info = this._subExtractor(viewable.index);
298
+ if (!info) {
299
+ return null;
300
+ }
301
+ const keyExtractorWithNullableIndex = info.section.keyExtractor;
302
+ const keyExtractorWithNonNullableIndex =
303
+ this.props.keyExtractor || defaultKeyExtractor;
304
+ const key =
305
+ keyExtractorWithNullableIndex != null
306
+ ? keyExtractorWithNullableIndex(viewable.item, info.index)
307
+ : keyExtractorWithNonNullableIndex(viewable.item, info.index ?? 0);
308
+
309
+ return {
310
+ ...viewable,
311
+ index: info.index,
312
+ key,
313
+ section: info.section,
314
+ };
315
+ };
316
+
317
+ _onViewableItemsChanged = ({
318
+ viewableItems,
319
+ changed,
320
+ }: {
321
+ viewableItems: Array<ViewToken>,
322
+ changed: Array<ViewToken>,
323
+ ...
324
+ }) => {
325
+ const onViewableItemsChanged = this.props.onViewableItemsChanged;
326
+ if (onViewableItemsChanged != null) {
327
+ onViewableItemsChanged({
328
+ viewableItems: viewableItems
329
+ .map(this._convertViewable, this)
330
+ .filter(Boolean),
331
+ changed: changed.map(this._convertViewable, this).filter(Boolean),
332
+ });
333
+ }
334
+ };
335
+
336
+ _renderItem =
337
+ (listItemCount: number): $FlowFixMe =>
338
+ // eslint-disable-next-line react/no-unstable-nested-components
339
+ ({item, index}: {item: Item, index: number, ...}) => {
340
+ const info = this._subExtractor(index);
341
+ if (!info) {
342
+ return null;
343
+ }
344
+ const infoIndex = info.index;
345
+ if (infoIndex == null) {
346
+ const {section} = info;
347
+ if (info.header === true) {
348
+ const {renderSectionHeader} = this.props;
349
+ return renderSectionHeader ? renderSectionHeader({section}) : null;
350
+ } else {
351
+ const {renderSectionFooter} = this.props;
352
+ return renderSectionFooter ? renderSectionFooter({section}) : null;
353
+ }
354
+ } else {
355
+ const renderItem = info.section.renderItem || this.props.renderItem;
356
+ const SeparatorComponent = this._getSeparatorComponent(
357
+ index,
358
+ info,
359
+ listItemCount,
360
+ );
361
+ invariant(renderItem, 'no renderItem!');
362
+ return (
363
+ <ItemWithSeparator
364
+ SeparatorComponent={SeparatorComponent}
365
+ LeadingSeparatorComponent={
366
+ infoIndex === 0 ? this.props.SectionSeparatorComponent : undefined
367
+ }
368
+ cellKey={info.key}
369
+ index={infoIndex}
370
+ item={item}
371
+ leadingItem={info.leadingItem}
372
+ leadingSection={info.leadingSection}
373
+ prevCellKey={(this._subExtractor(index - 1) || {}).key}
374
+ // Callback to provide updateHighlight for this item
375
+ setSelfHighlightCallback={this._setUpdateHighlightFor}
376
+ setSelfUpdatePropsCallback={this._setUpdatePropsFor}
377
+ // Provide child ability to set highlight/updateProps for previous item using prevCellKey
378
+ updateHighlightFor={this._updateHighlightFor}
379
+ updatePropsFor={this._updatePropsFor}
380
+ renderItem={renderItem}
381
+ section={info.section}
382
+ trailingItem={info.trailingItem}
383
+ trailingSection={info.trailingSection}
384
+ inverted={!!this.props.inverted}
385
+ />
386
+ );
387
+ }
388
+ };
389
+
390
+ _updatePropsFor = (cellKey: string, value: any) => {
391
+ const updateProps = this._updatePropsMap[cellKey];
392
+ if (updateProps != null) {
393
+ updateProps(value);
394
+ }
395
+ };
396
+
397
+ _updateHighlightFor = (cellKey: string, value: boolean) => {
398
+ const updateHighlight = this._updateHighlightMap[cellKey];
399
+ if (updateHighlight != null) {
400
+ updateHighlight(value);
401
+ }
402
+ };
403
+
404
+ _setUpdateHighlightFor = (
405
+ cellKey: string,
406
+ updateHighlightFn: ?(boolean) => void,
407
+ ) => {
408
+ if (updateHighlightFn != null) {
409
+ this._updateHighlightMap[cellKey] = updateHighlightFn;
410
+ } else {
411
+ // $FlowFixMe[prop-missing]
412
+ delete this._updateHighlightFor[cellKey];
413
+ }
414
+ };
415
+
416
+ _setUpdatePropsFor = (cellKey: string, updatePropsFn: ?(boolean) => void) => {
417
+ if (updatePropsFn != null) {
418
+ this._updatePropsMap[cellKey] = updatePropsFn;
419
+ } else {
420
+ delete this._updatePropsMap[cellKey];
421
+ }
422
+ };
423
+
424
+ _getSeparatorComponent(
425
+ index: number,
426
+ info?: ?Object,
427
+ listItemCount: number,
428
+ ): ?React.ComponentType<any> {
429
+ info = info || this._subExtractor(index);
430
+ if (!info) {
431
+ return null;
432
+ }
433
+ const ItemSeparatorComponent =
434
+ info.section.ItemSeparatorComponent || this.props.ItemSeparatorComponent;
435
+ const {SectionSeparatorComponent} = this.props;
436
+ const isLastItemInList = index === listItemCount - 1;
437
+ const isLastItemInSection =
438
+ info.index === this.props.getItemCount(info.section.data) - 1;
439
+ if (SectionSeparatorComponent && isLastItemInSection) {
440
+ return SectionSeparatorComponent;
441
+ }
442
+ if (ItemSeparatorComponent && !isLastItemInSection && !isLastItemInList) {
443
+ return ItemSeparatorComponent;
444
+ }
445
+ return null;
446
+ }
447
+
448
+ _updateHighlightMap: {[string]: (boolean) => void} = {};
449
+ _updatePropsMap: {[string]: void | (boolean => void)} = {};
450
+ _listRef: ?VirtualizedList;
451
+ _captureRef = (ref: null | VirtualizedList) => {
452
+ this._listRef = ref;
453
+ };
454
+ }
455
+
456
+ type ItemWithSeparatorCommonProps = $ReadOnly<{|
457
+ leadingItem: ?Item,
458
+ leadingSection: ?Object,
459
+ section: Object,
460
+ trailingItem: ?Item,
461
+ trailingSection: ?Object,
462
+ |}>;
463
+
464
+ type ItemWithSeparatorProps = $ReadOnly<{|
465
+ ...ItemWithSeparatorCommonProps,
466
+ LeadingSeparatorComponent: ?React.ComponentType<any>,
467
+ SeparatorComponent: ?React.ComponentType<any>,
468
+ cellKey: string,
469
+ index: number,
470
+ item: Item,
471
+ setSelfHighlightCallback: (
472
+ cellKey: string,
473
+ updateFn: ?(boolean) => void,
474
+ ) => void,
475
+ setSelfUpdatePropsCallback: (
476
+ cellKey: string,
477
+ updateFn: ?(boolean) => void,
478
+ ) => void,
479
+ prevCellKey?: ?string,
480
+ updateHighlightFor: (prevCellKey: string, value: boolean) => void,
481
+ updatePropsFor: (prevCellKey: string, value: Object) => void,
482
+ renderItem: Function,
483
+ inverted: boolean,
484
+ |}>;
485
+
486
+ function ItemWithSeparator(props: ItemWithSeparatorProps): React.Node {
487
+ const {
488
+ LeadingSeparatorComponent,
489
+ // this is the trailing separator and is associated with this item
490
+ SeparatorComponent,
491
+ cellKey,
492
+ prevCellKey,
493
+ setSelfHighlightCallback,
494
+ updateHighlightFor,
495
+ setSelfUpdatePropsCallback,
496
+ updatePropsFor,
497
+ item,
498
+ index,
499
+ section,
500
+ inverted,
501
+ } = props;
502
+
503
+ const [leadingSeparatorHiglighted, setLeadingSeparatorHighlighted] =
504
+ React.useState(false);
505
+
506
+ const [separatorHighlighted, setSeparatorHighlighted] = React.useState(false);
507
+
508
+ const [leadingSeparatorProps, setLeadingSeparatorProps] = React.useState({
509
+ leadingItem: props.leadingItem,
510
+ leadingSection: props.leadingSection,
511
+ section: props.section,
512
+ trailingItem: props.item,
513
+ trailingSection: props.trailingSection,
514
+ });
515
+ const [separatorProps, setSeparatorProps] = React.useState({
516
+ leadingItem: props.item,
517
+ leadingSection: props.leadingSection,
518
+ section: props.section,
519
+ trailingItem: props.trailingItem,
520
+ trailingSection: props.trailingSection,
521
+ });
522
+
523
+ React.useEffect(() => {
524
+ setSelfHighlightCallback(cellKey, setSeparatorHighlighted);
525
+ // $FlowFixMe[incompatible-call]
526
+ setSelfUpdatePropsCallback(cellKey, setSeparatorProps);
527
+
528
+ return () => {
529
+ setSelfUpdatePropsCallback(cellKey, null);
530
+ setSelfHighlightCallback(cellKey, null);
531
+ };
532
+ }, [
533
+ cellKey,
534
+ setSelfHighlightCallback,
535
+ setSeparatorProps,
536
+ setSelfUpdatePropsCallback,
537
+ ]);
538
+
539
+ const separators = {
540
+ highlight: () => {
541
+ setLeadingSeparatorHighlighted(true);
542
+ setSeparatorHighlighted(true);
543
+ if (prevCellKey != null) {
544
+ updateHighlightFor(prevCellKey, true);
545
+ }
546
+ },
547
+ unhighlight: () => {
548
+ setLeadingSeparatorHighlighted(false);
549
+ setSeparatorHighlighted(false);
550
+ if (prevCellKey != null) {
551
+ updateHighlightFor(prevCellKey, false);
552
+ }
553
+ },
554
+ updateProps: (
555
+ select: 'leading' | 'trailing',
556
+ newProps: Partial<ItemWithSeparatorCommonProps>,
557
+ ) => {
558
+ if (select === 'leading') {
559
+ if (LeadingSeparatorComponent != null) {
560
+ setLeadingSeparatorProps({...leadingSeparatorProps, ...newProps});
561
+ } else if (prevCellKey != null) {
562
+ // update the previous item's separator
563
+ updatePropsFor(prevCellKey, {...leadingSeparatorProps, ...newProps});
564
+ }
565
+ } else if (select === 'trailing' && SeparatorComponent != null) {
566
+ setSeparatorProps({...separatorProps, ...newProps});
567
+ }
568
+ },
569
+ };
570
+ const element = props.renderItem({
571
+ item,
572
+ index,
573
+ section,
574
+ separators,
575
+ });
576
+ const leadingSeparator = LeadingSeparatorComponent != null && (
577
+ <LeadingSeparatorComponent
578
+ highlighted={leadingSeparatorHiglighted}
579
+ {...leadingSeparatorProps}
580
+ />
581
+ );
582
+ const separator = SeparatorComponent != null && (
583
+ <SeparatorComponent
584
+ highlighted={separatorHighlighted}
585
+ {...separatorProps}
586
+ />
587
+ );
588
+ const RenderSeparator = leadingSeparator || separator;
589
+ const firstSeparator = inverted === false ? leadingSeparator : separator;
590
+ const secondSeparator = inverted === false ? separator : leadingSeparator;
591
+
592
+ return (
593
+ <>
594
+ {RenderSeparator ? firstSeparator : null}
595
+ {element}
596
+ {RenderSeparator ? secondSeparator : null}
597
+ </>
598
+ );
599
+ }
600
+
601
+ module.exports = VirtualizedSectionList as component(
602
+ ref: React.RefSetter<
603
+ interface {
604
+ getListRef(): ?VirtualizedList,
605
+ scrollToLocation(params: ScrollToLocationParamsType): void,
606
+ },
607
+ >,
608
+ ...Props<SectionBase<any>>
609
+ );
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @react-native/virtualized-lists
2
+
3
+ [![Version][version-badge]][package]
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ yarn add @react-native/virtualized-lists
9
+ ```
10
+
11
+ *Note: We're using `yarn` to install deps. Feel free to change commands to use `npm` 3+ and `npx` if you like*
12
+
13
+ [version-badge]: https://img.shields.io/npm/v/@react-native/virtualized-lists?style=flat-square
14
+ [package]: https://www.npmjs.com/package/@react-native/virtualized-lists
15
+
16
+ ## Testing
17
+
18
+ To run the tests in this package, run the following commands from the React Native root folder:
19
+
20
+ 1. `yarn` to install the dependencies. You just need to run this once
21
+ 2. `yarn jest packages/virtualized-lists`.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ function clamp(min: number, value: number, max: number): number {
14
+ if (value < min) {
15
+ return min;
16
+ }
17
+ if (value > max) {
18
+ return max;
19
+ }
20
+ return value;
21
+ }
22
+
23
+ module.exports = clamp;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ /**
14
+ * Intentional info-level logging for clear separation from ad-hoc console debug logging.
15
+ */
16
+ function infoLog(...args: Array<mixed>): void {
17
+ return console.log(...args);
18
+ }
19
+
20
+ module.exports = infoLog;
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ */
9
+
10
+ export * from './Lists/VirtualizedList';