@legendapp/list 2.0.0-next.0 → 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} +63 -15
- package/{index.d.ts → dist/index.d.ts} +63 -15
- package/dist/index.js +2525 -0
- package/dist/index.mjs +2497 -0
- 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/index.js +0 -2348
- package/index.mjs +0 -2320
- /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,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Dispatch,
|
|
3
|
+
type SetStateAction,
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from "react";
|
|
11
|
+
import { isFunction } from "./helpers";
|
|
12
|
+
import { useArr$, useSelector$, useStateContext } from "./state";
|
|
13
|
+
import type { LegendListRecyclingState, ViewabilityAmountCallback, ViewabilityCallback } from "./types";
|
|
14
|
+
import { useInit } from "./useInit";
|
|
15
|
+
|
|
16
|
+
export interface ContextContainerType {
|
|
17
|
+
containerId: number;
|
|
18
|
+
itemKey: string;
|
|
19
|
+
index: number;
|
|
20
|
+
value: any;
|
|
21
|
+
triggerLayout: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const ContextContainer = createContext<ContextContainerType>(null as any);
|
|
25
|
+
|
|
26
|
+
export function useViewability(callback: ViewabilityCallback, configId?: string) {
|
|
27
|
+
const ctx = useStateContext();
|
|
28
|
+
const { containerId } = useContext(ContextContainer);
|
|
29
|
+
|
|
30
|
+
const key = containerId + (configId ?? "");
|
|
31
|
+
|
|
32
|
+
useInit(() => {
|
|
33
|
+
const value = ctx.mapViewabilityValues.get(key);
|
|
34
|
+
if (value) {
|
|
35
|
+
callback(value);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
ctx.mapViewabilityCallbacks.set(key, callback);
|
|
40
|
+
|
|
41
|
+
useEffect(
|
|
42
|
+
() => () => {
|
|
43
|
+
ctx.mapViewabilityCallbacks.delete(key);
|
|
44
|
+
},
|
|
45
|
+
[],
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useViewabilityAmount(callback: ViewabilityAmountCallback) {
|
|
50
|
+
const ctx = useStateContext();
|
|
51
|
+
const { containerId } = useContext(ContextContainer);
|
|
52
|
+
|
|
53
|
+
useInit(() => {
|
|
54
|
+
const value = ctx.mapViewabilityAmountValues.get(containerId);
|
|
55
|
+
if (value) {
|
|
56
|
+
callback(value);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
ctx.mapViewabilityAmountCallbacks.set(containerId, callback);
|
|
61
|
+
|
|
62
|
+
useEffect(
|
|
63
|
+
() => () => {
|
|
64
|
+
ctx.mapViewabilityAmountCallbacks.delete(containerId);
|
|
65
|
+
},
|
|
66
|
+
[],
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function useRecyclingEffect(effect: (info: LegendListRecyclingState<unknown>) => void | (() => void)) {
|
|
71
|
+
const { index, value } = useContext(ContextContainer);
|
|
72
|
+
const prevValues = useRef<{ prevIndex: number | undefined; prevItem: any }>({
|
|
73
|
+
prevIndex: undefined,
|
|
74
|
+
prevItem: undefined,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
let ret: void | (() => void) = undefined;
|
|
79
|
+
// Only run effect if there's a previous value
|
|
80
|
+
if (prevValues.current.prevIndex !== undefined && prevValues.current.prevItem !== undefined) {
|
|
81
|
+
ret = effect({
|
|
82
|
+
index,
|
|
83
|
+
item: value,
|
|
84
|
+
prevIndex: prevValues.current.prevIndex,
|
|
85
|
+
prevItem: prevValues.current.prevItem,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Update refs for next render
|
|
90
|
+
prevValues.current = {
|
|
91
|
+
prevIndex: index,
|
|
92
|
+
prevItem: value,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return ret;
|
|
96
|
+
}, [index, value]);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function useRecyclingState<ItemT>(valueOrFun: ((info: LegendListRecyclingState<ItemT>) => ItemT) | ItemT) {
|
|
100
|
+
const { index, value, itemKey, triggerLayout } = useContext(ContextContainer);
|
|
101
|
+
const refState = useRef<{ itemKey: string | null; value: ItemT | null }>({
|
|
102
|
+
itemKey: null,
|
|
103
|
+
value: null,
|
|
104
|
+
});
|
|
105
|
+
const [_, setRenderNum] = useState(0);
|
|
106
|
+
const state = refState.current;
|
|
107
|
+
|
|
108
|
+
if (state.itemKey !== itemKey) {
|
|
109
|
+
state.itemKey = itemKey;
|
|
110
|
+
// Reset local state in ref
|
|
111
|
+
state.value = isFunction(valueOrFun)
|
|
112
|
+
? valueOrFun({
|
|
113
|
+
index,
|
|
114
|
+
item: value,
|
|
115
|
+
prevIndex: undefined,
|
|
116
|
+
prevItem: undefined,
|
|
117
|
+
})
|
|
118
|
+
: valueOrFun;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const setState: Dispatch<SetStateAction<ItemT>> = useCallback(
|
|
122
|
+
(newState: SetStateAction<ItemT>) => {
|
|
123
|
+
// Update local state in ref
|
|
124
|
+
state.value = isFunction(newState) ? (newState as (prevState: ItemT) => ItemT)(state.value!) : newState;
|
|
125
|
+
// Trigger item to re-render
|
|
126
|
+
setRenderNum((v) => v + 1);
|
|
127
|
+
// Trigger container to re-render to update item size
|
|
128
|
+
triggerLayout();
|
|
129
|
+
},
|
|
130
|
+
[triggerLayout, state],
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return [state.value, setState] as const;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function useIsLastItem(): boolean {
|
|
137
|
+
const { itemKey } = useContext(ContextContainer);
|
|
138
|
+
const isLast = useSelector$("lastItemKeys", (lastItemKeys) => lastItemKeys?.includes(itemKey) || false);
|
|
139
|
+
return isLast;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function useListScrollSize(): { width: number; height: number } {
|
|
143
|
+
const [scrollSize] = useArr$(["scrollSize"]);
|
|
144
|
+
return scrollSize;
|
|
145
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useEffect, useReducer } from "react";
|
|
3
|
+
import { Text, View } from "react-native";
|
|
4
|
+
import { getContentSize, useArr$, useStateContext } from "./state";
|
|
5
|
+
import type { InternalState } from "./types";
|
|
6
|
+
|
|
7
|
+
const DebugRow = ({ children }: React.PropsWithChildren) => {
|
|
8
|
+
return (
|
|
9
|
+
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between" }}>{children}</View>
|
|
10
|
+
);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const DebugView = React.memo(function DebugView({ state }: { state: InternalState }) {
|
|
14
|
+
const ctx = useStateContext();
|
|
15
|
+
|
|
16
|
+
const [totalSize = 0, scrollAdjust = 0, rawScroll = 0, scroll = 0, numContainers = 0, numContainersPooled = 0] =
|
|
17
|
+
useArr$([
|
|
18
|
+
"totalSize",
|
|
19
|
+
"scrollAdjust",
|
|
20
|
+
"debugRawScroll",
|
|
21
|
+
"debugComputedScroll",
|
|
22
|
+
"numContainers",
|
|
23
|
+
"numContainersPooled",
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
const contentSize = getContentSize(ctx);
|
|
27
|
+
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
28
|
+
|
|
29
|
+
useInterval(() => {
|
|
30
|
+
forceUpdate();
|
|
31
|
+
}, 100);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<View
|
|
35
|
+
style={{
|
|
36
|
+
position: "absolute",
|
|
37
|
+
top: 0,
|
|
38
|
+
right: 0,
|
|
39
|
+
paddingLeft: 4,
|
|
40
|
+
paddingBottom: 4,
|
|
41
|
+
// height: 100,
|
|
42
|
+
backgroundColor: "#FFFFFFCC",
|
|
43
|
+
padding: 4,
|
|
44
|
+
borderRadius: 4,
|
|
45
|
+
}}
|
|
46
|
+
pointerEvents="none"
|
|
47
|
+
>
|
|
48
|
+
<DebugRow>
|
|
49
|
+
<Text>TotalSize:</Text>
|
|
50
|
+
<Text>{totalSize.toFixed(2)}</Text>
|
|
51
|
+
</DebugRow>
|
|
52
|
+
<DebugRow>
|
|
53
|
+
<Text>ContentSize:</Text>
|
|
54
|
+
<Text>{contentSize.toFixed(2)}</Text>
|
|
55
|
+
</DebugRow>
|
|
56
|
+
<DebugRow>
|
|
57
|
+
<Text>At end:</Text>
|
|
58
|
+
<Text>{String(state.isAtEnd)}</Text>
|
|
59
|
+
</DebugRow>
|
|
60
|
+
<Text />
|
|
61
|
+
<DebugRow>
|
|
62
|
+
<Text>ScrollAdjust:</Text>
|
|
63
|
+
<Text>{scrollAdjust.toFixed(2)}</Text>
|
|
64
|
+
</DebugRow>
|
|
65
|
+
<Text />
|
|
66
|
+
<DebugRow>
|
|
67
|
+
<Text>RawScroll: </Text>
|
|
68
|
+
<Text>{rawScroll.toFixed(2)}</Text>
|
|
69
|
+
</DebugRow>
|
|
70
|
+
<DebugRow>
|
|
71
|
+
<Text>ComputedScroll: </Text>
|
|
72
|
+
<Text>{scroll.toFixed(2)}</Text>
|
|
73
|
+
</DebugRow>
|
|
74
|
+
</View>
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
function useInterval(callback: () => void, delay: number) {
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
const interval = setInterval(callback, delay);
|
|
81
|
+
return () => clearInterval(interval);
|
|
82
|
+
}, [delay]);
|
|
83
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AnimatedLegendList } from "@legendapp/list/animated";
|
|
2
|
+
import type { AnimatedLegendList as ReanimatedLegendList } from "@legendapp/list/reanimated";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { type ForwardedRef, forwardRef } from "react";
|
|
5
|
+
import { LegendList as LegendListBase } from "./LegendList";
|
|
6
|
+
import { isArray } from "./helpers";
|
|
7
|
+
import type { LegendListProps, LegendListRef, LegendListRenderItemProps } from "./types";
|
|
8
|
+
|
|
9
|
+
// biome-ignore lint/complexity/noBannedTypes: This is a workaround for the fact that forwardRef is not typed
|
|
10
|
+
type TypedForwardRef = <T, P = {}>(
|
|
11
|
+
render: (props: P, ref: React.Ref<T>) => React.ReactNode,
|
|
12
|
+
) => (props: P & React.RefAttributes<T>) => React.ReactNode;
|
|
13
|
+
|
|
14
|
+
const typedForwardRef = forwardRef as TypedForwardRef;
|
|
15
|
+
|
|
16
|
+
export interface LazyLegendListProps<ItemT, ListT>
|
|
17
|
+
extends Omit<LegendListProps<ItemT>, "data" | "keyExtractor" | "renderItem"> {
|
|
18
|
+
children?: React.ReactNode | undefined;
|
|
19
|
+
LegendList?: ListT;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const renderItem = ({ item }: LegendListRenderItemProps<any>) => item;
|
|
23
|
+
|
|
24
|
+
export const LazyLegendList = typedForwardRef(function LazyLegendList<
|
|
25
|
+
ItemT,
|
|
26
|
+
ListT extends
|
|
27
|
+
| typeof LegendListBase
|
|
28
|
+
| typeof AnimatedLegendList
|
|
29
|
+
| typeof ReanimatedLegendList = typeof LegendListBase,
|
|
30
|
+
>(props: LazyLegendListProps<ItemT, ListT>, forwardedRef: ForwardedRef<LegendListRef>) {
|
|
31
|
+
const { LegendList: LegendListProp, children, ...rest } = props;
|
|
32
|
+
|
|
33
|
+
const LegendListComponent = LegendListProp ?? LegendListBase;
|
|
34
|
+
|
|
35
|
+
const data = (isArray(children) ? children : React.Children.toArray(children)).flat(1);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
// @ts-expect-error TODO: Fix this type
|
|
39
|
+
<LegendListComponent {...rest} data={data} renderItem={renderItem} ref={forwardedRef} />
|
|
40
|
+
);
|
|
41
|
+
});
|
package/src/LeanView.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Platform, View, type ViewProps } from "react-native";
|
|
3
|
+
|
|
4
|
+
// Thanks to @hirbod
|
|
5
|
+
// https://gist.github.com/hirbod/03d487f40b4c091d2c56ebfb17dba7ed
|
|
6
|
+
|
|
7
|
+
const LeanViewComponent = React.forwardRef<View, ViewProps>((props, ref) => {
|
|
8
|
+
return React.createElement("RCTView", { ...props, ref });
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
LeanViewComponent.displayName = "RCTView";
|
|
12
|
+
|
|
13
|
+
// LeanView doesn't work well on web, and not sure how it works on other platforms,
|
|
14
|
+
// so just use it on iOS and Android for now. Could expand this later if we know it's safe
|
|
15
|
+
// for specific other platforms.
|
|
16
|
+
const LeanView = Platform.OS === "android" || Platform.OS === "ios" ? LeanViewComponent : View;
|
|
17
|
+
|
|
18
|
+
export { LeanView };
|