@legendapp/list 3.0.0-beta.32 → 3.0.0-beta.33

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.
Files changed (54) hide show
  1. package/README.md +7 -1
  2. package/animated.d.ts +600 -6
  3. package/animated.js +2 -2
  4. package/animated.mjs +1 -1
  5. package/index.d.ts +454 -108
  6. package/index.js +81 -32
  7. package/index.mjs +81 -32
  8. package/index.native.js +89 -44
  9. package/index.native.mjs +88 -43
  10. package/keyboard-controller.d.ts +611 -6
  11. package/keyboard-controller.js +2 -2
  12. package/keyboard-controller.mjs +1 -1
  13. package/keyboard.d.ts +204 -8
  14. package/keyboard.js +66 -52
  15. package/keyboard.mjs +69 -54
  16. package/{index.d.mts → list-react-native.d.ts} +95 -32
  17. package/list-react-native.js +4234 -0
  18. package/list-react-native.mjs +4204 -0
  19. package/{index.native.d.mts → list-react.d.ts} +355 -40
  20. package/list-react.js +4426 -0
  21. package/list-react.mjs +4396 -0
  22. package/package.json +52 -1
  23. package/reanimated.d.ts +595 -7
  24. package/reanimated.js +156 -11
  25. package/reanimated.mjs +153 -8
  26. package/section-list.d.ts +610 -14
  27. package/section-list.js +6 -6
  28. package/section-list.mjs +1 -1
  29. package/animated.d.mts +0 -9
  30. package/animated.native.d.mts +0 -9
  31. package/animated.native.d.ts +0 -9
  32. package/animated.native.js +0 -9
  33. package/animated.native.mjs +0 -7
  34. package/index.native.d.ts +0 -817
  35. package/keyboard-controller.d.mts +0 -12
  36. package/keyboard-controller.native.d.mts +0 -12
  37. package/keyboard-controller.native.d.ts +0 -12
  38. package/keyboard-controller.native.js +0 -69
  39. package/keyboard-controller.native.mjs +0 -48
  40. package/keyboard.d.mts +0 -13
  41. package/keyboard.native.d.mts +0 -13
  42. package/keyboard.native.d.ts +0 -13
  43. package/keyboard.native.js +0 -399
  44. package/keyboard.native.mjs +0 -377
  45. package/reanimated.d.mts +0 -18
  46. package/reanimated.native.d.mts +0 -18
  47. package/reanimated.native.d.ts +0 -18
  48. package/reanimated.native.js +0 -89
  49. package/reanimated.native.mjs +0 -65
  50. package/section-list.d.mts +0 -112
  51. package/section-list.native.d.mts +0 -112
  52. package/section-list.native.d.ts +0 -112
  53. package/section-list.native.js +0 -293
  54. package/section-list.native.mjs +0 -271
