@legendapp/list 2.0.0-next.1 → 2.0.0-next.2
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.
- package/.claude/settings.local.json +8 -0
- package/.cursor/rules/changelog.mdc +60 -0
- package/.github/FUNDING.yml +15 -0
- package/.gitignore +5 -0
- package/.prettierrc.json +5 -0
- package/.vscode/settings.json +14 -0
- package/CLAUDE.md +126 -0
- package/biome.json +46 -0
- package/bun.lock +1289 -0
- package/bunfig.toml +2 -0
- package/dist/CHANGELOG.md +119 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +139 -0
- package/{animated.d.mts → dist/animated.d.mts} +1 -1
- package/{animated.d.ts → dist/animated.d.ts} +1 -1
- package/{index.d.mts → dist/index.d.mts} +16 -10
- package/{index.d.ts → dist/index.d.ts} +16 -10
- package/{index.js → dist/index.js} +52 -32
- package/{index.mjs → dist/index.mjs} +52 -32
- package/{keyboard-controller.d.mts → dist/keyboard-controller.d.mts} +4 -4
- package/{keyboard-controller.d.ts → dist/keyboard-controller.d.ts} +4 -4
- package/dist/package.json +35 -0
- package/example/README.md +40 -0
- package/example/api/data/genres.json +23 -0
- package/example/api/data/playlist/10402-10749.json +1 -0
- package/example/api/data/playlist/10402-10770.json +1 -0
- package/example/api/data/playlist/10402-37.json +1 -0
- package/example/api/data/playlist/10749-10752.json +1 -0
- package/example/api/data/playlist/10749-10770.json +1 -0
- package/example/api/data/playlist/10749-37.json +1 -0
- package/example/api/data/playlist/10749-878.json +1 -0
- package/example/api/data/playlist/10751-10402.json +1 -0
- package/example/api/data/playlist/10751-10752.json +1 -0
- package/example/api/data/playlist/10751-37.json +1 -0
- package/example/api/data/playlist/10751-53.json +1 -0
- package/example/api/data/playlist/10751-878.json +1 -0
- package/example/api/data/playlist/10751-9648.json +1 -0
- package/example/api/data/playlist/10752-37.json +1 -0
- package/example/api/data/playlist/12-10402.json +1 -0
- package/example/api/data/playlist/12-10749.json +1 -0
- package/example/api/data/playlist/12-18.json +1 -0
- package/example/api/data/playlist/12-27.json +1 -0
- package/example/api/data/playlist/12-35.json +1 -0
- package/example/api/data/playlist/14-36.json +1 -0
- package/example/api/data/playlist/14-878.json +1 -0
- package/example/api/data/playlist/16-10751.json +1 -0
- package/example/api/data/playlist/16-10770.json +1 -0
- package/example/api/data/playlist/16-35.json +1 -0
- package/example/api/data/playlist/16-36.json +1 -0
- package/example/api/data/playlist/16-53.json +1 -0
- package/example/api/data/playlist/18-10751.json +1 -0
- package/example/api/data/playlist/18-10752.json +1 -0
- package/example/api/data/playlist/18-37.json +1 -0
- package/example/api/data/playlist/18-53.json +1 -0
- package/example/api/data/playlist/18-878.json +1 -0
- package/example/api/data/playlist/27-10749.json +1 -0
- package/example/api/data/playlist/27-10770.json +1 -0
- package/example/api/data/playlist/28-10749.json +1 -0
- package/example/api/data/playlist/28-10751.json +1 -0
- package/example/api/data/playlist/28-10770.json +1 -0
- package/example/api/data/playlist/28-16.json +1 -0
- package/example/api/data/playlist/28-18.json +1 -0
- package/example/api/data/playlist/28-36.json +1 -0
- package/example/api/data/playlist/28-37.json +1 -0
- package/example/api/data/playlist/28-53.json +1 -0
- package/example/api/data/playlist/28-80.json +1 -0
- package/example/api/data/playlist/28-99.json +1 -0
- package/example/api/data/playlist/35-10749.json +1 -0
- package/example/api/data/playlist/35-10751.json +1 -0
- package/example/api/data/playlist/35-10752.json +1 -0
- package/example/api/data/playlist/35-27.json +1 -0
- package/example/api/data/playlist/35-36.json +1 -0
- package/example/api/data/playlist/35-53.json +1 -0
- package/example/api/data/playlist/35-80.json +1 -0
- package/example/api/data/playlist/36-37.json +1 -0
- package/example/api/data/playlist/36-878.json +1 -0
- package/example/api/data/playlist/36-9648.json +1 -0
- package/example/api/data/playlist/53-10752.json +1 -0
- package/example/api/data/playlist/80-10770.json +1 -0
- package/example/api/data/playlist/80-14.json +1 -0
- package/example/api/data/playlist/80-18.json +1 -0
- package/example/api/data/playlist/80-37.json +1 -0
- package/example/api/data/playlist/878-37.json +1 -0
- package/example/api/data/playlist/9648-10770.json +1 -0
- package/example/api/data/playlist/9648-37.json +1 -0
- package/example/api/data/playlist/9648-53.json +1 -0
- package/example/api/data/playlist/9648-878.json +1 -0
- package/example/api/data/playlist/99-10749.json +1 -0
- package/example/api/data/playlist/99-14.json +1 -0
- package/example/api/data/playlist/99-18.json +1 -0
- package/example/api/data/playlist/99-27.json +1 -0
- package/example/api/data/playlist/99-53.json +1 -0
- package/example/api/data/playlist/99-9648.json +1 -0
- package/example/api/data/playlist/index.ts +73 -0
- package/example/api/data/rows.json +1 -0
- package/example/api/index.ts +36 -0
- package/example/app/(tabs)/_layout.tsx +60 -0
- package/example/app/(tabs)/cards.tsx +81 -0
- package/example/app/(tabs)/index.tsx +205 -0
- package/example/app/(tabs)/moviesL.tsx +7 -0
- package/example/app/(tabs)/moviesLR.tsx +7 -0
- package/example/app/+not-found.tsx +32 -0
- package/example/app/_layout.tsx +34 -0
- package/example/app/accurate-scrollto/index.tsx +125 -0
- package/example/app/accurate-scrollto-2/index.tsx +52 -0
- package/example/app/accurate-scrollto-huge/index.tsx +128 -0
- package/example/app/add-to-end/index.tsx +82 -0
- package/example/app/ai-chat/index.tsx +236 -0
- package/example/app/bidirectional-infinite-list/index.tsx +133 -0
- package/example/app/cards-columns/index.tsx +37 -0
- package/example/app/cards-flashlist/index.tsx +122 -0
- package/example/app/cards-flatlist/index.tsx +94 -0
- package/example/app/cards-no-recycle/index.tsx +110 -0
- package/example/app/cards-renderItem.tsx +354 -0
- package/example/app/chat-example/index.tsx +167 -0
- package/example/app/chat-infinite/index.tsx +239 -0
- package/example/app/chat-keyboard/index.tsx +248 -0
- package/example/app/chat-resize-outer/index.tsx +247 -0
- package/example/app/columns/index.tsx +78 -0
- package/example/app/countries/index.tsx +182 -0
- package/example/app/countries-flashlist/index.tsx +163 -0
- package/example/app/countries-reorder/index.tsx +187 -0
- package/example/app/extra-data/index.tsx +86 -0
- package/example/app/filter-elements/filter-data-provider.tsx +55 -0
- package/example/app/filter-elements/index.tsx +118 -0
- package/example/app/initial-scroll-index/index.tsx +106 -0
- package/example/app/initial-scroll-index/renderFixedItem.tsx +215 -0
- package/example/app/initial-scroll-index-free-height/index.tsx +70 -0
- package/example/app/initial-scroll-index-keyed/index.tsx +62 -0
- package/example/app/lazy-list/index.tsx +123 -0
- package/example/app/movies-flashlist/index.tsx +7 -0
- package/example/app/mutable-cells/index.tsx +104 -0
- package/example/app/video-feed/index.tsx +119 -0
- package/example/app.config.js +22 -0
- package/example/app.json +45 -0
- package/example/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/example/assets/images/adaptive-icon.png +0 -0
- package/example/assets/images/favicon.png +0 -0
- package/example/assets/images/icon.png +0 -0
- package/example/assets/images/partial-react-logo.png +0 -0
- package/example/assets/images/react-logo.png +0 -0
- package/example/assets/images/react-logo@2x.png +0 -0
- package/example/assets/images/react-logo@3x.png +0 -0
- package/example/assets/images/splash-icon.png +0 -0
- package/example/autoscroll.sh +101 -0
- package/example/bun.lock +2266 -0
- package/example/bunfig.toml +2 -0
- package/example/components/Breathe.tsx +54 -0
- package/example/components/Circle.tsx +69 -0
- package/example/components/Collapsible.tsx +44 -0
- package/example/components/ExternalLink.tsx +24 -0
- package/example/components/HapticTab.tsx +18 -0
- package/example/components/HelloWave.tsx +37 -0
- package/example/components/Movies.tsx +179 -0
- package/example/components/ParallaxScrollView.tsx +81 -0
- package/example/components/ThemedText.tsx +60 -0
- package/example/components/ThemedView.tsx +14 -0
- package/example/components/__tests__/ThemedText-test.tsx +10 -0
- package/example/components/__tests__/__snapshots__/ThemedText-test.tsx.snap +24 -0
- package/example/components/ui/IconSymbol.ios.tsx +32 -0
- package/example/components/ui/IconSymbol.tsx +43 -0
- package/example/components/ui/TabBarBackground.ios.tsx +22 -0
- package/example/components/ui/TabBarBackground.tsx +6 -0
- package/example/constants/Colors.ts +26 -0
- package/example/constants/constants.ts +5 -0
- package/example/constants/useScrollTest.ts +19 -0
- package/example/hooks/useColorScheme.ts +1 -0
- package/example/hooks/useColorScheme.web.ts +8 -0
- package/example/hooks/useThemeColor.ts +22 -0
- package/example/ios/.xcode.env +11 -0
- package/example/ios/Podfile +64 -0
- package/example/ios/Podfile.lock +2767 -0
- package/example/ios/Podfile.properties.json +5 -0
- package/example/ios/listtest/AppDelegate.swift +70 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/App-Icon-1024x1024@1x.png +0 -0
- package/example/ios/listtest/Images.xcassets/AppIcon.appiconset/Contents.json +14 -0
- package/example/ios/listtest/Images.xcassets/Contents.json +6 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenBackground.colorset/Contents.json +20 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/Contents.json +23 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@2x.png +0 -0
- package/example/ios/listtest/Images.xcassets/SplashScreenLogo.imageset/image@3x.png +0 -0
- package/example/ios/listtest/Info.plist +85 -0
- package/example/ios/listtest/PrivacyInfo.xcprivacy +48 -0
- package/example/ios/listtest/SplashScreen.storyboard +42 -0
- package/example/ios/listtest/Supporting/Expo.plist +12 -0
- package/example/ios/listtest/listtest-Bridging-Header.h +3 -0
- package/example/ios/listtest/listtest.entitlements +5 -0
- package/example/ios/listtest.xcodeproj/project.pbxproj +547 -0
- package/example/ios/listtest.xcodeproj/xcshareddata/xcschemes/listtest.xcscheme +88 -0
- package/example/ios/listtest.xcworkspace/contents.xcworkspacedata +10 -0
- package/example/metro.config.js +16 -0
- package/example/package.json +73 -0
- package/example/scripts/reset-project.js +84 -0
- package/example/tsconfig.json +26 -0
- package/package.json +88 -34
- package/posttsup.ts +24 -0
- package/src/Container.tsx +176 -0
- package/src/Containers.tsx +85 -0
- package/src/ContextContainer.ts +145 -0
- package/src/DebugView.tsx +83 -0
- package/src/LazyLegendList.tsx +41 -0
- package/src/LeanView.tsx +18 -0
- package/src/LegendList.tsx +558 -0
- package/src/ListComponent.tsx +191 -0
- package/src/ScrollAdjust.tsx +24 -0
- package/src/ScrollAdjustHandler.ts +26 -0
- package/src/Separator.tsx +14 -0
- package/src/animated.tsx +6 -0
- package/src/calculateItemsInView.ts +363 -0
- package/src/calculateOffsetForIndex.ts +23 -0
- package/src/calculateOffsetWithOffsetPosition.ts +26 -0
- package/src/checkAllSizesKnown.ts +17 -0
- package/src/checkAtBottom.ts +36 -0
- package/src/checkAtTop.ts +27 -0
- package/src/checkThreshold.ts +30 -0
- package/src/constants.ts +11 -0
- package/src/createColumnWrapperStyle.ts +16 -0
- package/src/doInitialAllocateContainers.ts +40 -0
- package/src/doMaintainScrollAtEnd.ts +34 -0
- package/src/findAvailableContainers.ts +98 -0
- package/src/finishScrollTo.ts +8 -0
- package/src/getId.ts +21 -0
- package/src/getItemSize.ts +52 -0
- package/src/getRenderedItem.ts +34 -0
- package/src/getScrollVelocity.ts +47 -0
- package/src/handleLayout.ts +70 -0
- package/src/helpers.ts +39 -0
- package/src/index.ts +11 -0
- package/src/keyboard-controller.tsx +63 -0
- package/src/onScroll.ts +66 -0
- package/src/prepareMVCP.ts +50 -0
- package/src/reanimated.tsx +63 -0
- package/src/requestAdjust.ts +41 -0
- package/src/scrollTo.ts +40 -0
- package/src/scrollToIndex.ts +34 -0
- package/src/setDidLayout.ts +25 -0
- package/src/setPaddingTop.ts +28 -0
- package/src/state.tsx +304 -0
- package/src/types.ts +610 -0
- package/src/updateAlignItemsPaddingTop.ts +18 -0
- package/src/updateAllPositions.ts +130 -0
- package/src/updateItemSize.ts +203 -0
- package/src/updateTotalSize.ts +44 -0
- package/src/useAnimatedValue.ts +6 -0
- package/src/useCombinedRef.ts +22 -0
- package/src/useInit.ts +17 -0
- package/src/useSyncLayout.tsx +68 -0
- package/src/useValue$.ts +53 -0
- package/src/viewability.ts +279 -0
- package/tsconfig.json +59 -0
- package/tsup.config.ts +21 -0
- /package/{animated.js → dist/animated.js} +0 -0
- /package/{animated.mjs → dist/animated.mjs} +0 -0
- /package/{keyboard-controller.js → dist/keyboard-controller.js} +0 -0
- /package/{keyboard-controller.mjs → dist/keyboard-controller.mjs} +0 -0
- /package/{reanimated.d.mts → dist/reanimated.d.mts} +0 -0
- /package/{reanimated.d.ts → dist/reanimated.d.ts} +0 -0
- /package/{reanimated.js → dist/reanimated.js} +0 -0
- /package/{reanimated.mjs → dist/reanimated.mjs} +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { getId } from "./getId";
|
|
2
|
+
import { type StateContext, peek$ } from "./state";
|
|
3
|
+
import type {
|
|
4
|
+
InternalState,
|
|
5
|
+
LegendListProps,
|
|
6
|
+
ViewAmountToken,
|
|
7
|
+
ViewToken,
|
|
8
|
+
ViewabilityConfig,
|
|
9
|
+
ViewabilityConfigCallbackPair,
|
|
10
|
+
ViewabilityConfigCallbackPairs,
|
|
11
|
+
} from "./types";
|
|
12
|
+
|
|
13
|
+
const mapViewabilityConfigCallbackPairs = new Map<
|
|
14
|
+
string,
|
|
15
|
+
{
|
|
16
|
+
viewableItems: ViewToken[];
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
previousStart: number;
|
|
20
|
+
previousEnd: number;
|
|
21
|
+
}
|
|
22
|
+
>();
|
|
23
|
+
|
|
24
|
+
export function setupViewability(
|
|
25
|
+
props: Pick<
|
|
26
|
+
LegendListProps<any>,
|
|
27
|
+
"viewabilityConfig" | "viewabilityConfigCallbackPairs" | "onViewableItemsChanged"
|
|
28
|
+
>,
|
|
29
|
+
): ViewabilityConfigCallbackPairs | undefined {
|
|
30
|
+
let { viewabilityConfig, viewabilityConfigCallbackPairs, onViewableItemsChanged } = props;
|
|
31
|
+
|
|
32
|
+
if (viewabilityConfig || onViewableItemsChanged) {
|
|
33
|
+
viewabilityConfigCallbackPairs = [
|
|
34
|
+
...(viewabilityConfigCallbackPairs! || []),
|
|
35
|
+
{
|
|
36
|
+
viewabilityConfig:
|
|
37
|
+
viewabilityConfig ||
|
|
38
|
+
({
|
|
39
|
+
viewAreaCoveragePercentThreshold: 0,
|
|
40
|
+
} as any),
|
|
41
|
+
onViewableItemsChanged,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (viewabilityConfigCallbackPairs) {
|
|
47
|
+
for (const pair of viewabilityConfigCallbackPairs) {
|
|
48
|
+
mapViewabilityConfigCallbackPairs.set(pair.viewabilityConfig.id!, {
|
|
49
|
+
viewableItems: [],
|
|
50
|
+
start: -1,
|
|
51
|
+
end: -1,
|
|
52
|
+
previousStart: -1,
|
|
53
|
+
previousEnd: -1,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return viewabilityConfigCallbackPairs;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function updateViewableItems(
|
|
62
|
+
state: InternalState,
|
|
63
|
+
ctx: StateContext,
|
|
64
|
+
viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPair[],
|
|
65
|
+
scrollSize: number,
|
|
66
|
+
start: number,
|
|
67
|
+
end: number,
|
|
68
|
+
) {
|
|
69
|
+
for (const viewabilityConfigCallbackPair of viewabilityConfigCallbackPairs) {
|
|
70
|
+
const viewabilityState = mapViewabilityConfigCallbackPairs.get(
|
|
71
|
+
viewabilityConfigCallbackPair.viewabilityConfig.id!,
|
|
72
|
+
)!;
|
|
73
|
+
viewabilityState.start = start;
|
|
74
|
+
viewabilityState.end = end;
|
|
75
|
+
if (viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime) {
|
|
76
|
+
const timer: any = setTimeout(() => {
|
|
77
|
+
state.timeouts.delete(timer);
|
|
78
|
+
updateViewableItemsWithConfig(state.data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
|
|
79
|
+
}, viewabilityConfigCallbackPair.viewabilityConfig.minimumViewTime);
|
|
80
|
+
state.timeouts.add(timer);
|
|
81
|
+
} else {
|
|
82
|
+
updateViewableItemsWithConfig(state.data, viewabilityConfigCallbackPair, state, ctx, scrollSize);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function updateViewableItemsWithConfig(
|
|
88
|
+
data: readonly any[],
|
|
89
|
+
viewabilityConfigCallbackPair: ViewabilityConfigCallbackPair,
|
|
90
|
+
state: InternalState,
|
|
91
|
+
ctx: StateContext,
|
|
92
|
+
scrollSize: number,
|
|
93
|
+
) {
|
|
94
|
+
const { viewabilityConfig, onViewableItemsChanged } = viewabilityConfigCallbackPair;
|
|
95
|
+
const configId = viewabilityConfig.id!;
|
|
96
|
+
const viewabilityState = mapViewabilityConfigCallbackPairs.get(configId)!;
|
|
97
|
+
const { viewableItems: previousViewableItems, start, end } = viewabilityState;
|
|
98
|
+
|
|
99
|
+
const viewabilityTokens = new Map<number, ViewAmountToken>();
|
|
100
|
+
for (const [containerId, value] of ctx.mapViewabilityAmountValues) {
|
|
101
|
+
viewabilityTokens.set(
|
|
102
|
+
containerId,
|
|
103
|
+
computeViewability(
|
|
104
|
+
state,
|
|
105
|
+
ctx,
|
|
106
|
+
viewabilityConfig,
|
|
107
|
+
containerId,
|
|
108
|
+
value.key,
|
|
109
|
+
scrollSize,
|
|
110
|
+
value.item,
|
|
111
|
+
value.index,
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const changed: ViewToken[] = [];
|
|
116
|
+
if (previousViewableItems) {
|
|
117
|
+
for (const viewToken of previousViewableItems) {
|
|
118
|
+
const containerId = findContainerId(ctx, viewToken.key);
|
|
119
|
+
if (
|
|
120
|
+
!isViewable(
|
|
121
|
+
state,
|
|
122
|
+
ctx,
|
|
123
|
+
viewabilityConfig,
|
|
124
|
+
containerId,
|
|
125
|
+
viewToken.key,
|
|
126
|
+
scrollSize,
|
|
127
|
+
viewToken.item,
|
|
128
|
+
viewToken.index,
|
|
129
|
+
)
|
|
130
|
+
) {
|
|
131
|
+
viewToken.isViewable = false;
|
|
132
|
+
changed.push(viewToken);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const viewableItems: ViewToken[] = [];
|
|
138
|
+
|
|
139
|
+
for (let i = start; i <= end; i++) {
|
|
140
|
+
const item = data[i];
|
|
141
|
+
if (item) {
|
|
142
|
+
const key = getId(state, i);
|
|
143
|
+
const containerId = findContainerId(ctx, key);
|
|
144
|
+
if (isViewable(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, i)) {
|
|
145
|
+
const viewToken: ViewToken = {
|
|
146
|
+
item,
|
|
147
|
+
key,
|
|
148
|
+
index: i,
|
|
149
|
+
isViewable: true,
|
|
150
|
+
containerId,
|
|
151
|
+
};
|
|
152
|
+
viewableItems.push(viewToken);
|
|
153
|
+
if (!previousViewableItems?.find((v) => v.key === viewToken.key)) {
|
|
154
|
+
changed.push(viewToken);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
Object.assign(viewabilityState, {
|
|
161
|
+
viewableItems,
|
|
162
|
+
previousStart: start,
|
|
163
|
+
previousEnd: end,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
if (changed.length > 0) {
|
|
167
|
+
viewabilityState.viewableItems = viewableItems;
|
|
168
|
+
|
|
169
|
+
for (let i = 0; i < changed.length; i++) {
|
|
170
|
+
const change = changed[i];
|
|
171
|
+
maybeUpdateViewabilityCallback(ctx, configId, change.containerId, change);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (onViewableItemsChanged) {
|
|
175
|
+
onViewableItemsChanged({ viewableItems, changed });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
for (const [containerId, value] of ctx.mapViewabilityAmountValues) {
|
|
180
|
+
if (value.sizeVisible < 0) {
|
|
181
|
+
ctx.mapViewabilityAmountValues.delete(containerId);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function computeViewability(
|
|
187
|
+
state: InternalState,
|
|
188
|
+
ctx: StateContext,
|
|
189
|
+
viewabilityConfig: ViewabilityConfig,
|
|
190
|
+
containerId: number,
|
|
191
|
+
key: string,
|
|
192
|
+
scrollSize: number,
|
|
193
|
+
item: any,
|
|
194
|
+
index: number,
|
|
195
|
+
): ViewAmountToken {
|
|
196
|
+
const { sizes, positions, scroll: scrollState } = state;
|
|
197
|
+
const topPad = (peek$(ctx, "stylePaddingTop") || 0) + (peek$(ctx, "headerSize") || 0);
|
|
198
|
+
const { itemVisiblePercentThreshold, viewAreaCoveragePercentThreshold } = viewabilityConfig;
|
|
199
|
+
const viewAreaMode = viewAreaCoveragePercentThreshold != null;
|
|
200
|
+
const viewablePercentThreshold = viewAreaMode ? viewAreaCoveragePercentThreshold : itemVisiblePercentThreshold;
|
|
201
|
+
const scroll = scrollState - topPad;
|
|
202
|
+
|
|
203
|
+
const top = positions.get(key)! - scroll;
|
|
204
|
+
const size = sizes.get(key)! || 0;
|
|
205
|
+
const bottom = top + size;
|
|
206
|
+
const isEntirelyVisible = top >= 0 && bottom <= scrollSize && bottom > top;
|
|
207
|
+
|
|
208
|
+
const sizeVisible = isEntirelyVisible ? size : Math.min(bottom, scrollSize) - Math.max(top, 0);
|
|
209
|
+
const percentVisible = size ? (isEntirelyVisible ? 100 : 100 * (sizeVisible / size)) : 0;
|
|
210
|
+
const percentOfScroller = size ? 100 * (sizeVisible / scrollSize) : 0;
|
|
211
|
+
const percent = isEntirelyVisible ? 100 : viewAreaMode ? percentOfScroller : percentVisible;
|
|
212
|
+
|
|
213
|
+
const isViewable = percent >= viewablePercentThreshold!;
|
|
214
|
+
|
|
215
|
+
const value: ViewAmountToken = {
|
|
216
|
+
index,
|
|
217
|
+
isViewable,
|
|
218
|
+
item,
|
|
219
|
+
key,
|
|
220
|
+
percentVisible,
|
|
221
|
+
percentOfScroller,
|
|
222
|
+
sizeVisible,
|
|
223
|
+
size,
|
|
224
|
+
scrollSize,
|
|
225
|
+
containerId,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
if (JSON.stringify(value) !== JSON.stringify(ctx.mapViewabilityAmountValues.get(containerId))) {
|
|
229
|
+
ctx.mapViewabilityAmountValues.set(containerId, value);
|
|
230
|
+
const cb = ctx.mapViewabilityAmountCallbacks.get(containerId);
|
|
231
|
+
if (cb) {
|
|
232
|
+
cb(value);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return value;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function isViewable(
|
|
240
|
+
state: InternalState,
|
|
241
|
+
ctx: StateContext,
|
|
242
|
+
viewabilityConfig: ViewabilityConfig,
|
|
243
|
+
containerId: number,
|
|
244
|
+
key: string,
|
|
245
|
+
scrollSize: number,
|
|
246
|
+
item: any,
|
|
247
|
+
index: number,
|
|
248
|
+
) {
|
|
249
|
+
const value =
|
|
250
|
+
ctx.mapViewabilityAmountValues.get(containerId) ||
|
|
251
|
+
computeViewability(state, ctx, viewabilityConfig, containerId, key, scrollSize, item, index);
|
|
252
|
+
|
|
253
|
+
return value.isViewable;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function findContainerId(ctx: StateContext, key: string) {
|
|
257
|
+
const numContainers = peek$(ctx, "numContainers");
|
|
258
|
+
for (let i = 0; i < numContainers; i++) {
|
|
259
|
+
const itemKey = peek$(ctx, `containerItemKey${i}`);
|
|
260
|
+
if (itemKey === key) {
|
|
261
|
+
return i;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return -1;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function maybeUpdateViewabilityCallback(
|
|
268
|
+
ctx: StateContext,
|
|
269
|
+
configId: string,
|
|
270
|
+
containerId: number,
|
|
271
|
+
viewToken: ViewToken,
|
|
272
|
+
) {
|
|
273
|
+
const key = containerId + configId;
|
|
274
|
+
|
|
275
|
+
ctx.mapViewabilityValues.set(key, viewToken);
|
|
276
|
+
|
|
277
|
+
const cb = ctx.mapViewabilityCallbacks.get(key);
|
|
278
|
+
cb?.(viewToken);
|
|
279
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"target": "es2018",
|
|
5
|
+
"module": "ES2015",
|
|
6
|
+
"lib": [
|
|
7
|
+
"dom",
|
|
8
|
+
"dom.iterable",
|
|
9
|
+
"esnext"
|
|
10
|
+
],
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"incremental": true,
|
|
16
|
+
"tsBuildInfoFile": "./tsconfig.tsbuildinfo", // Specify the build info file
|
|
17
|
+
"esModuleInterop": true,
|
|
18
|
+
"moduleResolution": "node",
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"jsx": "preserve",
|
|
21
|
+
"stripInternal": true,
|
|
22
|
+
"baseUrl": ".",
|
|
23
|
+
"rootDirs": [
|
|
24
|
+
"./src",
|
|
25
|
+
],
|
|
26
|
+
"declaration": true,
|
|
27
|
+
"declarationMap": false,
|
|
28
|
+
"sourceMap": true,
|
|
29
|
+
"paths": {
|
|
30
|
+
"react": [
|
|
31
|
+
"node_modules/react"
|
|
32
|
+
],
|
|
33
|
+
"react-native": [
|
|
34
|
+
"node_modules/react-native"
|
|
35
|
+
],
|
|
36
|
+
"@legendapp/list": [
|
|
37
|
+
"src/index"
|
|
38
|
+
],
|
|
39
|
+
"@legendapp/list/animated": [
|
|
40
|
+
"src/animated"
|
|
41
|
+
],
|
|
42
|
+
"@legendapp/list/reanimated": [
|
|
43
|
+
"src/reanimated"
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
"resolveJsonModule": true,
|
|
47
|
+
"noEmit": true
|
|
48
|
+
},
|
|
49
|
+
"include": [
|
|
50
|
+
"**/*.ts",
|
|
51
|
+
"**/*.tsx"
|
|
52
|
+
],
|
|
53
|
+
"exclude": [
|
|
54
|
+
"node_modules",
|
|
55
|
+
"dist",
|
|
56
|
+
"types.d.ts",
|
|
57
|
+
"src/types"
|
|
58
|
+
],
|
|
59
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
const external = [
|
|
4
|
+
"react",
|
|
5
|
+
"react-native",
|
|
6
|
+
"react-native-keyboard-controller",
|
|
7
|
+
"react-native-reanimated",
|
|
8
|
+
"@legendapp/list",
|
|
9
|
+
"@legendapp/list/animated",
|
|
10
|
+
"@legendapp/list/reanimated",
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
entry: ["src/index.ts", "src/animated.tsx", "src/reanimated.tsx", "src/keyboard-controller.tsx"],
|
|
15
|
+
format: ["cjs", "esm"],
|
|
16
|
+
external,
|
|
17
|
+
dts: true,
|
|
18
|
+
treeshake: true,
|
|
19
|
+
splitting: false,
|
|
20
|
+
clean: true,
|
|
21
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|