Skip to content

Commit

Permalink
fix: revert the overrideItemLayout (#5558)
Browse files Browse the repository at this point in the history
* Revert "fix: the invisible cell of SectionList on native OK-31409 (#5546)"

This reverts commit f128852.

* fix: remove the duplicate keyExtractor of Currency #5546

* fix: remove the duplicate keyExtractor of Currency #5546
  • Loading branch information
hellohublot authored Aug 16, 2024
1 parent 5a6594d commit f2e143f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 70 deletions.
7 changes: 0 additions & 7 deletions packages/components/src/layouts/ListView/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ export type IListViewProps<T> = Omit<
See https://shopify.github.io/flash-list/docs/estimated-item-size/#how-to-calculate
*/
estimatedItemSize?: number | `$${keyof Tokens['size']}`;
overrideItemLayout?: (
layout: { span?: number; size?: number },
item: T,
index: number,
maxColumns: number,
extraData?: any,
) => void;
getItemType?: (item: T) => string | undefined;
onBlankArea?: (blankAreaEvent: {
offsetStart: number;
Expand Down
66 changes: 3 additions & 63 deletions packages/components/src/layouts/SectionList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useRef,
} from 'react';

import { getTokenValue, withStaticProperties } from 'tamagui';
import { withStaticProperties } from 'tamagui';

import platformEnv from '@onekeyhq/shared/src/platformEnv';

Expand All @@ -16,7 +16,6 @@ import { ListView } from '../ListView/list';

import type { ISizableTextProps, IStackProps } from '../../primitives';
import type { IListViewProps, IListViewRef } from '../ListView/list';
import type { Tokens } from '@tamagui/web/types/types';
import type { ListRenderItem } from 'react-native';

type ISectionRenderInfo = (info: {
Expand All @@ -26,7 +25,7 @@ type ISectionRenderInfo = (info: {

export type ISectionListProps<T> = Omit<
IListViewProps<T>,
'data' | 'renderItem' | 'overrideItemLayout'
'data' | 'renderItem'
> & {
sections: Array<{
data?: any[];
Expand All @@ -40,9 +39,6 @@ export type ISectionListProps<T> = Omit<
renderSectionFooter?: ISectionRenderInfo;
SectionSeparatorComponent?: ReactNode;
stickySectionHeadersEnabled?: boolean;
estimatedSectionHeaderSize?: number | `$${keyof Tokens['size']}`;
estimatedSectionFooterSize?: number | `$${keyof Tokens['size']}`;
estimatedSectionSeparatorSize?: number | `$${keyof Tokens['size']}`;
};

type IScrollToLocationParams = {
Expand Down Expand Up @@ -82,10 +78,7 @@ function BaseSectionList<T>(
SectionSeparatorComponent = <Stack h="$5" />,
stickySectionHeadersEnabled = false,
keyExtractor,
estimatedItemSize = 0,
estimatedSectionHeaderSize = '$9',
estimatedSectionFooterSize = 0,
estimatedSectionSeparatorSize = 20,
estimatedItemSize,
...restProps
}: ISectionListProps<T>,
parentRef: ForwardedRef<IListViewRef<T>>,
Expand Down Expand Up @@ -220,56 +213,6 @@ function BaseSectionList<T>(
},
[keyExtractor],
);
const getTokenSizeNumber = useCallback(
(token?: number | `$${keyof Tokens['size']}`) => {
if (typeof token === 'undefined') {
return undefined;
}
return typeof token === 'number'
? token
: (getTokenValue(token) as number);
},
[],
);
const tokenSizeNumberList = useMemo(
() => ({
[ESectionLayoutType.Header]: getTokenSizeNumber(
estimatedSectionHeaderSize,
),
[ESectionLayoutType.Item]: getTokenSizeNumber(estimatedItemSize),
[ESectionLayoutType.Footer]: getTokenSizeNumber(
estimatedSectionFooterSize,
),
[ESectionLayoutType.SectionSeparator]: getTokenSizeNumber(
estimatedSectionSeparatorSize,
),
}),
[
getTokenSizeNumber,
estimatedSectionHeaderSize,
estimatedItemSize,
estimatedSectionFooterSize,
estimatedSectionSeparatorSize,
],
);
const overrideItemLayout = useCallback(
(layout: { span?: number; size?: number }, item: T) => {
layout.size = tokenSizeNumberList[(item as ISectionLayoutItem).type] ?? 0;
},
[tokenSizeNumberList],
);
const layoutList = useMemo(() => {
let offset = 0;
return reloadSections.map((item, index) => {
const size = tokenSizeNumberList[item.type] ?? 0;
offset += size;
return { offset, length: size, index };
});
}, [reloadSections, tokenSizeNumberList]);
const getItemLayout = useCallback(
(_: ArrayLike<T> | null | undefined, index: number) => layoutList[index],
[layoutList],
);
return (
<ListView
ref={ref}
Expand All @@ -280,9 +223,6 @@ function BaseSectionList<T>(
getItemType={getItemType}
keyExtractor={platformEnv.isNative ? reloadKeyExtractor : undefined}
estimatedItemSize={platformEnv.isNative ? estimatedItemSize : undefined}
overrideItemLayout={platformEnv.isNative ? overrideItemLayout : undefined}
// will enable `getItemLayout` in next version
// getItemLayout={getItemLayout}
{...restProps}
/>
);
Expand Down

0 comments on commit f2e143f

Please sign in to comment.