()
| 180 | } |
| 181 | |
| 182 | getScrollPosition() { |
| 183 | // Cache scroll position as this causes a forced synchronous layout. |
| 184 | if (typeof this.cachedScrollPosition === 'number') { |
| 185 | return this.cachedScrollPosition; |
| 186 | } |
| 187 | const { scrollParent } = this; |
| 188 | const { axis } = this.props; |
| 189 | const scrollKey = SCROLL_START_KEYS[axis]; |
| 190 | const actual = |
| 191 | scrollParent === window |
| 192 | ? // Firefox always returns document.body[scrollKey] as 0 and Chrome/Safari |
| 193 | // always return document.documentElement[scrollKey] as 0, so take |
| 194 | // whichever has a value. |
| 195 | document.body[scrollKey] || document.documentElement[scrollKey] |
| 196 | : scrollParent[scrollKey]; |
| 197 | const max = |
| 198 | this.getScrollSize() - this.props.scrollParentViewportSizeGetter(this); |
| 199 | const scroll = Math.max(0, Math.min(actual, max)); |
| 200 | const el = this.getEl(); |
| 201 | this.cachedScrollPosition = |
| 202 | this.getOffset(scrollParent) + scroll - this.getOffset(el); |
| 203 | return this.cachedScrollPosition; |
| 204 | } |
| 205 | |
| 206 | setScroll(offset) { |
| 207 | const { scrollParent } = this; |
no test coverage detected