@@ -47,7 +47,6 @@ import androidx.compose.ui.unit.LayoutDirection
47
47
import androidx.compose.ui.unit.dp
48
48
import androidx.compose.ui.unit.offset
49
49
import androidx.core.view.ViewCompat
50
- import kotlin.math.min
51
50
52
51
/* *
53
52
* Main holder of our inset values.
@@ -382,59 +381,65 @@ private data class InsetsSizeModifier(
382
381
private val heightSide : VerticalSide ? = null ,
383
382
private val additionalHeight : Dp = 0 .dp
384
383
) : LayoutModifier {
385
- private fun targetConstraints (density : Density ): Constraints = with (density) {
386
- val additionalWidthPx = additionalWidth.toIntPx()
387
- val additionalHeightPx = additionalHeight.toIntPx()
388
- Constraints (
389
- minWidth = additionalWidthPx + when (widthSide) {
390
- HorizontalSide .Left -> insets.left
391
- HorizontalSide .Right -> insets.right
392
- null -> 0
393
- },
394
- minHeight = additionalHeightPx + when (heightSide) {
395
- VerticalSide .Top -> insets.top
396
- VerticalSide .Bottom -> insets.bottom
397
- null -> 0
398
- },
399
- maxWidth = when (widthSide) {
400
- HorizontalSide .Left -> insets.left + additionalWidthPx
401
- HorizontalSide .Right -> insets.right + additionalWidthPx
402
- null -> Constraints .Infinity
403
- },
404
- maxHeight = when (heightSide) {
405
- VerticalSide .Top -> insets.top + additionalHeightPx
406
- VerticalSide .Bottom -> insets.bottom + additionalHeightPx
407
- null -> Constraints .Infinity
408
- }
409
- )
410
- }
384
+ private val Density .targetConstraints: Constraints
385
+ get() {
386
+ val additionalWidthPx = additionalWidth.toIntPx()
387
+ val additionalHeightPx = additionalHeight.toIntPx()
388
+ return Constraints (
389
+ minWidth = additionalWidthPx + when (widthSide) {
390
+ HorizontalSide .Left -> insets.left
391
+ HorizontalSide .Right -> insets.right
392
+ null -> 0
393
+ },
394
+ minHeight = additionalHeightPx + when (heightSide) {
395
+ VerticalSide .Top -> insets.top
396
+ VerticalSide .Bottom -> insets.bottom
397
+ null -> 0
398
+ },
399
+ maxWidth = when (widthSide) {
400
+ HorizontalSide .Left -> insets.left + additionalWidthPx
401
+ HorizontalSide .Right -> insets.right + additionalWidthPx
402
+ null -> Constraints .Infinity
403
+ },
404
+ maxHeight = when (heightSide) {
405
+ VerticalSide .Top -> insets.top + additionalHeightPx
406
+ VerticalSide .Bottom -> insets.bottom + additionalHeightPx
407
+ null -> Constraints .Infinity
408
+ }
409
+ )
410
+ }
411
411
412
412
override fun MeasureScope.measure (
413
413
measurable : Measurable ,
414
414
constraints : Constraints
415
415
): MeasureScope .MeasureResult {
416
- val wrappedConstraints = targetConstraints( this ) .let { targetConstraints ->
416
+ val wrappedConstraints = targetConstraints.let { targetConstraints ->
417
417
val resolvedMinWidth = if (widthSide != null ) {
418
418
targetConstraints.minWidth
419
419
} else {
420
- min( constraints.minWidth, targetConstraints.maxWidth)
420
+ constraints.minWidth.coerceAtMost( targetConstraints.maxWidth)
421
421
}
422
422
val resolvedMaxWidth = if (widthSide != null ) {
423
423
targetConstraints.maxWidth
424
424
} else {
425
- min( constraints.maxWidth, targetConstraints.minWidth)
425
+ constraints.maxWidth.coerceAtLeast( targetConstraints.minWidth)
426
426
}
427
427
val resolvedMinHeight = if (heightSide != null ) {
428
428
targetConstraints.minHeight
429
429
} else {
430
- min( constraints.minHeight, targetConstraints.maxHeight)
430
+ constraints.minHeight.coerceAtMost( targetConstraints.maxHeight)
431
431
}
432
432
val resolvedMaxHeight = if (heightSide != null ) {
433
433
targetConstraints.maxHeight
434
434
} else {
435
- min( constraints.maxHeight, targetConstraints.minHeight)
435
+ constraints.maxHeight.coerceAtLeast( targetConstraints.minHeight)
436
436
}
437
- Constraints (resolvedMinWidth, resolvedMaxWidth, resolvedMinHeight, resolvedMaxHeight)
437
+ Constraints (
438
+ resolvedMinWidth,
439
+ resolvedMaxWidth,
440
+ resolvedMinHeight,
441
+ resolvedMaxHeight
442
+ )
438
443
}
439
444
val placeable = measurable.measure(wrappedConstraints)
440
445
return layout(placeable.width, placeable.height) {
@@ -446,31 +451,31 @@ private data class InsetsSizeModifier(
446
451
measurable : IntrinsicMeasurable ,
447
452
height : Int
448
453
) = measurable.minIntrinsicWidth(height).let {
449
- val constraints = targetConstraints( this )
454
+ val constraints = targetConstraints
450
455
it.coerceIn(constraints.minWidth, constraints.maxWidth)
451
456
}
452
457
453
458
override fun IntrinsicMeasureScope.maxIntrinsicWidth (
454
459
measurable : IntrinsicMeasurable ,
455
460
height : Int
456
461
) = measurable.maxIntrinsicWidth(height).let {
457
- val constraints = targetConstraints( this )
462
+ val constraints = targetConstraints
458
463
it.coerceIn(constraints.minWidth, constraints.maxWidth)
459
464
}
460
465
461
466
override fun IntrinsicMeasureScope.minIntrinsicHeight (
462
467
measurable : IntrinsicMeasurable ,
463
468
width : Int
464
469
) = measurable.minIntrinsicHeight(width).let {
465
- val constraints = targetConstraints( this )
470
+ val constraints = targetConstraints
466
471
it.coerceIn(constraints.minHeight, constraints.maxHeight)
467
472
}
468
473
469
474
override fun IntrinsicMeasureScope.maxIntrinsicHeight (
470
475
measurable : IntrinsicMeasurable ,
471
476
width : Int
472
477
) = measurable.maxIntrinsicHeight(width).let {
473
- val constraints = targetConstraints( this )
478
+ val constraints = targetConstraints
474
479
it.coerceIn(constraints.minHeight, constraints.maxHeight)
475
480
}
476
481
}
0 commit comments