Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: internal state types #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@expo/vector-icons": "^14.0.2",
"@legendapp/list": "^0.3.6",
"@legendapp/motion": "^2.4.0",
"@legendapp/state": "^3.0.0-beta.19",
"@react-navigation/bottom-tabs": "^7.0.0",
Expand Down Expand Up @@ -63,4 +64,4 @@
"typescript": "^5.3.3"
},
"private": true
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/LegendList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const LegendListInner: <T>(props: LegendListProps<T> & { ref?: ForwardedRef<Lege
isEndReached: false,
isAtBottom: false,
data: data,
idsInFirstRender: undefined as any,
idsInFirstRender: null,
hasScrolled: false,
scrollLength: Dimensions.get('window')[horizontal ? 'width' : 'height'],
startBuffered: 0,
Expand All @@ -133,7 +133,7 @@ const LegendListInner: <T>(props: LegendListProps<T> & { ref?: ForwardedRef<Lege
scroll: initialContentOffset || 0,
totalSize: 0,
timeouts: new Set(),
viewabilityConfigCallbackPairs: undefined as any,
viewabilityConfigCallbackPairs: null,
};
refState.current.idsInFirstRender = new Set(data.map((_: any, i: number) => getId(i)));
}
Expand Down Expand Up @@ -455,7 +455,7 @@ const LegendListInner: <T>(props: LegendListProps<T> & { ref?: ForwardedRef<Lege
}
const sizes = refState.current?.sizes!;
const id = getId(index);
const wasInFirstRender = refState.current?.idsInFirstRender.has(id);
const wasInFirstRender = refState.current?.idsInFirstRender?.has(id);

const prevSize = sizes.get(id) || (wasInFirstRender ? getItemSize(index, data[index]) : 0);
// let scrollNeedsAdjust = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface InternalState {
isEndReached: boolean;
isAtBottom: boolean;
data: any[];
idsInFirstRender: Set<string>;
idsInFirstRender: Set<string> | null;
hasScrolled: boolean;
scrollLength: number;
startBuffered: number;
Expand All @@ -55,7 +55,7 @@ export interface InternalState {
scroll: number;
totalSize: number;
timeouts: Set<number>;
viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPairs;
viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPairs | null;
}

export interface ViewableRange<T> {
Expand Down
3 changes: 2 additions & 1 deletion src/viewability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export function setupViewability(props: LegendListProps<any>) {
export function updateViewableItems(
state: InternalState,
ctx: StateContext,
viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPair[],
viewabilityConfigCallbackPairs: ViewabilityConfigCallbackPair[] | null,
getId: (index: number) => string,
scrollSize: number,
start: number,
end: number,
) {
if (!viewabilityConfigCallbackPairs) return;
for (const viewabilityConfigCallbackPair of viewabilityConfigCallbackPairs) {
const viewabilityState = mapViewabilityConfigCallbackPairs.get(viewabilityConfigCallbackPair)!;
viewabilityState.start = start;
Expand Down