Skip to content

Commit 69b28af

Browse files
janb87jquense
authored andcommitted
fix: issue with gutter width initialization (jquense#1181)
Reproduce the original issue (in Chrome): 1. Directly go to http://intljusticemission.github.io/react-big-calendar/examples/index.html#selectable 2. Notice that you cannot see the day headers because the width of the gutter is set way too big By wrapping it in the requestAnimationFrame it ensures that it is set after the initial paint is finished (which does the css etc).
1 parent c1f017c commit 69b28af

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/TimeGrid.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ export default class TimeGrid extends Component {
9999
window.removeEventListener('resize', this.handleResize)
100100

101101
raf.cancel(this.rafHandle)
102+
103+
if (this.measureGutterAnimationFrameRequest) {
104+
window.cancelAnimationFrame(this.measureGutterAnimationFrameRequest)
105+
}
102106
}
103107

104108
componentDidUpdate() {
@@ -145,7 +149,7 @@ export default class TimeGrid extends Component {
145149
let { min, max, components, accessors, localizer } = this.props
146150

147151
const resources = this.memoizedResources(this.props.resources, accessors)
148-
const groupedEvents = resources.groupEvents(events)
152+
const groupedEvents = resources.groupEvents(events)
149153

150154
return resources.map(([id, resource], i) =>
151155
range.map((date, jj) => {
@@ -277,11 +281,18 @@ export default class TimeGrid extends Component {
277281
}
278282

279283
measureGutter() {
280-
const width = getWidth(this.gutter)
281-
282-
if (width && this.state.gutterWidth !== width) {
283-
this.setState({ gutterWidth: width })
284+
if (this.measureGutterAnimationFrameRequest) {
285+
window.cancelAnimationFrame(this.measureGutterAnimationFrameRequest)
284286
}
287+
this.measureGutterAnimationFrameRequest = window.requestAnimationFrame(
288+
() => {
289+
const width = getWidth(this.gutter)
290+
291+
if (width && this.state.gutterWidth !== width) {
292+
this.setState({ gutterWidth: width })
293+
}
294+
}
295+
)
285296
}
286297

287298
applyScroll() {

0 commit comments

Comments
 (0)