Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit 6d517b9

Browse files
authored
fix: teach ScrollPager how to call onIndexChange (#994)
fixes #993
1 parent 1f04e9f commit 6d517b9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/ScrollPager.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Animated from 'react-native-reanimated';
44
import { Props } from './Pager';
55
import { Route, Listener } from './types';
66

7-
const { event, divide, Value } = Animated;
7+
const { event, divide, onChange, cond, eq, round, call, Value } = Animated;
88

99
type State = {
1010
initialOffset: { x: number; y: number };
@@ -136,6 +136,7 @@ export default class ScrollPager<T extends Route> extends React.Component<
136136
onSwipeStart,
137137
onSwipeEnd,
138138
overscroll,
139+
onIndexChange,
139140
navigationState,
140141
} = this.props;
141142

@@ -188,6 +189,16 @@ export default class ScrollPager<T extends Route> extends React.Component<
188189
ref={this.scrollViewRef}
189190
>
190191
{children}
192+
<Animated.Code
193+
exec={onChange(
194+
this.relativePosition,
195+
cond(eq(round(this.relativePosition), this.relativePosition), [
196+
call([this.relativePosition], ([relativePosition]) =>
197+
onIndexChange(relativePosition)
198+
),
199+
])
200+
)}
201+
/>
191202
</Animated.ScrollView>
192203
),
193204
});

0 commit comments

Comments
 (0)