Skip to content

Commit 3a90495

Browse files
authored
Merge pull request #34 from shuding/shu/d99c
Fix width rounding issue
2 parents 7ad4c39 + e0b7ca7 commit 3a90495

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
dist
33
.DS_Store
44
.next
5-
.turbo
5+
.turbo
6+
.vscode

src/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ const relayout: RelayoutFn = (id, ratio, wrapper) => {
4040
const height = container.clientHeight
4141

4242
// Synchronously do binary search and calculate the layout
43-
let left: number = width / 2
44-
let right: number = width
43+
let lower: number = width / 2 - 0.25
44+
let upper: number = width + 0.5
4545
let middle: number
4646

4747
if (width) {
48-
while (left + 1 < right) {
49-
middle = ~~((left + right) / 2)
48+
while (lower + 1 < upper) {
49+
middle = Math.round((lower + upper) / 2)
5050
update(middle)
5151
if (container.clientHeight === height) {
52-
right = middle
52+
upper = middle
5353
} else {
54-
left = middle
54+
lower = middle
5555
}
5656
}
5757

5858
// Update the wrapper width
59-
update(right * ratio + width * (1 - ratio))
59+
update(upper * ratio + width * (1 - ratio))
6060
}
6161

6262
// Create a new observer if we don't have one.

0 commit comments

Comments
 (0)