Skip to content

Commit

Permalink
fix: snapping when momentum scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
andreialecu committed Dec 2, 2020
1 parent d97657b commit 887b0d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"babel-plugin-module-resolver": "^4.0.0",
"babel-preset-expo": "^8.2.3",
"expo-cli": "^3.23.1",
"typescript": "~3.9.7"
"typescript": "~3.9.7",
"use-debounce": "^5.1.0"
},
"resolutions": {
"@babel/runtime": "^7.9.0"
Expand Down
5 changes: 5 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12981,6 +12981,11 @@ url@^0.11.0:
punycode "1.3.2"
querystring "0.2.0"

use-debounce@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/use-debounce/-/use-debounce-5.1.0.tgz#3df34bd7449da7dd2dbb10a6513efe701fc79d02"
integrity sha512-fU7O7iel2bA19fxSiPfRkieVGxrow503phSUAGZ/EqiJtCPrU9AdUdrKOAdgh803IrjdIzhj+8eDsDGn4OPy8g==

use-subscription@^1.0.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/use-subscription/-/use-subscription-1.4.1.tgz#edcbcc220f1adb2dd4fa0b2f61b6cc308e620069"
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,8 @@
"module",
"typescript"
]
},
"dependencies": {
"use-debounce": "^5.1.0"
}
}
8 changes: 5 additions & 3 deletions src/CollapsibleTabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
NavigationState,
SceneRendererProps,
} from 'react-native-tab-view';

import { useDebouncedCallback } from 'use-debounce';
import { CollapsibleContextProvider } from './CollapsibleTabViewContext';
import scrollScene from './scrollScene';
import type { ScrollRef, GetRef } from './types';
Expand Down Expand Up @@ -174,18 +174,20 @@ const CollapsibleTabView = <T extends Route>({
}
});
}, [routes, index, headerHeight, disableSnap, snapThreshold]);
const syncScrollOffsetDebounced = useDebouncedCallback(syncScrollOffset, 16);

const onMomentumScrollBegin = () => {
isGliding.current = true;
syncScrollOffsetDebounced.cancel();
};

const onMomentumScrollEnd = () => {
isGliding.current = false;
syncScrollOffset();
syncScrollOffsetDebounced.callback();
};

const onScrollEndDrag = () => {
syncScrollOffset();
syncScrollOffsetDebounced.callback();
};

/**
Expand Down

0 comments on commit 887b0d9

Please sign in to comment.