Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
gusgard committed Apr 23, 2024
1 parent 9b26891 commit d9e22c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ web-build/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

artifacts/*
23 changes: 18 additions & 5 deletions src/components/SwiperFlatList/SwiperFlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
I18nManager,
Platform,
useWindowDimensions,
ViewabilityConfigCallbackPair,
ViewabilityConfigCallbackPairs,
} from 'react-native';

import { Pagination } from '../Pagination/Pagination';
Expand Down Expand Up @@ -199,7 +201,9 @@ export const SwiperFlatList = React.forwardRef(
onMomentumScrollEnd?.({ index: currentIndexes.index }, event);
};

const _onViewableItemsChanged = React.useMemo<FlatListProps<unknown>['onViewableItemsChanged']>(
const _onViewableItemsChanged = React.useMemo<
ViewabilityConfigCallbackPair['onViewableItemsChanged']
>(
() => (params) => {
const { changed } = params;
const newItem = changed?.[FIRST_INDEX];
Expand All @@ -216,8 +220,16 @@ export const SwiperFlatList = React.forwardRef(
[onViewableItemsChanged],
);

const viewabilityConfigCallbackPairs = useRef<any>([
{ onViewableItemsChanged:_onViewableItemsChanged, },
const viewabilityConfigCallbackPairs = useRef<ViewabilityConfigCallbackPairs>([
{
onViewableItemsChanged: _onViewableItemsChanged,
viewabilityConfig: {
// https://facebook.github.io/react-native/docs/flatlist#minimumviewtime
minimumViewTime: 200,
itemVisiblePercentThreshold: ITEM_VISIBLE_PERCENT_THRESHOLD,
...viewabilityConfig,
},
},
]);

const flatListProps: FlatListProps<unknown> & { ref: React.RefObject<RNFlatList<unknown>> } = {
Expand Down Expand Up @@ -246,8 +258,9 @@ export const SwiperFlatList = React.forwardRef(
itemVisiblePercentThreshold: ITEM_VISIBLE_PERCENT_THRESHOLD,
...viewabilityConfig,
},
viewabilityConfigCallbackPairs: Platform.OS === 'ios'? viewabilityConfigCallbackPairs.current : undefined,
onViewableItemsChanged: Platform.OS === 'android'? _onViewableItemsChanged : undefined,
viewabilityConfigCallbackPairs:
Platform.OS === 'ios' ? viewabilityConfigCallbackPairs.current : undefined,
onViewableItemsChanged: Platform.OS === 'android' ? _onViewableItemsChanged : undefined,
// debug: true, // for debug
testID: e2eID,
};
Expand Down

0 comments on commit d9e22c1

Please sign in to comment.