Updated on 2026-08-14

This commit is contained in:
Tangem 2026-06-26 09:29:36 +02:00
parent 5beda756fa
commit 2a06529480

View file

@ -25,7 +25,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.BiasAlignment import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusManager import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.FocusRequester
@ -201,6 +200,7 @@ private fun DecorationBox(
Field( Field(
state = state, state = state,
innerTextField = innerTextField, innerTextField = innerTextField,
modifier = if (state.query.isEmpty()) Modifier else Modifier.weight(1f),
) )
ClearButton( ClearButton(
state = state, state = state,
@ -217,58 +217,45 @@ private fun DecorationBox(
} }
@Composable @Composable
private fun Field(state: SearchBarUM, innerTextField: @Composable () -> Unit) { private fun Field(state: SearchBarUM, modifier: Modifier = Modifier, innerTextField: @Composable () -> Unit) {
Box( Box(
contentAlignment = Alignment.CenterStart, contentAlignment = Alignment.CenterStart,
modifier = Modifier modifier = modifier
.heightIn(min = TangemTheme.dimens2.x5) .heightIn(min = TangemTheme.dimens2.x5)
.width(IntrinsicSize.Max), .then(if (state.query.isEmpty()) Modifier.width(IntrinsicSize.Max) else Modifier),
) { ) {
innerTextField() innerTextField()
val placeholderOpacity by remember(state.query) { if (state.query.isEmpty()) {
derivedStateOf { Text(
if (state.query.isNotEmpty()) { text = state.placeholderText.resolveReference(),
0f color = TangemTheme.colors2.text.neutral.tertiary,
} else { style = TangemTheme.typography2.bodySemibold16,
1f maxLines = 1,
} overflow = TextOverflow.Ellipsis,
} modifier = Modifier.testTag(SearchBarTestTags.PLACEHOLDER_TEXT),
)
} }
Text(
text = state.placeholderText.resolveReference(),
color = TangemTheme.colors2.text.neutral.tertiary,
style = TangemTheme.typography2.bodySemibold16,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.testTag(SearchBarTestTags.PLACEHOLDER_TEXT)
.alpha(placeholderOpacity),
)
} }
} }
@Composable @Composable
private fun ClearButton(state: SearchBarUM) { private fun ClearButton(state: SearchBarUM) {
if (state.query.isNotEmpty()) { if (state.query.isNotEmpty()) {
Box(modifier = Modifier.fillMaxWidth()) { Icon(
Icon( imageVector = ImageVector.vectorResource(R.drawable.ic_close_new_20),
imageVector = ImageVector.vectorResource(R.drawable.ic_close_new_20), tint = TangemTheme.colors2.graphic.neutral.tertiary,
tint = TangemTheme.colors2.graphic.neutral.tertiary, contentDescription = null,
contentDescription = null, modifier = Modifier
modifier = Modifier .size(TangemTheme.dimens2.x5)
.align(Alignment.CenterEnd) .clip(CircleShape)
.size(TangemTheme.dimens2.x5) .clickable(
.clip(CircleShape) onClick = state.onClearClick,
.clickable( interactionSource = remember { MutableInteractionSource() },
onClick = state.onClearClick, indication = ripple(bounded = false),
interactionSource = remember { MutableInteractionSource() }, )
indication = ripple(bounded = false), .testTag(SearchBarTestTags.CLEAR_BUTTON),
) )
.testTag(SearchBarTestTags.CLEAR_BUTTON),
)
}
} }
} }