Skip to content

Commit 4fae119

Browse files
committed
add onScrollOffsetChange prop
1 parent 756eb94 commit 4fae119

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ All props are spread onto underlying [FlatList](https://facebook.github.io/react
3333
| `animationConfig` | `Partial<Animated.SpringConfig>` | Configure list animations. See [reanimated spring config](https://github.com/software-mansion/react-native-reanimated/blob/master/react-native-reanimated.d.ts#L112-L120) |
3434
| `activationDistance` | `number` | Distance a finger must travel before the gesture handler activates. Useful when using a draggable list within a TabNavigator so that the list does not capture navigator gestures. |
3535
| `layoutInvalidationKey` | `string` | Changing this value forces a remeasure of all item layouts. Useful if item size/ordering updates after initial mount. |
36+
| `onScrollOffsetChange` | `(offset: number) => void` | Called with scroll offset. Stand-in for `onScroll`. |
3637

3738
## Example
3839

src/index.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type Props<T> = Modify<
108108
activationDistance?: number;
109109
debug?: boolean;
110110
layoutInvalidationKey?: string;
111+
onScrollOffsetChange?: (scrollOffset: number) => void;
111112
} & Partial<DefaultProps>
112113
>;
113114

@@ -859,7 +860,13 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
859860
};
860861

861862
render() {
862-
const { scrollEnabled, debug, horizontal, activationDistance } = this.props;
863+
const {
864+
scrollEnabled,
865+
debug,
866+
horizontal,
867+
activationDistance,
868+
onScrollOffsetChange
869+
} = this.props;
863870
const { hoverComponent } = this.state;
864871
let dynamicProps = {};
865872
if (activationDistance) {
@@ -894,7 +901,6 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
894901
scrollEventThrottle={1}
895902
/>
896903
{!!hoverComponent && this.renderHoverComponent()}
897-
{debug && this.renderDebug()}
898904
<Animated.Code>
899905
{() =>
900906
block([
@@ -919,6 +925,19 @@ class DraggableFlatList<T> extends React.Component<Props<T>, State> {
919925
])
920926
}
921927
</Animated.Code>
928+
{onScrollOffsetChange && (
929+
<Animated.Code>
930+
{() =>
931+
onChange(
932+
this.scrollOffset,
933+
call([this.scrollOffset], ([offset]) =>
934+
onScrollOffsetChange(offset)
935+
)
936+
)
937+
}
938+
</Animated.Code>
939+
)}
940+
{debug && this.renderDebug()}
922941
</Animated.View>
923942
</PanGestureHandler>
924943
);

0 commit comments

Comments
 (0)