Skip to content

Commit fac7dda

Browse files
authored
Merge pull request #724 from skydoves/fix/width-ratio-compose
Fix the widthRatio doesn't calculate properly in Compose
2 parents 80a2ef4 + a9a41c1 commit fac7dda

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/Balloon.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,18 @@ public fun Balloon(
132132
.padding(start = paddingStart, end = paddingEnd)
133133
.onGloballyPositioned { coordinates ->
134134
val originalSize = coordinates.size
135-
val calculatedWidth = if (originalSize.width > screenWidth) {
136-
screenWidth
137-
} else {
138-
originalSize.width
139-
}
135+
val calculatedWidth =
136+
if (screenWidth * builder.widthRatio != 0f) {
137+
(
138+
screenWidth * builder.widthRatio -
139+
with(density) { builder.marginRight.dp.toPx() } -
140+
with(density) { builder.marginLeft.dp.toPx() }
141+
).toInt()
142+
} else if (originalSize.width > screenWidth) {
143+
screenWidth
144+
} else {
145+
originalSize.width
146+
}
140147
val size = IntSize(
141148
width = calculatedWidth,
142149
height = coordinates.size.height,

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
agp = "8.7.0"
2+
agp = "8.6.1"
33
dokka = "1.9.20"
44
kotlin = "2.0.20"
55
kotlinBinaryCompatibility = "0.16.3"

0 commit comments

Comments
 (0)