diff --git a/integration-core/uikit-compose-fixtures/src/main/kotlin/com/sdds/compose/uikit/fixtures/stories/bottomsheet/BottomSheetStory.kt b/integration-core/uikit-compose-fixtures/src/main/kotlin/com/sdds/compose/uikit/fixtures/stories/bottomsheet/BottomSheetStory.kt index ee88e7688..aacaadb15 100644 --- a/integration-core/uikit-compose-fixtures/src/main/kotlin/com/sdds/compose/uikit/fixtures/stories/bottomsheet/BottomSheetStory.kt +++ b/integration-core/uikit-compose-fixtures/src/main/kotlin/com/sdds/compose/uikit/fixtures/stories/bottomsheet/BottomSheetStory.kt @@ -247,7 +247,8 @@ private fun Footer( ) { TextField( modifier = Modifier - .fillMaxWidth(), + .fillMaxWidth() + .heightIn(max = 50.dp), value = "", placeholderText = "Для проверки клавиатуры", onValueChange = {}, diff --git a/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/Popover.kt b/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/Popover.kt index 072872356..f1db559ad 100644 --- a/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/Popover.kt +++ b/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/Popover.kt @@ -207,8 +207,6 @@ internal val endAlignmentLine = VerticalAlignmentLine(merger = { old, new -> max * @property size размеры триггера * @property focusScaleFactor на сколько триггер увеличен в фокусе * @property topAlignmentLine верхняя линия выранивания триггера. Рассчитывается относительно [positionInRoot] - * @property bottomAlignmentLine верхняя линия выранивания триггера. Рассчитывается относительно [positionInRoot] - * @property topAlignmentLine верхняя линия выранивания триггера. Рассчитывается относительно [positionInRoot] * @property bottomAlignmentLine нижняя линия выранивания триггера. Рассчитывается относительно [positionInRoot] * @property startAlignmentLine начальная линия выранивания триггера. Рассчитывается относительно [positionInRoot] * @property endAlignmentLine конечная линия выранивания триггера. Рассчитывается относительно [positionInRoot] diff --git a/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/internal/popover/BasePopover.kt b/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/internal/popover/BasePopover.kt index e92fda8de..172efa32e 100644 --- a/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/internal/popover/BasePopover.kt +++ b/sdds-core/uikit-compose/src/main/kotlin/com/sdds/compose/uikit/internal/popover/BasePopover.kt @@ -282,6 +282,7 @@ private fun CacheDrawScope.createTailPath( tailWidthPx: Float, tailHeightPx: Float, tailPaddingPx: Float, + shape: CornerBasedShape, ): Path { val tailPath = Path().apply { addArc( @@ -303,11 +304,11 @@ private fun CacheDrawScope.createTailPath( ) close() } - + val trueSideWidthPx = sideWidthWithoutCorners(placement, shape) val tailTranslationY = - getTailTranslationY(placement, tailAlignment, tailWidthPx, tailPaddingPx) + getTailTranslationY(placement, tailAlignment, tailWidthPx, tailPaddingPx, trueSideWidthPx) val tailTranslationX = - getTailTranslationX(placement, tailAlignment, tailWidthPx, tailPaddingPx) + getTailTranslationX(placement, tailAlignment, tailWidthPx, tailPaddingPx, trueSideWidthPx) val rotation = getTailRotationAngle(placement) val tailMatrix = Matrix().apply { translate(x = tailTranslationX, y = tailTranslationY) @@ -321,12 +322,18 @@ private fun CacheDrawScope.getTailTranslationX( tailAlignment: PopoverAlignment, tailWidthPx: Float, tailPaddingPx: Float, + trueSideWidthPx: Float, ): Float { - val horizontalAlignment = when (tailAlignment) { - PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2 - PopoverAlignment.End -> size.width - tailPaddingPx - tailWidthPx / 2 - PopoverAlignment.Center -> size.width / 2 - } + val horizontalAlignment = + if (canApplyAlignToTail(tailPaddingPx, tailWidthPx, trueSideWidthPx)) { + when (tailAlignment) { + PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2 + PopoverAlignment.End -> size.width - tailPaddingPx - tailWidthPx / 2 + PopoverAlignment.Center -> size.width / 2 + } + } else { + size.width / 2 + } return when (placement) { PopoverPlacement.Start -> size.width PopoverPlacement.End -> 0f @@ -341,11 +348,16 @@ private fun CacheDrawScope.getTailTranslationY( tailAlignment: PopoverAlignment, tailWidthPx: Float, tailPaddingPx: Float, + trueSideWidthPx: Float, ): Float { - val verticalAlignment = when (tailAlignment) { - PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2 - PopoverAlignment.End -> size.height - tailPaddingPx - tailWidthPx / 2 - PopoverAlignment.Center -> size.height / 2 + val verticalAlignment = if (canApplyAlignToTail(tailPaddingPx, tailWidthPx, trueSideWidthPx)) { + when (tailAlignment) { + PopoverAlignment.Start -> tailPaddingPx + tailWidthPx / 2 + PopoverAlignment.End -> size.height - tailPaddingPx - tailWidthPx / 2 + PopoverAlignment.Center -> size.height / 2 + } + } else { + size.height / 2 } return when (placement) { PopoverPlacement.Top -> size.height @@ -356,6 +368,28 @@ private fun CacheDrawScope.getTailTranslationY( } } +private fun CacheDrawScope.sideWidthWithoutCorners( + placement: PopoverPlacement, + shape: CornerBasedShape, +): Float { + val topStart = shape.topStart.toPx(size, this) + val topEnd = shape.topEnd.toPx(size, this) + val bottomStart = shape.bottomStart.toPx(size, this) + val bottomEnd = shape.bottomEnd.toPx(size, this) + return when (placement) { + PopoverPlacement.Start -> size.height - topEnd - bottomEnd + PopoverPlacement.Top -> size.width - bottomStart - bottomEnd + PopoverPlacement.End -> size.height - topStart - bottomStart + PopoverPlacement.Bottom -> size.width - topStart - topEnd + } +} + +private fun canApplyAlignToTail( + tailOffset: Float, + tailWidth: Float, + total: Float, +) = if (tailOffset + tailWidth >= total) false else true + private fun Modifier.drawPopover( shape: CornerBasedShape, backgroundColor: Brush, @@ -382,6 +416,7 @@ private fun Modifier.drawPopover( tailWidthPx = tailWidthPx, tailHeightPx = tailHeightPx, tailPaddingPx = tailPaddingPx, + shape = shape, ) Path().apply { op(backgroundPath, tailPath, PathOperation.Union) } }