Skip to content

Commit 1d665c0

Browse files
committed
Clean up warnings and exceptions
1 parent 330290e commit 1d665c0

14 files changed

+63
-74
lines changed

src/__tests__/ViewabilityHelper.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Dimension, Layout } from "recyclerlistview";
22

3-
import CustomError from "../errors/CustomError";
4-
import ExceptionList from "../errors/ExceptionList";
53
import ViewabilityHelper from "../recyclerview/viewability/ViewabilityHelper";
4+
import { ErrorMessages } from "../errors/ErrorMessages";
65

76
describe("ViewabilityHelper", () => {
87
const viewableIndicesChanged = jest.fn();
@@ -246,9 +245,7 @@ describe("ViewabilityHelper", () => {
246245
viewableIndicesChanged
247246
);
248247
expect(() => updateViewableItems({ viewabilityHelper })).toThrow(
249-
new CustomError(
250-
ExceptionList.multipleViewabilityThresholdTypesNotSupported
251-
)
248+
ErrorMessages.multipleViewabilityThresholdTypesNotSupported
252249
);
253250
});
254251

src/benchmark/JSFPSMonitor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ErrorMessages } from "../errors/ErrorMessages";
2+
13
import { roundToDecimalPlaces } from "./roundToDecimalPlaces";
24

35
/**
@@ -44,9 +46,7 @@ export class JSFPSMonitor {
4446

4547
public startTracking() {
4648
if (this.startTime !== 0) {
47-
throw new Error(
48-
"This FPS Monitor has already been run, please create a new instance"
49-
);
49+
throw new Error(ErrorMessages.fpsMonitorAlreadyRunning);
5050
}
5151
this.startTime = Date.now();
5252
this.timeWindow.startTime = Date.now();

src/benchmark/useBenchmark.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect } from "react";
22

33
import { FlashListRef } from "../FlashListRef";
4+
import { ErrorMessages } from "../errors/ErrorMessages";
45

56
import { autoScroll, Cancellable } from "./AutoScrollHelper";
67
import { JSFPSMonitor, JSFPSResult } from "./JSFPSMonitor";
@@ -48,7 +49,7 @@ export function useBenchmark(
4849
const suggestions: string[] = [];
4950
if (flashListRef.current) {
5051
if (!(Number(flashListRef.current.props.data?.length) > 0)) {
51-
throw new Error("Data is empty, cannot run benchmark");
52+
throw new Error(ErrorMessages.dataEmptyCannotRunBenchmark);
5253
}
5354
}
5455
const cancelTimeout = setTimeout(async () => {

src/benchmark/useFlatListBenchmark.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { useEffect } from "react";
22
import { FlatList } from "react-native";
33

4+
import { ErrorMessages } from "../errors/ErrorMessages";
5+
46
import { autoScroll, Cancellable } from "./AutoScrollHelper";
57
import { JSFPSMonitor } from "./JSFPSMonitor";
68
import {
@@ -27,7 +29,7 @@ export function useFlatListBenchmark(
2729
const cancellable = new Cancellable();
2830
if (flatListRef.current && flatListRef.current.props) {
2931
if (!(Number(flatListRef.current.props.data?.length) > 0)) {
30-
throw new Error("Data is empty, cannot run benchmark");
32+
throw new Error(ErrorMessages.dataEmptyCannotRunBenchmark);
3133
}
3234
}
3335
const cancelTimeout = setTimeout(async () => {

src/errors/CustomError.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/errors/ErrorMessages.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const ErrorMessages = {
2+
multipleViewabilityThresholdTypesNotSupported:
3+
"You can set exactly one of itemVisiblePercentThreshold or viewAreaCoveragePercentThreshold. Specifying both is not supported.",
4+
flashListV2OnlySupportsNewArchitecture:
5+
"FlashList v2 is only supported on new architecture",
6+
layoutManagerNotInitializedLayoutInfo:
7+
"LayoutManager is not initialized, layout info is unavailable",
8+
layoutManagerNotInitializedChildContainer:
9+
"LayoutManager is not initialized, child container layout is unavailable",
10+
layoutManagerNotInitializedWindowSize:
11+
"LayoutManager is not initialized, window size is unavailable",
12+
horizontalPropCannotBeToggled:
13+
"Horizontal prop cannot be toggled, you can use a key on FlashList to recreate it.",
14+
layoutManagerNotInitializedVisibleIndices:
15+
"LayoutManager is not initialized, visible indices are not unavailable",
16+
masonryAndHorizontalIncompatible:
17+
"Masonry and horizontal props are incompatible",
18+
numColumnsAndHorizontalIncompatible:
19+
"numColumns and horizontal props are incompatible",
20+
indexOutOfBounds: "index out of bounds, not enough layouts",
21+
fpsMonitorAlreadyRunning:
22+
"This FPS Monitor has already been run, please create a new instance",
23+
dataEmptyCannotRunBenchmark: "Data is empty, cannot run benchmark",
24+
stickyHeadersNotSupportedForHorizontal:
25+
"Sticky headers are not supported when list is horizontal",
26+
};

src/errors/ExceptionList.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/errors/WarningMessages.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const WarningMessages = {
2+
keyExtractorNotDefinedForAnimation:
3+
"keyExtractor is not defined. This might cause the animations to not work as expected.",
4+
};

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Keep this unmodified for TS type checking
22
import { isNewArch } from "./isNewArch";
3+
import { ErrorMessages } from "./errors/ErrorMessages";
34

45
export { FlashList } from "./FlashList";
56
export { FlashListRef } from "./FlashListRef";
@@ -34,5 +35,5 @@ export {
3435
} from "./recyclerview/LayoutCommitObserver";
3536

3637
if (!isNewArch()) {
37-
throw new Error("FlashList v2 is only supported on new architecture");
38+
throw new Error(ErrorMessages.flashListV2OnlySupportsNewArchitecture);
3839
}

src/recyclerview/RecyclerView.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "react-native";
2121

2222
import { FlashListRef } from "../FlashListRef";
23+
import { ErrorMessages } from "../errors/ErrorMessages";
2324

2425
import { RVDimension } from "./layout-managers/LayoutManager";
2526
import {
@@ -384,6 +385,9 @@ const RecyclerViewComponent = <T,>(
384385
stickyHeaderIndices &&
385386
stickyHeaderIndices.length > 0
386387
) {
388+
if (horizontal) {
389+
throw new Error(ErrorMessages.stickyHeadersNotSupportedForHorizontal);
390+
}
387391
return (
388392
<StickyHeaders
389393
stickyHeaderIndices={stickyHeaderIndices}
@@ -402,6 +406,7 @@ const RecyclerViewComponent = <T,>(
402406
stickyHeaderIndices,
403407
renderItem,
404408
scrollY,
409+
horizontal,
405410
recyclerViewManager,
406411
extraData,
407412
]);

0 commit comments

Comments
 (0)