Skip to content

Commit

Permalink
fix: TextField padding between leadingContent and Label/BasicTextField (
Browse files Browse the repository at this point in the history
  • Loading branch information
soulcramer authored Aug 3, 2023
1 parent 35143bd commit f5170e9
Show file tree
Hide file tree
Showing 58 changed files with 108 additions and 136 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.lerp
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import com.adevinta.spark.SparkTheme
Expand Down Expand Up @@ -99,6 +100,8 @@ internal fun SparkDecorationBox(
val contentPadding = OutlinedTextFieldDefaults.contentPadding(
top = VerticalContentPadding,
bottom = VerticalContentPadding,
start = if (leadingIcon != null) 8.dp else 16.dp,
end = if (trailingIcon != null) 8.dp else 16.dp,
)

val isFocused = interactionSource.collectIsFocusedAsState().value
Expand Down Expand Up @@ -201,7 +204,7 @@ internal fun SparkDecorationBox(
Box(
Modifier
.layoutId(ContainerId)
.outlineCutout(labelSize.value, contentPadding),
.outlineCutout(labelSize.value, 16.dp),
propagateMinConstraints = true,
) {
border?.invoke()
Expand Down Expand Up @@ -378,12 +381,12 @@ internal fun SparkTextFieldLayout(
internal fun widthOrZero(placeable: Placeable?) = placeable?.width ?: 0
internal fun heightOrZero(placeable: Placeable?) = placeable?.height ?: 0

internal fun Modifier.outlineCutout(labelSize: Size, paddingValues: PaddingValues) =
internal fun Modifier.outlineCutout(labelSize: Size, leftPadding: Dp) =
this.drawWithContent {
val labelWidth = labelSize.width
if (labelWidth > 0f) {
val innerPadding = OutlinedTextFieldInnerPadding.toPx()
val leftLtr = paddingValues.calculateLeftPadding(layoutDirection).toPx() - innerPadding
val leftLtr = leftPadding.toPx() - innerPadding
val rightLtr = leftLtr + labelWidth + 2 * innerPadding
val left = when (layoutDirection) {
LayoutDirection.Rtl -> size.width - rightLtr
Expand Down Expand Up @@ -520,7 +523,7 @@ private const val PlaceholderAnimationDuration = 83
private const val PlaceholderAnimationDelayOrDuration = 67

internal val CounterPadding = 8.dp
internal val HorizontalIconPadding = 8.dp
internal val HorizontalIconPadding = 16.dp
internal val VerticalContentPadding = 12.dp

internal val IconDefaultSizeModifier = Modifier.defaultMinSize(24.dp, 24.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ private fun Placeable.PlacementScope.place(
val startPadding =
(paddingValues.calculateStartPadding(layoutDirection).value * density).roundToInt()

val iconPadding = HorizontalIconPadding.value * density

// placed center vertically and to the start edge horizontally
leadingPlaceable?.placeRelative(
0,
Expand Down Expand Up @@ -441,7 +439,7 @@ private fun Placeable.PlacementScope.place(
if (leadingPlaceable == null) {
0f
} else {
(widthOrZero(leadingPlaceable) - iconPadding) * (1 - animationProgress)
(widthOrZero(leadingPlaceable) - startPadding) * (1 - animationProgress) + startPadding
}
).roundToInt() + startPadding
it.placeRelative(positionX, positionY.roundToInt())
Expand Down
Loading

0 comments on commit f5170e9

Please sign in to comment.