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

Feat 29 #94

Merged
merged 3 commits into from
Dec 29, 2024
Merged
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
4 changes: 2 additions & 2 deletions core/dimensions-model/src/types/ListDimensionsModel.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IMasonryDimensions,
IMasonryDimensionsModel,
} from '@infinite-list/types';
import { RecyclerProps } from '@infinite-list/strategies';
import { IDefaultKeyExtra } from '@infinite-list/utils';

export type GetItemSeparatorLength<ItemT> = (
Expand Down Expand Up @@ -42,6 +43,7 @@ export type OnListDimensionsModelDataChanged<
export interface ListDimensionsModelProps<
ItemT extends GenericItemT = GenericItemT
> extends ListBaseDimensionsProps,
RecyclerProps,
BaseDimensionsProps {
/**
* @template ItemT the generic data item type
Expand Down Expand Up @@ -84,8 +86,6 @@ export interface ListDimensionsModelProps<
*/
manuallyApplyInitialData?: boolean;

recyclerTypes?: Array<string>;

onListDimensionsModelDataChanged?: OnListDimensionsModelDataChanged<ItemT>;
}

Expand Down
3 changes: 2 additions & 1 deletion core/strategies/src/RecycleStateImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class RecycleStateImpl<
.map((state) => {
if (!state) return null;
const copy = { ...state };
// @ts-expect-error

// @ts-expect-error [TODO]
delete copy.viewable;

return copy;
Expand Down
7 changes: 7 additions & 0 deletions core/strategies/src/types/stateHub.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export type BaseStateImplProps<ItemT extends GenericItemT = GenericItemT> = {
export type SpaceStateImplProps<ItemT extends GenericItemT = GenericItemT> =
{} & BaseStateImplProps<ItemT>;

export type RecyclerProps = {
recyclerTypes?: string[];
recyclerBufferSize?: number;
recyclerReservedBufferPerBatch?: number;
onRecyclerProcess?: (type?: string, index?: number) => boolean;
};

export type RecycleStateImplProps<ItemT extends GenericItemT = GenericItemT> = {
recyclerTypes?: string[];
recyclerBufferSize?: number;
Expand Down
52 changes: 44 additions & 8 deletions examples/ReactNativeListPlayground/app/(tabs)/Group.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useRef, useCallback } from 'react';
import { useRef, useCallback, useEffect } from 'react';
import { View, Text, ScrollView as NativeScrollView } from 'react-native';

import { ScrollView, ScrollViewContext } from '@infinite-list/scroller';
Expand All @@ -20,7 +20,40 @@ export default () => {
const scrollViewRef = useRef<NativeScrollView>(null);

const renderItem = useCallback((props: { item }) => {
const { item } = props;
const { item, itemMeta, ...rest } = props;

const initRef = useRef(true);
const itemMetaRef = useRef(itemMeta);

if (itemMetaRef.current !== itemMeta) {
itemMetaRef.current = itemMeta;
}

useEffect(() => {
return () => {
console.log('unmount ------------------');
};
}, []);

console.log('rest ---- ', rest);

useEffect(() => {
if (initRef.current) console.log('mount ', itemMeta.getKey());
else {
console.log('update to ', itemMeta.getKey());
}

initRef.current = false;

return () => {
console.log(
'unmount ',
itemMeta.getKey(),
itemMetaRef.current.getKey()
);
};
}, [itemMeta]);

return (
<View style={{ height: 80, width: '100%', backgroundColor: '#fff' }}>
<Text>{item.value}</Text>
Expand All @@ -40,27 +73,30 @@ export default () => {
backgroundColor: 'green',
}}
>
<View
style={{
height: 340,
}}
/>

<ListGroup
id="basic"
containerRef={scrollViewRef}
recyclerBufferSize={100}
recyclerReservedBufferPerBatch={50}
initialNumToRender={10}
scrollComponentContext={ScrollViewContext}
>
<GroupList
id="first"
data={buildData(500)}
recyclerBufferSize={100}
recyclerReservedBufferPerBatch={50}
renderItem={renderItem}
keyExtractor={keyExtractor}
initialNumToRender={0}
/>

<GroupList<Item>
id="second"
initialNumToRender={0}
data={buildData(500, 500)}
recyclerBufferSize={100}
recyclerReservedBufferPerBatch={50}
renderItem={renderItem}
keyExtractor={keyExtractor}
/>
Expand Down
18 changes: 16 additions & 2 deletions examples/ReactNativeListPlayground/app/(tabs)/MasonryList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useMemo, useRef } from 'react';
import { useCallback, useMemo, useRef, useEffect } from 'react';
import { ScrollView as NativeScrollView } from 'react-native';
import { MasonryList } from '@infinite-list/masonry';
import { ScrollView } from '@infinite-list/scroller';
Expand All @@ -14,10 +14,24 @@ export default () => {
const data = useMemo(() => buildData(10000), []);
const scrollViewRef = useRef<NativeScrollView>(null);

const renderItem = useCallback((props: { item }) => {
const renderItem = useCallback((props) => {
const { item, itemMeta } = props;
const index = itemMeta.getIndexInfo().index;
const totalIndex = itemMeta.getIndexInfo().indexInTotal;
const initRef = useRef(true);

useEffect(() => {
if (initRef.current) console.log('mount ', itemMeta.getKey());
else {
console.log('update to ', itemMeta.getKey());
}

initRef.current = false;

return () => {
console.log('unmount ', itemMeta.getKey());
};
}, [itemMeta]);

return (
<View
Expand Down
2 changes: 1 addition & 1 deletion examples/ReactNativeListPlayground/app/(tabs)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ import Group from './Group';
import HorizontalList from './HorizontalList';

export default () => {
return <Group />;
// return <Group />;
// return <MasonryList />;
return <List />;
return <HorizontalList />;
Expand Down
17 changes: 8 additions & 9 deletions examples/react-playground/src/app/group.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ const meta: Meta<typeof ListGroup> = {
// overflowY: 'auto',
}}
>
<ListGroup id="basic">
<ListGroup
id="basic"
initialNumToRender={0}
recyclerBufferSize={100}
recyclerReservedBufferPerBatch={50}
>
<GroupList
id="first"
initialNumToRender={0}
data={buildData(500)}
recyclerBufferSize={100}
recyclerReservedBufferPerBatch={50}
renderItem={(props: RenderItemInfo<Item>) => {
const { item } = props;
return (
Expand All @@ -50,15 +52,12 @@ const meta: Meta<typeof ListGroup> = {
</div>
);
}}
keyExtractor={defaultKeyExtractor as KeyExtractor<Item>}
keyExtractor={defaultKeyExtractor}
/>

<GroupList
id="second"
initialNumToRender={0}
data={buildData(500, 500)}
recyclerBufferSize={100}
recyclerReservedBufferPerBatch={50}
renderItem={(props: RenderItemInfo<Item>) => {
const { item } = props;

Expand All @@ -76,7 +75,7 @@ const meta: Meta<typeof ListGroup> = {
</div>
);
}}
keyExtractor={defaultKeyExtractor as KeyExtractor<Item>}
keyExtractor={defaultKeyExtractor}
/>
</ListGroup>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/common/PortalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const SpaceContent = <ItemT extends GenericItemT = GenericItemT>(
return (
<>
{state.map((stateResult) => {
const { isSpace, key, item, length, isSticky, itemMeta } = stateResult;
const { isSpace, key, item, length, itemMeta } = stateResult;

const metaOwner = itemMeta?.getOwner();
const info = metaOwner?.extraInfo as ExtraInfo<ItemT>;
Expand Down
5 changes: 1 addition & 4 deletions ui/group/src/react-native/CompatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ const CompatListItem = <ItemT extends GenericItemT>(
style: _style = {},
children,
forwardRef,

dimensions,
recycleItemContainerKey,
CellRendererComponent,
onMeasureLayout: _onMeasureLayout,
setDimensionItemLayout,
addItemChangedListener,
containerRef,
itemMeta,
...rest
item,
} = props;
const containerStyle = useMemo(
() => StyleSheet.flatten([_style, { elevation: 0 }]),
Expand Down Expand Up @@ -104,7 +102,6 @@ const CompatListItem = <ItemT extends GenericItemT>(
onLayout={layoutHandler}
key={recycleItemContainerKey}
{...refProps}
{...rest}
style={containerStyle}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion ui/group/src/react-native/ListGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const ListGroup = <ItemT extends GenericItemT>(
* like IOC, the specific logic placed on the topmost.
*/
const ListItemWrapper = useCallback<TListItemWrapper<ItemT>>((props) => {
return <CompatListItem {...props} containerRef={containerRef} />;
return <CompatListItem {...props} containerRef={viewRef} />;
}, []);

return (
Expand Down
1 change: 0 additions & 1 deletion ui/group/src/react-native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export { default as ListGroup } from './ListGroup';
export { default as GroupList } from '../common/GroupList';
export { default as ListGroupContext } from '../common/context';
export { default as GroupListItem } from '../common/GroupDimensionItem';
export * from './types';
29 changes: 5 additions & 24 deletions ui/group/src/react-native/types/ListGroup.types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import {
OnEndReachedHelperProps,
ViewabilityConfig,
OnViewableItemsChanged,
ViewabilityConfigCallbackPairs,
} from '@infinite-list/viewable';
import { ComponentType, PropsWithChildren, MutableRefObject } from 'react';
import { MutableRefObject } from 'react';
import { View, ScrollView, LayoutChangeEvent } from 'react-native';
import { GenericItemT } from '@infinite-list/item-meta';
import { GenericItemT } from '@infinite-list/types';
import { RefObject } from 'react';
import { ListGroupProps as CommonListGroupProps } from '../../types';

export type ScrollComponentUseMeasureLayout = (
itemRef: MutableRefObject<View | null>,
Expand All @@ -24,19 +19,5 @@ export type ScrollComponentUseMeasureLayout = (

export type ContainerRef = RefObject<ScrollView | View | any>;

export type ListGroupProps<ItemT extends GenericItemT> = PropsWithChildren<{
id: string;
onViewableItemsChanged?: OnViewableItemsChanged;
viewabilityConfig?: ViewabilityConfig;
viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs;
initialNumToRender?: number;
windowSize?: number;
maxToRenderPerBatch?: number;
onRenderFinished?: () => void;
persistanceIndices?: number[];

scrollComponentContext: any;
containerRef: ContainerRef;
GroupListSeparatorComponent?: ComponentType<ItemT> | null | undefined;
}> &
OnEndReachedHelperProps;
export type ListGroupProps<ItemT extends GenericItemT> =
CommonListGroupProps<ItemT>;
1 change: 0 additions & 1 deletion ui/group/src/react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export { default as ListGroup } from './ListGroup';
export { default as GroupList } from '../common/GroupList';
export { default as ListGroupContext } from '../common/context';
export { default as GroupListItem } from '../common/GroupDimensionItem';
export * from './types';
27 changes: 5 additions & 22 deletions ui/group/src/react/types/ListGroup.types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {
OnEndReachedHelperProps,
ViewabilityConfig,
OnViewableItemsChanged,
ViewabilityConfigCallbackPairs,
} from '@infinite-list/viewable';
import { ComponentType, PropsWithChildren, MutableRefObject } from 'react';
import { MutableRefObject } from 'react';
import { View, LayoutChangeEvent } from 'react-native';
import { GenericItemT } from '@infinite-list/types';
import { ListGroupProps as CommonListGroupProps } from '../../types';

export type ScrollComponentUseMeasureLayout = (
itemRef: MutableRefObject<View | null>,
Expand All @@ -20,18 +16,5 @@ export type ScrollComponentUseMeasureLayout = (
layoutHandler: (e: LayoutChangeEvent) => void;
};

export type ListGroupProps = PropsWithChildren<{
GroupListSeparatorComponent?: ComponentType<any> | null | undefined;
id: string;
onViewableItemsChanged?: OnViewableItemsChanged;
viewabilityConfig?: ViewabilityConfig;
viewabilityConfigCallbackPairs?: ViewabilityConfigCallbackPairs;
initialNumToRender?: number;
windowSize?: number;
maxToRenderPerBatch?: number;
onRenderFinished?: () => void;
persistanceIndices?: number[];

scrollComponentContext: any;
}> &
OnEndReachedHelperProps;
export type ListGroupProps<ItemT extends GenericItemT> =
CommonListGroupProps<ItemT>;
Loading
Loading