@shopify/flash-list 1.2.1 → 1.3.0
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/CHANGELOG.md +10 -0
- package/dist/FlashList.d.ts +1 -1
- package/dist/FlashList.d.ts.map +1 -1
- package/dist/FlashList.js +8 -4
- package/dist/FlashList.js.map +1 -1
- package/dist/MasonryFlashList.d.ts +39 -0
- package/dist/MasonryFlashList.d.ts.map +1 -0
- package/dist/MasonryFlashList.js +241 -0
- package/dist/MasonryFlashList.js.map +1 -0
- package/dist/__tests__/MasonryFlashList.test.d.ts +2 -0
- package/dist/__tests__/MasonryFlashList.test.d.ts.map +1 -0
- package/dist/__tests__/MasonryFlashList.test.js +205 -0
- package/dist/__tests__/MasonryFlashList.test.js.map +1 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts +18 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts.map +1 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.js +44 -0
- package/dist/__tests__/helpers/mountMasonryFlashList.js.map +1 -0
- package/dist/errors/ExceptionList.d.ts +4 -0
- package/dist/errors/ExceptionList.d.ts.map +1 -1
- package/dist/errors/ExceptionList.js +4 -0
- package/dist/errors/ExceptionList.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/native/auto-layout/AutoLayoutView.d.ts +2 -1
- package/dist/native/auto-layout/AutoLayoutView.d.ts.map +1 -1
- package/dist/native/auto-layout/AutoLayoutView.js.map +1 -1
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +2 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/viewability/ViewabilityManager.d.ts.map +1 -1
- package/dist/viewability/ViewabilityManager.js +3 -3
- package/dist/viewability/ViewabilityManager.js.map +1 -1
- package/package.json +11 -2
- package/src/FlashList.tsx +10 -5
- package/src/MasonryFlashList.tsx +439 -0
- package/src/__tests__/MasonryFlashList.test.ts +235 -0
- package/src/__tests__/helpers/mountMasonryFlashList.tsx +65 -0
- package/src/errors/ExceptionList.ts +5 -0
- package/src/index.ts +7 -0
- package/src/native/auto-layout/AutoLayoutView.tsx +2 -1
- package/src/native/auto-layout/AutoLayoutViewNativeComponentProps.ts +3 -0
- package/src/viewability/ViewabilityManager.ts +2 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text } from "react-native";
|
|
3
|
+
import "@quilted/react-testing/matchers";
|
|
4
|
+
import { mount, Root } from "@quilted/react-testing";
|
|
5
|
+
|
|
6
|
+
import { ListRenderItem } from "../../FlashListProps";
|
|
7
|
+
import {
|
|
8
|
+
MasonryFlashList,
|
|
9
|
+
MasonryFlashListProps,
|
|
10
|
+
MasonryFlashListRef,
|
|
11
|
+
} from "../../MasonryFlashList";
|
|
12
|
+
|
|
13
|
+
jest.mock("../../FlashList", () => {
|
|
14
|
+
const ActualFlashList = jest.requireActual("../../FlashList").default;
|
|
15
|
+
class MockFlashList extends ActualFlashList {
|
|
16
|
+
componentDidMount() {
|
|
17
|
+
super.componentDidMount();
|
|
18
|
+
this.rlvRef?._scrollComponent?._scrollViewRef?.props.onLayout({
|
|
19
|
+
nativeEvent: { layout: { height: 900, width: 400 } },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return MockFlashList;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type MockMasonryFlashListProps = Omit<
|
|
27
|
+
MasonryFlashListProps<string>,
|
|
28
|
+
"estimatedItemSize" | "data" | "renderItem"
|
|
29
|
+
> & {
|
|
30
|
+
estimatedItemSize?: number;
|
|
31
|
+
data?: string[];
|
|
32
|
+
renderItem?: ListRenderItem<string>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Helper to mount MasonryFlashList for testing.
|
|
37
|
+
*/
|
|
38
|
+
export const mountMasonryFlashList = (
|
|
39
|
+
props?: MockMasonryFlashListProps,
|
|
40
|
+
ref?: React.RefObject<MasonryFlashListRef<string>>
|
|
41
|
+
) => {
|
|
42
|
+
const flashList = mount(renderMasonryFlashList(props, ref)) as Omit<
|
|
43
|
+
Root<MasonryFlashListProps<string>>,
|
|
44
|
+
"instance"
|
|
45
|
+
> & {
|
|
46
|
+
instance: MasonryFlashListRef<string>;
|
|
47
|
+
};
|
|
48
|
+
return flashList;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export function renderMasonryFlashList(
|
|
52
|
+
props?: MockMasonryFlashListProps,
|
|
53
|
+
ref?: React.RefObject<MasonryFlashListRef<string>>
|
|
54
|
+
) {
|
|
55
|
+
return (
|
|
56
|
+
<MasonryFlashList
|
|
57
|
+
{...props}
|
|
58
|
+
ref={ref}
|
|
59
|
+
numColumns={props?.numColumns ?? 2}
|
|
60
|
+
renderItem={props?.renderItem || (({ item }) => <Text>{item}</Text>)}
|
|
61
|
+
estimatedItemSize={props?.estimatedItemSize ?? 200}
|
|
62
|
+
data={props?.data || ["One", "Two", "Three", "Four"]}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -19,5 +19,10 @@ const ExceptionList = {
|
|
|
19
19
|
"You can set exactly one of itemVisiblePercentThreshold or viewAreaCoveragePercentThreshold. Specifying both is not supported.",
|
|
20
20
|
type: "MultipleViewabilityThresholdTypesException",
|
|
21
21
|
},
|
|
22
|
+
overrideItemLayoutRequiredForMasonryOptimization: {
|
|
23
|
+
message:
|
|
24
|
+
"optimizeItemArrangement has been enabled on `MasonryFlashList` but overrideItemLayout is not set.",
|
|
25
|
+
type: "InvariantViolation",
|
|
26
|
+
},
|
|
22
27
|
};
|
|
23
28
|
export default ExceptionList;
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,13 @@ export {
|
|
|
28
28
|
BlankAreaTrackerResult,
|
|
29
29
|
BlankAreaTrackerConfig,
|
|
30
30
|
} from "./benchmark/useBlankAreaTracker";
|
|
31
|
+
export {
|
|
32
|
+
MasonryFlashList,
|
|
33
|
+
MasonryFlashListProps,
|
|
34
|
+
MasonryFlashListScrollEvent,
|
|
35
|
+
MasonryFlashListRef,
|
|
36
|
+
MasonryListItem,
|
|
37
|
+
} from "./MasonryFlashList";
|
|
31
38
|
export { JSFPSMonitor, JSFPSResult } from "./benchmark/JSFPSMonitor";
|
|
32
39
|
export { autoScroll, Cancellable } from "./benchmark/AutoScrollHelper";
|
|
33
40
|
export { default as ViewToken } from "./viewability/ViewToken";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect } from "react";
|
|
1
|
+
import React, { useEffect, ReactNode } from "react";
|
|
2
2
|
import { LayoutChangeEvent } from "react-native";
|
|
3
3
|
|
|
4
4
|
import AutoLayoutViewNativeComponent from "./AutoLayoutViewNativeComponent";
|
|
@@ -25,6 +25,7 @@ export interface BlankAreaEvent {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export interface AutoLayoutViewProps {
|
|
28
|
+
children?: ReactNode;
|
|
28
29
|
onBlankAreaEvent?: BlankAreaEventHandler;
|
|
29
30
|
onLayout?: (event: LayoutChangeEvent) => void;
|
|
30
31
|
disableAutoLayout?: boolean;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
|
|
1
3
|
export interface OnBlankAreaEvent {
|
|
2
4
|
nativeEvent: {
|
|
3
5
|
offsetStart: number;
|
|
@@ -8,6 +10,7 @@ export interface OnBlankAreaEvent {
|
|
|
8
10
|
type OnBlankAreaEventHandler = (event: OnBlankAreaEvent) => void;
|
|
9
11
|
|
|
10
12
|
export interface AutoLayoutViewNativeComponentProps {
|
|
13
|
+
children?: ReactNode;
|
|
11
14
|
onBlankAreaEvent: OnBlankAreaEventHandler;
|
|
12
15
|
enableInstrumentation: boolean;
|
|
13
16
|
disableAutoLayout?: boolean;
|
|
@@ -68,7 +68,8 @@ export default class ViewabilityManager<T> {
|
|
|
68
68
|
|
|
69
69
|
public updateViewableItems = (newViewableIndices?: number[]) => {
|
|
70
70
|
const listSize =
|
|
71
|
-
this.flashListRef.recyclerlistview_unsafe?.getRenderedSize()
|
|
71
|
+
this.flashListRef.recyclerlistview_unsafe?.getRenderedSize() ??
|
|
72
|
+
this.flashListRef.props.estimatedListSize;
|
|
72
73
|
if (listSize === undefined || !this.shouldListenToVisibleIndices) {
|
|
73
74
|
return;
|
|
74
75
|
}
|