-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathscrollActions.js
70 lines (58 loc) · 1.55 KB
/
scrollActions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Copyright Schrodinger, LLC
* All rights reserved.
*
* @providesModule scrollActions
*/
'use strict';
import { bindActionCreators } from 'redux';
import { scrollToX, scrollToY, scrollEnd } from '../reducers';
const getScrollActions = (store, getProps) => {
const scrollActions = bindActionCreators(
{
scrollToX,
scrollToY,
scrollEnd,
},
store.dispatch
);
/**
* Scrolls the table horizontally to position
*
* @param {number} scrollX
*/
const smartScrollToX = (scrollPos) => {
const { scrollX, scrolling } = store.getState();
if (scrollPos === scrollX) {
return;
}
// This is a workaround to prevent content blurring. This happens when translate3d
// is applied with non-rounded values to elements having text.
const roundedScrollPos = Math.round(scrollPos);
const { onHorizontalScroll } = getProps();
if (onHorizontalScroll ? onHorizontalScroll(roundedScrollPos) : true) {
scrollActions.scrollToX(roundedScrollPos);
}
};
/**
* Scrolls the table vertically to position
*
* @param {number} scrollY
*/
const smartScrollToY = (scrollPos) => {
const { scrollY } = store.getState();
if (scrollPos === scrollY) {
return;
}
const { onVerticalScroll } = getProps();
if (onVerticalScroll ? onVerticalScroll(scrollPos) : true) {
scrollActions.scrollToY(scrollPos);
}
};
return {
scrollToX: smartScrollToX,
scrollToY: smartScrollToY,
stopScroll: scrollActions.scrollEnd,
};
};
export { getScrollActions };