@@ -1,112 +0,0 @@
1
- import * as react_native from 'react-native';
2
- import { SectionListData, SectionBase, SectionListRenderItemInfo, SectionListScrollParams } from 'react-native';
3
- import * as React from 'react';
4
- import { LegendListProps, LegendListRef } from '@legendapp/list';
5
-
6
- type SectionListSeparatorProps<ItemT, SectionT> = {
7
- leadingItem?: ItemT;
8
- leadingSection?: SectionListData<ItemT, SectionT>;
9
- section: SectionListData<ItemT, SectionT>;
10
- trailingItem?: ItemT;
11
- trailingSection?: SectionListData<ItemT, SectionT>;
12
- };
13
- type SectionHeaderItem<SectionT> = {
14
- kind: "header";
15
- key: string;
16
- section: SectionT;
17
- sectionIndex: number;
18
- };
19
- type SectionFooterItem<SectionT> = {
20
- kind: "footer";
21
- key: string;
22
- section: SectionT;
23
- sectionIndex: number;
24
- };
25
- type SectionBodyItem<ItemT, SectionT> = {
26
- kind: "item";
27
- key: string;
28
- section: SectionT;
29
- sectionIndex: number;
30
- item: ItemT;
31
- itemIndex: number;
32
- absoluteItemIndex: number;
33
- };
34
- type SectionItemSeparator<ItemT, SectionT> = {
35
- kind: "item-separator";
36
- key: string;
37
- section: SectionT;
38
- sectionIndex: number;
39
- leadingItem: ItemT;
40
- leadingItemIndex: number;
41
- trailingItem?: ItemT;
42
- };
43
- type SectionSeparator<SectionT> = {
44
- kind: "section-separator";
45
- key: string;
46
- leadingSection: SectionT;
47
- leadingSectionIndex: number;
48
- trailingSection?: SectionT;
49
- };
50
- type FlatSectionListItem<ItemT, SectionT> = SectionHeaderItem<SectionT> | SectionFooterItem<SectionT> | SectionBodyItem<ItemT, SectionT> | SectionItemSeparator<ItemT, SectionT> | SectionSeparator<SectionT>;
51
- type SectionMeta = {
52
- header?: number;
53
- footer?: number;
54
- items: number[];
55
- };
56
- type BuildSectionListDataResult<ItemT, SectionT> = {
57
- data: Array<FlatSectionListItem<ItemT, SectionT>>;
58
- sectionMeta: SectionMeta[];
59
- stickyHeaderIndices: number[];
60
- };
61
-
62
- type SectionListViewToken<ItemT, SectionT> = {
63
- item: ItemT;
64
- key: string;
65
- index: number;
66
- isViewable: boolean;
67
- section: SectionListData<ItemT, SectionT>;
68
- };
69
- type SectionListOnViewableItemsChanged<ItemT, SectionT> = ((info: {
70
- viewableItems: Array<SectionListViewToken<ItemT, SectionT>>;
71
- changed: Array<SectionListViewToken<ItemT, SectionT>>;
72
- }) => void) | null;
73
- type SectionListLegendProps<ItemT, SectionT> = Omit<LegendListProps<FlatSectionListItem<ItemT, SectionT>>, "data" | "children" | "renderItem" | "keyExtractor" | "ItemSeparatorComponent" | "getItemType" | "getFixedItemSize" | "stickyHeaderIndices" | "numColumns" | "columnWrapperStyle" | "onViewableItemsChanged">;
74
- type SectionListProps<ItemT, SectionT extends SectionBase<ItemT> = SectionBase<ItemT>> = SectionListLegendProps<ItemT, SectionT> & {
75
- sections: ReadonlyArray<SectionListData<ItemT, SectionT>>;
76
- extraData?: any;
77
- renderItem?: (info: SectionListRenderItemInfo<ItemT, SectionT>) => React.ReactElement | null;
78
- renderSectionHeader?: (info: {
79
- section: SectionListData<ItemT, SectionT>;
80
- }) => React.ReactElement | null;
81
- renderSectionFooter?: (info: {
82
- section: SectionListData<ItemT, SectionT>;
83
- }) => React.ReactElement | null;
84
- ItemSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null;
85
- SectionSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | React.ReactElement | null;
86
- keyExtractor?: (item: ItemT, index: number) => string;
87
- stickySectionHeadersEnabled?: boolean;
88
- onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT>;
89
- };
90
- type SectionListRef = LegendListRef & {
91
- scrollToLocation(params: SectionListScrollParams): void;
92
- };
93
- declare const SectionList: (<ItemT, SectionT extends SectionBase<ItemT, react_native.DefaultSectionT>>(props: SectionListLegendProps<ItemT, SectionT> & {
94
- sections: readonly SectionListData<ItemT, SectionT>[];
95
- extraData?: any;
96
- renderItem?: ((info: SectionListRenderItemInfo<ItemT, SectionT>) => React.ReactElement | null) | undefined;
97
- renderSectionHeader?: ((info: {
98
- section: SectionListData<ItemT, SectionT>;
99
- }) => React.ReactElement | null) | undefined;
100
- renderSectionFooter?: ((info: {
101
- section: SectionListData<ItemT, SectionT>;
102
- }) => React.ReactElement | null) | undefined;
103
- ItemSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
104
- SectionSeparatorComponent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
105
- keyExtractor?: ((item: ItemT, index: number) => string) | undefined;
106
- stickySectionHeadersEnabled?: boolean;
107
- onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT> | undefined;
108
- } & React.RefAttributes<SectionListRef>) => React.ReactNode) & {
109
- displayName?: string;
110
- };
111
-
112
- export { type BuildSectionListDataResult, type FlatSectionListItem, SectionList, type SectionListOnViewableItemsChanged, type SectionListProps, type SectionListRef, type SectionListSeparatorProps, type SectionListViewToken, type SectionMeta };
@@ -1,112 +0,0 @@
1
- import * as react_native from 'react-native';
2
- import { SectionListData, SectionBase, SectionListRenderItemInfo, SectionListScrollParams } from 'react-native';
3
- import * as React from 'react';
4
- import { LegendListProps, LegendListRef } from '@legendapp/list';
5
-
6
- type SectionListSeparatorProps<ItemT, SectionT> = {
7
- leadingItem?: ItemT;
8
- leadingSection?: SectionListData<ItemT, SectionT>;
9
- section: SectionListData<ItemT, SectionT>;
10
- trailingItem?: ItemT;
11
- trailingSection?: SectionListData<ItemT, SectionT>;
12
- };
13
- type SectionHeaderItem<SectionT> = {
14
- kind: "header";
15
- key: string;
16
- section: SectionT;
17
- sectionIndex: number;
18
- };
19
- type SectionFooterItem<SectionT> = {
20
- kind: "footer";
21
- key: string;
22
- section: SectionT;
23
- sectionIndex: number;
24
- };
25
- type SectionBodyItem<ItemT, SectionT> = {
26
- kind: "item";
27
- key: string;
28
- section: SectionT;
29
- sectionIndex: number;
30
- item: ItemT;
31
- itemIndex: number;
32
- absoluteItemIndex: number;
33
- };
34
- type SectionItemSeparator<ItemT, SectionT> = {
35
- kind: "item-separator";
36
- key: string;
37
- section: SectionT;
38
- sectionIndex: number;
39
- leadingItem: ItemT;
40
- leadingItemIndex: number;
41
- trailingItem?: ItemT;
42
- };
43
- type SectionSeparator<SectionT> = {
44
- kind: "section-separator";
45
- key: string;
46
- leadingSection: SectionT;
47
- leadingSectionIndex: number;
48
- trailingSection?: SectionT;
49
- };
50
- type FlatSectionListItem<ItemT, SectionT> = SectionHeaderItem<SectionT> | SectionFooterItem<SectionT> | SectionBodyItem<ItemT, SectionT> | SectionItemSeparator<ItemT, SectionT> | SectionSeparator<SectionT>;
51
- type SectionMeta = {
52
- header?: number;
53
- footer?: number;
54
- items: number[];
55
- };
56
- type BuildSectionListDataResult<ItemT, SectionT> = {
57
- data: Array<FlatSectionListItem<ItemT, SectionT>>;
58
- sectionMeta: SectionMeta[];
59
- stickyHeaderIndices: number[];
60
- };
61
-
62
- type SectionListViewToken<ItemT, SectionT> = {
63
- item: ItemT;
64
- key: string;
65
- index: number;
66
- isViewable: boolean;
67
- section: SectionListData<ItemT, SectionT>;
68
- };
69
- type SectionListOnViewableItemsChanged<ItemT, SectionT> = ((info: {
70
- viewableItems: Array<SectionListViewToken<ItemT, SectionT>>;
71
- changed: Array<SectionListViewToken<ItemT, SectionT>>;
72
- }) => void) | null;
73
- type SectionListLegendProps<ItemT, SectionT> = Omit<LegendListProps<FlatSectionListItem<ItemT, SectionT>>, "data" | "children" | "renderItem" | "keyExtractor" | "ItemSeparatorComponent" | "getItemType" | "getFixedItemSize" | "stickyHeaderIndices" | "numColumns" | "columnWrapperStyle" | "onViewableItemsChanged">;
74
- type SectionListProps<ItemT, SectionT extends SectionBase<ItemT> = SectionBase<ItemT>> = SectionListLegendProps<ItemT, SectionT> & {
75
- sections: ReadonlyArray<SectionListData<ItemT, SectionT>>;
76
- extraData?: any;
77
- renderItem?: (info: SectionListRenderItemInfo<ItemT, SectionT>) => React.ReactElement | null;
78
- renderSectionHeader?: (info: {
79
- section: SectionListData<ItemT, SectionT>;
80
- }) => React.ReactElement | null;
81
- renderSectionFooter?: (info: {
82
- section: SectionListData<ItemT, SectionT>;
83
- }) => React.ReactElement | null;
84
- ItemSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null;
85
- SectionSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | React.ReactElement | null;
86
- keyExtractor?: (item: ItemT, index: number) => string;
87
- stickySectionHeadersEnabled?: boolean;
88
- onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT>;
89
- };
90
- type SectionListRef = LegendListRef & {
91
- scrollToLocation(params: SectionListScrollParams): void;
92
- };
93
- declare const SectionList: (<ItemT, SectionT extends SectionBase<ItemT, react_native.DefaultSectionT>>(props: SectionListLegendProps<ItemT, SectionT> & {
94
- sections: readonly SectionListData<ItemT, SectionT>[];
95
- extraData?: any;
96
- renderItem?: ((info: SectionListRenderItemInfo<ItemT, SectionT>) => React.ReactElement | null) | undefined;
97
- renderSectionHeader?: ((info: {
98
- section: SectionListData<ItemT, SectionT>;
99
- }) => React.ReactElement | null) | undefined;
100
- renderSectionFooter?: ((info: {
101
- section: SectionListData<ItemT, SectionT>;
102
- }) => React.ReactElement | null) | undefined;
103
- ItemSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
104
- SectionSeparatorComponent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
105
- keyExtractor?: ((item: ItemT, index: number) => string) | undefined;
106
- stickySectionHeadersEnabled?: boolean;
107
- onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT> | undefined;
108
- } & React.RefAttributes<SectionListRef>) => React.ReactNode) & {
109
- displayName?: string;
110
- };
111
-
112
- export { type BuildSectionListDataResult, type FlatSectionListItem, SectionList, type SectionListOnViewableItemsChanged, type SectionListProps, type SectionListRef, type SectionListSeparatorProps, type SectionListViewToken, type SectionMeta };
@@ -1,112 +0,0 @@
1
- import * as react_native from 'react-native';
2
- import { SectionListData, SectionBase, SectionListRenderItemInfo, SectionListScrollParams } from 'react-native';
3
- import * as React from 'react';
4
- import { LegendListProps, LegendListRef } from '@legendapp/list';
5
-
6
- type SectionListSeparatorProps<ItemT, SectionT> = {
7
- leadingItem?: ItemT;
8
- leadingSection?: SectionListData<ItemT, SectionT>;
9
- section: SectionListData<ItemT, SectionT>;
10
- trailingItem?: ItemT;
11
- trailingSection?: SectionListData<ItemT, SectionT>;
12
- };
13
- type SectionHeaderItem<SectionT> = {
14
- kind: "header";
15
- key: string;
16
- section: SectionT;
17
- sectionIndex: number;
18
- };
19
- type SectionFooterItem<SectionT> = {
20
- kind: "footer";
21
- key: string;
22
- section: SectionT;
23
- sectionIndex: number;
24
- };
25
- type SectionBodyItem<ItemT, SectionT> = {
26
- kind: "item";
27
- key: string;
28
- section: SectionT;
29
- sectionIndex: number;
30
- item: ItemT;
31
- itemIndex: number;
32
- absoluteItemIndex: number;
33
- };
34
- type SectionItemSeparator<ItemT, SectionT> = {
35
- kind: "item-separator";
36
- key: string;
37
- section: SectionT;
38
- sectionIndex: number;
39
- leadingItem: ItemT;
40
- leadingItemIndex: number;
41
- trailingItem?: ItemT;
42
- };
43
- type SectionSeparator<SectionT> = {
44
- kind: "section-separator";
45
- key: string;
46
- leadingSection: SectionT;
47
- leadingSectionIndex: number;
48
- trailingSection?: SectionT;
49
- };
50
- type FlatSectionListItem<ItemT, SectionT> = SectionHeaderItem<SectionT> | SectionFooterItem<SectionT> | SectionBodyItem<ItemT, SectionT> | SectionItemSeparator<ItemT, SectionT> | SectionSeparator<SectionT>;
51
- type SectionMeta = {
52
- header?: number;
53
- footer?: number;
54
- items: number[];
55
- };
56
- type BuildSectionListDataResult<ItemT, SectionT> = {
57
- data: Array<FlatSectionListItem<ItemT, SectionT>>;
58
- sectionMeta: SectionMeta[];
59
- stickyHeaderIndices: number[];
60
- };
61
-
62
- type SectionListViewToken<ItemT, SectionT> = {
63
- item: ItemT;
64
- key: string;
65
- index: number;
66
- isViewable: boolean;
67
- section: SectionListData<ItemT, SectionT>;
68
- };
69
- type SectionListOnViewableItemsChanged<ItemT, SectionT> = ((info: {
70
- viewableItems: Array<SectionListViewToken<ItemT, SectionT>>;
71
- changed: Array<SectionListViewToken<ItemT, SectionT>>;
72
- }) => void) | null;
73
- type SectionListLegendProps<ItemT, SectionT> = Omit<LegendListProps<FlatSectionListItem<ItemT, SectionT>>, "data" | "children" | "renderItem" | "keyExtractor" | "ItemSeparatorComponent" | "getItemType" | "getFixedItemSize" | "stickyHeaderIndices" | "numColumns" | "columnWrapperStyle" | "onViewableItemsChanged">;
74
- type SectionListProps<ItemT, SectionT extends SectionBase<ItemT> = SectionBase<ItemT>> = SectionListLegendProps<ItemT, SectionT> & {
75
- sections: ReadonlyArray<SectionListData<ItemT, SectionT>>;
76
- extraData?: any;
77
- renderItem?: (info: SectionListRenderItemInfo<ItemT, SectionT>) => React.ReactElement | null;
78
- renderSectionHeader?: (info: {
79
- section: SectionListData<ItemT, SectionT>;
80
- }) => React.ReactElement | null;
81
- renderSectionFooter?: (info: {
82
- section: SectionListData<ItemT, SectionT>;
83
- }) => React.ReactElement | null;
84
- ItemSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null;
85
- SectionSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | React.ReactElement | null;
86
- keyExtractor?: (item: ItemT, index: number) => string;
87
- stickySectionHeadersEnabled?: boolean;
88
- onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT>;
89
- };
90
- type SectionListRef = LegendListRef & {
91
- scrollToLocation(params: SectionListScrollParams): void;
92
- };
93
- declare const SectionList: (<ItemT, SectionT extends SectionBase<ItemT, react_native.DefaultSectionT>>(props: SectionListLegendProps<ItemT, SectionT> & {
94
- sections: readonly SectionListData<ItemT, SectionT>[];
95
- extraData?: any;
96
- renderItem?: ((info: SectionListRenderItemInfo<ItemT, SectionT>) => React.ReactElement | null) | undefined;
97
- renderSectionHeader?: ((info: {
98
- section: SectionListData<ItemT, SectionT>;
99
- }) => React.ReactElement | null) | undefined;
100
- renderSectionFooter?: ((info: {
101
- section: SectionListData<ItemT, SectionT>;
102
- }) => React.ReactElement | null) | undefined;
103
- ItemSeparatorComponent?: React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
104
- SectionSeparatorComponent?: React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ComponentType<SectionListSeparatorProps<ItemT, SectionT>> | null | undefined;
105
- keyExtractor?: ((item: ItemT, index: number) => string) | undefined;
106
- stickySectionHeadersEnabled?: boolean;
107
- onViewableItemsChanged?: SectionListOnViewableItemsChanged<ItemT, SectionT> | undefined;
108
- } & React.RefAttributes<SectionListRef>) => React.ReactNode) & {
109
- displayName?: string;
110
- };
111
-
112
- export { type BuildSectionListDataResult, type FlatSectionListItem, SectionList, type SectionListOnViewableItemsChanged, type SectionListProps, type SectionListRef, type SectionListSeparatorProps, type SectionListViewToken, type SectionMeta };
@@ -1,293 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
- var reactNative = require('react-native');
5
- var list = require('@legendapp/list');
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n.default = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
-
27
- // src/section-list/SectionList.tsx
28
-
29
- // src/section-list/flattenSections.ts
30
- var defaultKeyExtractor = (item, index) => {
31
- var _a;
32
- const key = (_a = item == null ? void 0 : item.key) != null ? _a : item == null ? void 0 : item.id;
33
- return key != null ? String(key) : String(index);
34
- };
35
- var getSectionKey = (section, sectionIndex) => {
36
- var _a;
37
- return (_a = section.key) != null ? _a : `section-${sectionIndex}`;
38
- };
39
- function buildSectionListData({
40
- sections,
41
- renderSectionHeader,
42
- renderSectionFooter,
43
- ItemSeparatorComponent,
44
- SectionSeparatorComponent,
45
- stickySectionHeadersEnabled,
46
- keyExtractor = defaultKeyExtractor
47
- }) {
48
- var _a, _b;
49
- const data = [];
50
- const sectionMeta = [];
51
- const stickyHeaderIndices = [];
52
- let absoluteItemIndex = 0;
53
- for (let sectionIndex = 0; sectionIndex < sections.length; sectionIndex++) {
54
- const section = sections[sectionIndex];
55
- const items = (_a = section.data) != null ? _a : [];
56
- const meta = { items: [] };
57
- const sectionKey = getSectionKey(section, sectionIndex);
58
- const hasHeader = typeof renderSectionHeader === "function";
59
- const hasFooter = typeof renderSectionFooter === "function";
60
- const hasItemSeparator = Boolean(ItemSeparatorComponent || section.ItemSeparatorComponent);
61
- const hasSectionSeparator = Boolean(SectionSeparatorComponent);
62
- if (hasHeader) {
63
- const headerIndex = data.length;
64
- data.push({
65
- key: `${sectionKey}:header`,
66
- kind: "header",
67
- section,
68
- sectionIndex
69
- });
70
- meta.header = headerIndex;
71
- if (stickySectionHeadersEnabled) {
72
- stickyHeaderIndices.push(headerIndex);
73
- }
74
- }
75
- for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
76
- const item = items[itemIndex];
77
- const itemKeyExtractor = (_b = section.keyExtractor) != null ? _b : keyExtractor;
78
- const itemKey = itemKeyExtractor(item, itemIndex);
79
- data.push({
80
- absoluteItemIndex: absoluteItemIndex++,
81
- item,
82
- itemIndex,
83
- key: `${sectionKey}:item:${itemKey}`,
84
- kind: "item",
85
- section,
86
- sectionIndex
87
- });
88
- meta.items.push(data.length - 1);
89
- if (hasItemSeparator && itemIndex < items.length - 1) {
90
- data.push({
91
- key: `${sectionKey}:separator:${itemIndex}`,
92
- kind: "item-separator",
93
- leadingItem: item,
94
- leadingItemIndex: itemIndex,
95
- section,
96
- sectionIndex,
97
- trailingItem: items[itemIndex + 1]
98
- });
99
- }
100
- }
101
- if (hasFooter) {
102
- data.push({
103
- key: `${sectionKey}:footer`,
104
- kind: "footer",
105
- section,
106
- sectionIndex
107
- });
108
- meta.footer = data.length - 1;
109
- }
110
- const isLastSection = sectionIndex === sections.length - 1;
111
- if (hasSectionSeparator && !isLastSection) {
112
- data.push({
113
- key: `${sectionKey}:section-separator`,
114
- kind: "section-separator",
115
- leadingSection: section,
116
- leadingSectionIndex: sectionIndex,
117
- trailingSection: sections[sectionIndex + 1]
118
- });
119
- }
120
- sectionMeta.push(meta);
121
- }
122
- return { data, sectionMeta, stickyHeaderIndices };
123
- }
124
-
125
- // src/section-list/SectionList.tsx
126
- var defaultSeparators = {
127
- highlight: () => {
128
- },
129
- unhighlight: () => {
130
- },
131
- updateProps: () => {
132
- }
133
- };
134
- function resolveSeparatorComponent(component, props) {
135
- if (!component) return null;
136
- if (React__namespace.isValidElement(component)) {
137
- return component;
138
- }
139
- const Component = component;
140
- return /* @__PURE__ */ React__namespace.createElement(Component, { ...props });
141
- }
142
- var SectionList = list.typedMemo(
143
- list.typedForwardRef(function SectionListInner(props, ref) {
144
- const {
145
- sections,
146
- renderItem: renderItemProp,
147
- renderSectionHeader,
148
- renderSectionFooter,
149
- ItemSeparatorComponent,
150
- SectionSeparatorComponent,
151
- stickySectionHeadersEnabled = reactNative.Platform.OS === "ios",
152
- keyExtractor,
153
- extraData,
154
- onViewableItemsChanged,
155
- horizontal,
156
- ...restProps
157
- } = props;
158
- const legendListRef = React__namespace.useRef(null);
159
- const flattened = React__namespace.useMemo(
160
- () => buildSectionListData({
161
- ItemSeparatorComponent,
162
- keyExtractor,
163
- renderSectionFooter,
164
- renderSectionHeader,
165
- SectionSeparatorComponent,
166
- sections,
167
- stickySectionHeadersEnabled: !horizontal && stickySectionHeadersEnabled
168
- }),
169
- [
170
- sections,
171
- extraData,
172
- renderSectionHeader,
173
- renderSectionFooter,
174
- ItemSeparatorComponent,
175
- SectionSeparatorComponent,
176
- stickySectionHeadersEnabled,
177
- keyExtractor,
178
- horizontal
179
- ]
180
- );
181
- const { data, sectionMeta, stickyHeaderIndices } = flattened;
182
- const handleViewableItemsChanged = React__namespace.useMemo(() => {
183
- if (!onViewableItemsChanged) return void 0;
184
- return ({
185
- viewableItems,
186
- changed
187
- }) => {
188
- const mapToken = (token) => {
189
- if (token.item.kind !== "item") return null;
190
- return {
191
- index: token.item.itemIndex,
192
- isViewable: token.isViewable,
193
- item: token.item.item,
194
- key: token.key,
195
- section: token.item.section
196
- };
197
- };
198
- const mappedViewable = viewableItems.map(mapToken).filter(Boolean);
199
- const mappedChanged = changed.map(mapToken).filter(Boolean);
200
- onViewableItemsChanged({ changed: mappedChanged, viewableItems: mappedViewable });
201
- };
202
- }, [onViewableItemsChanged]);
203
- const renderItem = React__namespace.useCallback(
204
- ({ item }) => {
205
- var _a, _b;
206
- switch (item.kind) {
207
- case "header":
208
- return renderSectionHeader ? renderSectionHeader({ section: item.section }) : null;
209
- case "footer":
210
- return renderSectionFooter ? renderSectionFooter({ section: item.section }) : null;
211
- case "item": {
212
- const render = (_a = item.section.renderItem) != null ? _a : renderItemProp;
213
- if (!render) return null;
214
- return render({
215
- index: item.itemIndex,
216
- item: item.item,
217
- section: item.section,
218
- separators: defaultSeparators
219
- });
220
- }
221
- case "item-separator": {
222
- const SeparatorComponent = (_b = item.section.ItemSeparatorComponent) != null ? _b : ItemSeparatorComponent;
223
- return resolveSeparatorComponent(SeparatorComponent, {
224
- leadingItem: item.leadingItem,
225
- leadingSection: item.section,
226
- section: item.section,
227
- trailingItem: item.trailingItem,
228
- trailingSection: item.section
229
- });
230
- }
231
- case "section-separator":
232
- return resolveSeparatorComponent(SectionSeparatorComponent, {
233
- leadingItem: void 0,
234
- leadingSection: item.leadingSection,
235
- section: item.leadingSection,
236
- trailingItem: void 0,
237
- trailingSection: item.trailingSection
238
- });
239
- default:
240
- return null;
241
- }
242
- },
243
- [
244
- ItemSeparatorComponent,
245
- SectionSeparatorComponent,
246
- renderItemProp,
247
- renderSectionFooter,
248
- renderSectionHeader
249
- ]
250
- );
251
- const scrollToLocation = React__namespace.useCallback(
252
- ({ sectionIndex, itemIndex, viewOffset, viewPosition, animated }) => {
253
- var _a, _b, _c;
254
- const meta = sectionMeta[sectionIndex];
255
- if (!meta) return;
256
- const target = itemIndex === -1 ? (_b = (_a = meta.header) != null ? _a : meta.items[0]) != null ? _b : meta.footer : meta.items[itemIndex];
257
- if (target === void 0) return;
258
- (_c = legendListRef.current) == null ? void 0 : _c.scrollToIndex({
259
- animated,
260
- index: target,
261
- viewOffset,
262
- viewPosition
263
- });
264
- },
265
- [sectionMeta]
266
- );
267
- React__namespace.useImperativeHandle(
268
- ref,
269
- () => ({
270
- ...legendListRef.current,
271
- scrollToLocation
272
- }),
273
- [scrollToLocation]
274
- );
275
- return /* @__PURE__ */ React__namespace.createElement(
276
- list.LegendList,
277
- {
278
- ...restProps,
279
- columnWrapperStyle: void 0,
280
- data,
281
- getItemType: (item) => item.kind,
282
- keyExtractor: (item) => item.key,
283
- numColumns: 1,
284
- onViewableItemsChanged: handleViewableItemsChanged,
285
- ref: legendListRef,
286
- renderItem,
287
- stickyHeaderIndices: !horizontal ? stickyHeaderIndices : void 0
288
- }
289
- );
290
- })
291
- );
292
-
293
- exports.SectionList = SectionList;