From e1d2717b71c6b77094434707c9f22c23b884d032 Mon Sep 17 00:00:00 2001 From: metkm Date: Fri, 17 Jan 2025 17:21:30 +0300 Subject: [PATCH] fix viewableitemschange --- components/lines/Lines.tsx | 11 +++++++++-- components/lines/line/LineBusStops.tsx | 2 +- .../markers/line/arrows/MarkersLineArrows.web.tsx | 6 ++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/components/lines/Lines.tsx b/components/lines/Lines.tsx index b98e194..ba111fb 100644 --- a/components/lines/Lines.tsx +++ b/components/lines/Lines.tsx @@ -67,7 +67,7 @@ const Lines = (props: LinesProps, outerRef: ForwardedRef) => { ) type ViewableItems = FlatListProps['onViewableItemsChanged'] - const handleOnViewChanged: ViewableItems = ({ viewableItems }) => { + const handleViewableItemsChanged: ViewableItems = ({ viewableItems }) => { if (viewableItems.length < 1 || Platform.OS === 'web') return useMiscStore.setState(() => ({ selectedLineScrollIndex: viewableItems.at(0)?.index || 0 })) @@ -82,7 +82,6 @@ const Lines = (props: LinesProps, outerRef: ForwardedRef) => { ref={innerRef} data={lines} renderItem={renderItem} - onViewableItemsChanged={handleOnViewChanged} viewabilityConfig={{ itemVisiblePercentThreshold: 70 }} contentContainerStyle={[styles.codes, props.contentContainerStyle]} keyExtractor={keyExtractor} @@ -92,6 +91,14 @@ const Lines = (props: LinesProps, outerRef: ForwardedRef) => { snapToAlignment="center" pagingEnabled horizontal + + { + ...Platform.OS !== 'web' + ? { + onViewableItemsChanged: handleViewableItemsChanged, + } + : {} + } /> ) diff --git a/components/lines/line/LineBusStops.tsx b/components/lines/line/LineBusStops.tsx index 304e495..398f714 100644 --- a/components/lines/line/LineBusStops.tsx +++ b/components/lines/line/LineBusStops.tsx @@ -230,7 +230,7 @@ export const LineBusStops = ({ lineCode, variant = 'solid' }: LineBusStopsProps) onMomentumScrollEnd={handleScrollMomentumEnd} drawDistance={1} { - ...Platform.OS === 'web' + ...Platform.OS !== 'web' ? { onViewableItemsChanged: handleViewableItemsChanged, } diff --git a/components/markers/line/arrows/MarkersLineArrows.web.tsx b/components/markers/line/arrows/MarkersLineArrows.web.tsx index 2d0e0dc..f264a78 100644 --- a/components/markers/line/arrows/MarkersLineArrows.web.tsx +++ b/components/markers/line/arrows/MarkersLineArrows.web.tsx @@ -34,9 +34,11 @@ export const MarkersLineArrows = ({ arrows, lineTheme }: MarkersLineArrowsProps) ( - +