Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scrollingResetTimeInterval to WindowScroller #728

Merged
merged 1 commit into from
Jul 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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