Skip to content

Commit

Permalink
Merge pull request #724 from skydoves/fix/width-ratio-compose
Browse files Browse the repository at this point in the history
Fix the widthRatio doesn't calculate properly in Compose
  • Loading branch information
skydoves authored Oct 9, 2024
2 parents 80a2ef4 + a9a41c1 commit fac7dda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,18 @@ public fun Balloon(
.padding(start = paddingStart, end = paddingEnd)
.onGloballyPositioned { coordinates ->
val originalSize = coordinates.size
val calculatedWidth = if (originalSize.width > screenWidth) {
screenWidth
} else {
originalSize.width
}
val calculatedWidth =
if (screenWidth * builder.widthRatio != 0f) {
(
screenWidth * builder.widthRatio -
with(density) { builder.marginRight.dp.toPx() } -
with(density) { builder.marginLeft.dp.toPx() }
).toInt()
} else if (originalSize.width > screenWidth) {
screenWidth
} else {
originalSize.width
}
val size = IntSize(
width = calculatedWidth,
height = coordinates.size.height,
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
agp = "8.7.0"
agp = "8.6.1"
dokka = "1.9.20"
kotlin = "2.0.20"
kotlinBinaryCompatibility = "0.16.3"
Expand Down

0 comments on commit fac7dda

Please sign in to comment.