Skip to content

Commit 7afd08c

Browse files
siddh1004Siddharth Agarwal
andauthored
Fix crash when displaying large statin risk percentage text (#5413)
https://app.shortcut.com/simpledotorg/story/15517/fix-crash-when-displaying-large-statin-risk-percentage-text --------- Co-authored-by: Siddharth Agarwal <[email protected]>
1 parent 338336d commit 7afd08c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535

3636
- Display only languages supported by the selected country in the settings screen
3737

38+
### Fixes
39+
40+
- Fix crash when displaying large statin risk percentage text
41+
3842
## 2025.04.07
3943

4044
### Internal

app/src/main/java/org/simple/clinic/summary/compose/StatinNudgeView.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,13 @@ fun RiskText(
157157
val totalTextWidth = textWidth + with(LocalDensity.current) { 8.dp.toPx() * 2 }
158158

159159
val calculatedOffsetX = midpoint - (totalTextWidth / 2)
160-
val clampedOffsetX = calculatedOffsetX.coerceIn(
161-
0f,
162-
parentWidth - totalTextWidth - parentPadding
163-
)
160+
val maxOffsetX = parentWidth - totalTextWidth - parentPadding
161+
val clampedOffsetX = if (maxOffsetX >= 0f) {
162+
calculatedOffsetX.coerceIn(0f, maxOffsetX)
163+
} else {
164+
0f
165+
}
166+
164167

165168
Text(
166169
modifier = Modifier

0 commit comments

Comments
 (0)