Skip to content

Commit

Permalink
Add scrollingResetTimeInterval to WindowScroller
Browse files Browse the repository at this point in the history
  • Loading branch information
code committed Jul 8, 2017
1 parent 0e48370 commit 1a6a835
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/WindowScroller.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This may change with a future release but for the time being this HOC is should
| onResize | Function | | Callback to be invoked on-resize; it is passed the following named parameters: `({ height: number, width: number })`. |
| onScroll | Function | | Callback to be invoked on-scroll; it is passed the following named parameters: `({ scrollTop: number, scrollLeft: number })`. |
| scrollElement | any | | Element to attach scroll event listeners. Defaults to `window`. |
| scrollingResetTimeInterval | Number | | Wait this amount of time after the last scroll event before resetting WindowScroller `pointer-events`; defaults to 150ms. |

### Public Methods

Expand Down
28 changes: 28 additions & 0 deletions source/WindowScroller/WindowScroller.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,34 @@ describe('WindowScroller', () => {

done()
})

it('should support a custom :scrollingResetTimeInterval prop', async (done) => {
const component = render(getMarkup({
scrollingResetTimeInterval: 500
}))

const rendered = findDOMNode(component)

expect(rendered.textContent).toContain('isScrolling:false')

simulateWindowScroll({ scrollY: 5000 })

expect(rendered.textContent).toContain('isScrolling:true')

await new Promise(resolve => setTimeout(resolve, 100))

expect(rendered.textContent).toContain('isScrolling:true')

await new Promise(resolve => setTimeout(resolve, 100))

expect(rendered.textContent).toContain('isScrolling:true')

await new Promise(resolve => setTimeout(resolve, 300))

expect(rendered.textContent).toContain('isScrolling:false')

done()
})
})

describe('onResize', () => {
Expand Down
11 changes: 10 additions & 1 deletion source/WindowScroller/utils/onScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ function enablePointerEventsAfterDelay () {
clearTimeout(disablePointerEventsTimeoutId)
}

var maximumTimeout = IS_SCROLLING_TIMEOUT
mountedInstances.forEach(function (instance) {
if (instance.props.scrollingResetTimeInterval) {
if (instance.props.scrollingResetTimeInterval > maximumTimeout) {
maximumTimeout = instance.props.scrollingResetTimeInterval
}
}
})

disablePointerEventsTimeoutId = setTimeout(
enablePointerEventsAfterDelayCallback,
IS_SCROLLING_TIMEOUT
maximumTimeout
)
}

Expand Down

0 comments on commit 1a6a835

Please sign in to comment.