Skip to content

Commit c9fc08a

Browse files
committed
Team Slide: Consider Text Reflow
Sometimes, team names are wrapped to multiple lines after a layout update, rendering the measurements for our layout moot. Now we run measuring and the layout update in a loop until the changes become negligible.
1 parent 23eb0cf commit c9fc08a

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

assets/js/event_session_teams_slide_hook.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const EventSessionTeamsSlideHook = {
88
},
99

1010
setUpLayout() {
11+
this.zoomFactor = 1;
1112
this.grid = document.getElementById("event-teams-grid");
1213
this.teams = this.grid.querySelectorAll(":scope > div");
13-
this.teamHeights = this.measureHeights(this.teams);
1414
this.isNewSession = this.el.dataset.isNewSession !== undefined;
1515

1616

@@ -25,15 +25,20 @@ const EventSessionTeamsSlideHook = {
2525
},
2626

2727
updateLayout() {
28-
this.setGridZoom(this.cols, this.calcZoomFactor(this.cols))
28+
// we might need multiple passes when reflowed test is split across lines
29+
do {
30+
this.measureHeights();
31+
this.setGridZoom(this.cols, this.calcZoomFactor(this.cols));
32+
var lastZoomFactor = this.zoomFactor;
33+
} while (Math.abs(this.zoomFactor - lastZoomFactor) > .001);
2934
},
3035

3136
measureHeight(el) {
3237
return el.getBoundingClientRect().height;
3338
},
3439

35-
measureHeights(els) {
36-
return Array.from(els).map(el => el.getBoundingClientRect().height)
40+
measureHeights() {
41+
this.teamHeights = Array.from(this.teams).map(el => el.getBoundingClientRect().height / this.zoomFactor)
3742
},
3843

3944
calcZoomFactor(cols) {
@@ -52,6 +57,7 @@ const EventSessionTeamsSlideHook = {
5257
},
5358

5459
setGridZoom(cols, factor) {
60+
this.zoomFactor = factor;
5561
this.grid.style.gridTemplateColumns = `repeat(${cols}, minmax(0, 1fr))`;
5662
for (let el of this.teams) {
5763
el.style.zoom = factor;

0 commit comments

Comments
 (0)