@shopify/flash-list 1.3.1 → 1.4.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 +7 -0
- package/dist/FlashList.d.ts +0 -1
- package/dist/FlashList.d.ts.map +1 -1
- package/dist/FlashList.js +17 -41
- package/dist/FlashList.js.map +1 -1
- package/dist/FlashListProps.d.ts +0 -1
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/GridLayoutProviderWithProps.d.ts +9 -1
- package/dist/GridLayoutProviderWithProps.d.ts.map +1 -1
- package/dist/GridLayoutProviderWithProps.js +30 -1
- package/dist/GridLayoutProviderWithProps.js.map +1 -1
- package/dist/MasonryFlashList.d.ts +1 -1
- package/dist/MasonryFlashList.d.ts.map +1 -1
- package/dist/MasonryFlashList.js +13 -4
- package/dist/MasonryFlashList.js.map +1 -1
- package/dist/__tests__/ContentContainerUtils.test.d.ts +2 -0
- package/dist/__tests__/ContentContainerUtils.test.d.ts.map +1 -0
- package/dist/__tests__/ContentContainerUtils.test.js +85 -0
- package/dist/__tests__/ContentContainerUtils.test.js.map +1 -0
- package/dist/__tests__/FlashList.test.js +32 -0
- package/dist/__tests__/FlashList.test.js.map +1 -1
- package/dist/__tests__/GridLayoutProviderWithProps.test.js +10 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.js.map +1 -1
- package/dist/__tests__/MasonryFlashList.test.js +28 -0
- package/dist/__tests__/MasonryFlashList.test.js.map +1 -1
- package/dist/__tests__/helpers/mountMasonryFlashList.d.ts.map +1 -1
- package/dist/__tests__/helpers/mountMasonryFlashList.js +7 -2
- package/dist/__tests__/helpers/mountMasonryFlashList.js.map +1 -1
- package/dist/errors/Warnings.d.ts +0 -1
- package/dist/errors/Warnings.d.ts.map +1 -1
- package/dist/errors/Warnings.js +1 -3
- package/dist/errors/Warnings.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/ContentContainerUtils.d.ts +27 -0
- package/dist/utils/ContentContainerUtils.d.ts.map +1 -0
- package/dist/utils/ContentContainerUtils.js +48 -0
- package/dist/utils/ContentContainerUtils.js.map +1 -0
- package/package.json +3 -3
- package/src/FlashList.tsx +29 -50
- package/src/FlashListProps.ts +0 -1
- package/src/GridLayoutProviderWithProps.ts +39 -3
- package/src/MasonryFlashList.tsx +18 -4
- package/src/__tests__/ContentContainerUtils.test.ts +130 -0
- package/src/__tests__/FlashList.test.tsx +32 -0
- package/src/__tests__/GridLayoutProviderWithProps.test.ts +29 -0
- package/src/__tests__/MasonryFlashList.test.ts +28 -0
- package/src/__tests__/helpers/mountMasonryFlashList.tsx +6 -1
- package/src/errors/Warnings.ts +1 -4
- package/src/utils/ContentContainerUtils.ts +92 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ViewStyle } from "react-native";
|
|
2
|
+
import { Dimension } from "recyclerlistview";
|
|
3
|
+
|
|
4
|
+
import { ContentStyle } from "../FlashListProps";
|
|
5
|
+
|
|
6
|
+
export interface ContentStyleExplicit {
|
|
7
|
+
paddingTop: number;
|
|
8
|
+
paddingBottom: number;
|
|
9
|
+
paddingLeft: number;
|
|
10
|
+
paddingRight: number;
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const updateContentStyle = (
|
|
15
|
+
contentStyle: ContentStyle,
|
|
16
|
+
contentContainerStyleSource: ContentStyle | undefined
|
|
17
|
+
): ContentStyleExplicit => {
|
|
18
|
+
const {
|
|
19
|
+
paddingTop,
|
|
20
|
+
paddingRight,
|
|
21
|
+
paddingBottom,
|
|
22
|
+
paddingLeft,
|
|
23
|
+
padding,
|
|
24
|
+
paddingVertical,
|
|
25
|
+
paddingHorizontal,
|
|
26
|
+
backgroundColor,
|
|
27
|
+
} = (contentContainerStyleSource ?? {}) as ViewStyle;
|
|
28
|
+
contentStyle.paddingLeft = Number(
|
|
29
|
+
paddingLeft || paddingHorizontal || padding || 0
|
|
30
|
+
);
|
|
31
|
+
contentStyle.paddingRight = Number(
|
|
32
|
+
paddingRight || paddingHorizontal || padding || 0
|
|
33
|
+
);
|
|
34
|
+
contentStyle.paddingTop = Number(
|
|
35
|
+
paddingTop || paddingVertical || padding || 0
|
|
36
|
+
);
|
|
37
|
+
contentStyle.paddingBottom = Number(
|
|
38
|
+
paddingBottom || paddingVertical || padding || 0
|
|
39
|
+
);
|
|
40
|
+
contentStyle.backgroundColor = backgroundColor;
|
|
41
|
+
return contentStyle as ContentStyleExplicit;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const hasUnsupportedKeysInContentContainerStyle = (
|
|
45
|
+
contentContainerStyleSource: ViewStyle | undefined
|
|
46
|
+
) => {
|
|
47
|
+
const {
|
|
48
|
+
paddingTop,
|
|
49
|
+
paddingRight,
|
|
50
|
+
paddingBottom,
|
|
51
|
+
paddingLeft,
|
|
52
|
+
padding,
|
|
53
|
+
paddingVertical,
|
|
54
|
+
paddingHorizontal,
|
|
55
|
+
backgroundColor,
|
|
56
|
+
...rest
|
|
57
|
+
} = (contentContainerStyleSource ?? {}) as ViewStyle;
|
|
58
|
+
return Object.keys(rest).length > 0;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Applies padding corrections to given dimension. Mutates the dim object that was passed and returns it. */
|
|
62
|
+
export const applyContentContainerInsetForLayoutManager = (
|
|
63
|
+
dim: Dimension,
|
|
64
|
+
contentContainerStyle: ViewStyle | undefined,
|
|
65
|
+
horizontal: boolean | undefined | null
|
|
66
|
+
) => {
|
|
67
|
+
const contentStyle = updateContentStyle({}, contentContainerStyle);
|
|
68
|
+
if (horizontal) {
|
|
69
|
+
dim.height -= contentStyle.paddingTop + contentStyle.paddingBottom;
|
|
70
|
+
} else {
|
|
71
|
+
dim.width -= contentStyle.paddingLeft + contentStyle.paddingRight;
|
|
72
|
+
}
|
|
73
|
+
return dim;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Returns padding to be applied on content container and will ignore paddings that have already been handled. */
|
|
77
|
+
export const getContentContainerPadding = (
|
|
78
|
+
contentStyle: ContentStyleExplicit,
|
|
79
|
+
horizontal: boolean | undefined | null
|
|
80
|
+
) => {
|
|
81
|
+
if (horizontal) {
|
|
82
|
+
return {
|
|
83
|
+
paddingTop: contentStyle.paddingTop,
|
|
84
|
+
paddingBottom: contentStyle.paddingBottom,
|
|
85
|
+
};
|
|
86
|
+
} else {
|
|
87
|
+
return {
|
|
88
|
+
paddingLeft: contentStyle.paddingLeft,
|
|
89
|
+
paddingRight: contentStyle.paddingRight,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|