Skip to content

Commit

Permalink
fix: ellipsis with maxWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Sep 14, 2023
1 parent 0a25893 commit d38b506
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,15 @@ export default async function* buildTextNodes(
}
flow(r)
measuredTextSize = { width: r, height }
return { width: r, height }
return { width: Math.ceil(r), height }
}

measuredTextSize = { width, height }
return { width, height }
// This may be a temporary fix, I didn't dig deep into yoga.
// But when the return value of width here doesn't change (assuming the value of width is 216.9),
// when we later get the width through `parent.getComputedWidth()`, sometimes it returns 216 and sometimes 217.
// I'm not sure if this is a yoga bug, but it seems related to the entire page width.
// So I use Math.ceil.
return { width: Math.ceil(width), height }
})

const [x, y] = yield
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('Basic', () => {
display: 'flex',
height: '100%',
width: '100%',
background: 'white',
}}
>
Hi {0} <div>hi</div> {0} {false} {undefined} {0} {null} {0} {true} {'x'}{' '}
Expand Down
2 changes: 1 addition & 1 deletion test/event.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Event', () => {
"textContent": "World",
"top": 0,
"type": "div",
"width": 41,
"width": 42,
},
]
`)
Expand Down

0 comments on commit d38b506

Please sign in to comment.