Skip to content

Commit cf9f955

Browse files
committed
Add limit to Proportion.Ratio on PlaceholderManager.kt
1 parent f996062 commit cf9f955

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,12 @@ class PlaceholderManager(
392392
} else {
393393
height.ratio
394394
}
395-
(ratio * calculateWidth(attrs, windowWidth)).toInt()
395+
val result = (ratio * calculateWidth(attrs, windowWidth)).toInt()
396+
if (height.limit != null && height.limit < result) {
397+
height.limit
398+
} else {
399+
result
400+
}
396401
}
397402
}
398403
}
@@ -411,15 +416,20 @@ class PlaceholderManager(
411416
width.ratio > 1.0 -> 1.0f
412417
else -> width.ratio
413418
}
414-
(safeRatio * windowWidth).toInt()
419+
val result = (safeRatio * windowWidth).toInt()
420+
if (width.limit != null && result > width.limit) {
421+
width.limit
422+
} else {
423+
result
424+
}
415425
}
416426
}
417427
}
418428
}
419429

420430
sealed class Proportion {
421-
data class Fixed(val value: Int) : Proportion()
422-
data class Ratio(val ratio: Float) : Proportion()
431+
data class Fixed(val value: Int, val limit: Int? = null) : Proportion()
432+
data class Ratio(val ratio: Float, val limit: Int? = null) : Proportion()
423433
}
424434
}
425435

0 commit comments

Comments
 (0)