Skip to content

fix: enhance type definitions #111

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

Merged
merged 2 commits into from
Aug 19, 2025
Merged
Changes from 1 commit
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
16 changes: 10 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { SectionListData } from "react-native";
import type { DefaultSectionT, SectionListData } from "react-native";

export type GetItemLayoutParams<T> = {
getItemHeight:
| number
| ((item: T, sectionIndex: number, itemIndex: number) => number);
getItemSeparatorHeight?:
| number
| ((sectionIndex: number, rowIndex: number) => number);
| ((sectionIndex: number, itemIndex: number) => number);
getListHeaderHeight?: number | (() => number);
getSectionHeaderHeight?: number | ((sectionIndex: number) => number);
getSectionFooterHeight?: number | ((sectionIndex: number) => number);
Expand All @@ -28,16 +28,19 @@ const resolveValue = <T, Args extends unknown[]>(
: value;

const getItemLayout =
<T>({
<ItemT, SectionT = DefaultSectionT>({
getItemHeight,
getItemSeparatorHeight = 0,
getSectionHeaderHeight = 0,
getSectionFooterHeight = 0,
getSectionSeparatorHeight = 0,
getListHeaderHeight = 0,
}: GetItemLayoutParams<T>) =>
(data: SectionListData<T>[] | null, index: number): GetItemLayoutShape => {
if (!data || !data.length) {
}: GetItemLayoutParams<ItemT>) =>
(
data: readonly SectionListData<ItemT, SectionT>[] | null,
index: number,
): GetItemLayoutShape => {
if (!data?.length || index < 0) {
return { length: 0, offset: 0, index };
}

Expand Down Expand Up @@ -119,3 +122,4 @@ const getItemLayout =
};

export default getItemLayout;
export type GetItemLayoutFunction = typeof getItemLayout;