Updated on 2026-08-14
This commit is contained in:
parent
85a7e6e1a0
commit
545932dca3
8 changed files with 38 additions and 8 deletions
|
|
@ -28,6 +28,7 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
|
|
@ -63,6 +64,7 @@ fun ExpandableSearchView(
|
|||
onBackClick: () -> Unit,
|
||||
onSearchChange: (String) -> Unit,
|
||||
onSearchDisplayClose: () -> Unit,
|
||||
onFocusChange: (Boolean) -> Unit,
|
||||
title: String? = null,
|
||||
placeholderSearchText: String = "",
|
||||
expandedInitially: Boolean = false,
|
||||
|
|
@ -79,6 +81,7 @@ fun ExpandableSearchView(
|
|||
onSearchChange = onSearchChange,
|
||||
onSearchDisplayClose = onSearchDisplayClose,
|
||||
onExpandedChange = onExpandedChanged,
|
||||
onFocusChange = onFocusChange,
|
||||
tint = tint,
|
||||
)
|
||||
} else {
|
||||
|
|
@ -171,12 +174,14 @@ private fun SubtitleView(subtitle: String, icon: Painter?) {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
@Composable
|
||||
private fun ExpandedSearchView(
|
||||
placeholderSearchText: String,
|
||||
onSearchChange: (String) -> Unit,
|
||||
onSearchDisplayClose: () -> Unit,
|
||||
onExpandedChange: (Boolean) -> Unit,
|
||||
onFocusChange: (Boolean) -> Unit,
|
||||
tint: Color,
|
||||
) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
|
@ -216,7 +221,8 @@ private fun ExpandedSearchView(
|
|||
singleLine = true,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.focusRequester(textFieldFocusRequester),
|
||||
.focusRequester(textFieldFocusRequester)
|
||||
.onFocusChanged { onFocusChange(it.hasFocus) },
|
||||
placeholder = {
|
||||
Text(text = placeholderSearchText)
|
||||
},
|
||||
|
|
@ -245,6 +251,7 @@ private fun CollapsedSearchViewPreview() {
|
|||
placeholderSearchText = "Search",
|
||||
onSearchChange = {},
|
||||
onSearchDisplayClose = {},
|
||||
onFocusChange = {},
|
||||
subtitle = "Ethereum",
|
||||
icon = painterResource(id = R.drawable.img_eth_22),
|
||||
)
|
||||
|
|
@ -262,6 +269,7 @@ private fun ExpandedSearchViewPreview() {
|
|||
onSearchChange = {},
|
||||
expandedInitially = true,
|
||||
onSearchDisplayClose = {},
|
||||
onFocusChange = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ data class SwapStateHolder(
|
|||
val onRefresh: () -> Unit,
|
||||
val onBackClicked: () -> Unit,
|
||||
val onChangeCardsClicked: () -> Unit,
|
||||
val onSearchFocusChange: (Boolean) -> Unit,
|
||||
val onSelectTokenClick: (() -> Unit)? = null,
|
||||
val onSuccess: (() -> Unit)? = null,
|
||||
val onMaxAmountSelected: (() -> Unit)? = null,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tangem.feature.swap.models
|
|||
|
||||
data class UiActions(
|
||||
val onSearchEntered: (String) -> Unit,
|
||||
val onSearchFocusChange: (Boolean) -> Unit,
|
||||
val onTokenSelected: (String) -> Unit,
|
||||
val onAmountChanged: (String) -> Unit,
|
||||
val onAmountSelected: (Boolean) -> Unit,
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ class SwapFragment : Fragment() {
|
|||
if (tokenState != null) {
|
||||
SwapSelectTokenScreen(
|
||||
state = tokenState,
|
||||
onSearchFocusChange = viewModel.uiState.onSearchFocusChange,
|
||||
onBack = viewModel.uiState.onBackClicked,
|
||||
)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import com.tangem.feature.swap.models.UiActions
|
|||
/**
|
||||
* State builder creates a specific states for SwapScreen
|
||||
*/
|
||||
@Suppress("LargeClass")
|
||||
internal class StateBuilder(val actions: UiActions) {
|
||||
|
||||
private val tokensDataConverter = TokensDataConverter(actions.onSearchEntered, actions.onTokenSelected)
|
||||
|
|
@ -60,6 +61,7 @@ internal class StateBuilder(val actions: UiActions) {
|
|||
networkCurrency = networkInfo.blockchainCurrency,
|
||||
swapButton = SwapButton(enabled = false, loading = true, onClick = {}),
|
||||
onRefresh = {},
|
||||
onSearchFocusChange = actions.onSearchFocusChange,
|
||||
onBackClicked = actions.onBackClicked,
|
||||
onChangeCardsClicked = actions.onChangeCardsClicked,
|
||||
onMaxAmountSelected = actions.onMaxAmountSelected,
|
||||
|
|
@ -319,7 +321,13 @@ internal class StateBuilder(val actions: UiActions) {
|
|||
onClick: () -> Unit,
|
||||
): SwapStateHolder {
|
||||
val renewWarnings = uiState.warnings.filterNot { it is SwapWarning.GenericWarning }.toMutableList()
|
||||
renewWarnings.add(SwapWarning.GenericWarning(message, shouldWrapMessage = shouldWrapMessage, onClick = onClick))
|
||||
renewWarnings.add(
|
||||
SwapWarning.GenericWarning(
|
||||
message = message,
|
||||
shouldWrapMessage = shouldWrapMessage,
|
||||
onClick = onClick,
|
||||
),
|
||||
)
|
||||
return uiState.copy(
|
||||
warnings = renewWarnings,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -390,9 +390,12 @@ private val state = SwapStateHolder(
|
|||
warnings = listOf(SwapWarning.PermissionNeeded("DAI")),
|
||||
networkCurrency = "MATIC",
|
||||
swapButton = SwapButton(enabled = true, loading = false, onClick = {}),
|
||||
onRefresh = {}, onBackClicked = {}, onChangeCardsClicked = {},
|
||||
onRefresh = {},
|
||||
onBackClicked = {},
|
||||
onChangeCardsClicked = {},
|
||||
permissionState = SwapPermissionState.InProgress,
|
||||
blockchainId = "POLYGON",
|
||||
onSearchFocusChange = {},
|
||||
// alert = SwapWarning.GenericWarning("There was an error. Please try again.") {},
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,11 @@ import com.tangem.feature.swap.presentation.R
|
|||
import com.valentinilk.shimmer.shimmer
|
||||
|
||||
@Composable
|
||||
fun SwapSelectTokenScreen(state: SwapSelectTokenStateHolder, onBack: () -> Unit) {
|
||||
fun SwapSelectTokenScreen(
|
||||
state: SwapSelectTokenStateHolder,
|
||||
onSearchFocusChange: (Boolean) -> Unit,
|
||||
onBack: () -> Unit,
|
||||
) {
|
||||
TangemTheme {
|
||||
Scaffold(
|
||||
content = { padding ->
|
||||
|
|
@ -57,6 +61,7 @@ fun SwapSelectTokenScreen(state: SwapSelectTokenStateHolder, onBack: () -> Unit)
|
|||
placeholderSearchText = stringResource(id = R.string.search_tokens_title),
|
||||
onSearchChange = state.onSearchEntered,
|
||||
onSearchDisplayClose = { state.onSearchEntered("") },
|
||||
onFocusChange = onSearchFocusChange,
|
||||
subtitle = state.network.name,
|
||||
icon = painterResource(id = getActiveIconRes(state.network.blockchainId)),
|
||||
)
|
||||
|
|
@ -264,6 +269,7 @@ private fun TokenScreenPreview() {
|
|||
onTokenSelected = {},
|
||||
network = Network("Ethereum", "ETH"),
|
||||
),
|
||||
onSearchFocusChange = {},
|
||||
onBack = {},
|
||||
)
|
||||
}
|
||||
|
|
@ -379,10 +379,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
private fun createUiActions(): UiActions {
|
||||
return UiActions(
|
||||
onSearchEntered = { onSearchEntered(it) },
|
||||
onTokenSelected = {
|
||||
onTokenSelect(it)
|
||||
analyticsEventHandler.send(SwapEvents.SearchTokenClicked)
|
||||
},
|
||||
onTokenSelected = { onTokenSelect(it) },
|
||||
onAmountChanged = { onAmountChanged(it) },
|
||||
onSwapClick = {
|
||||
onSwapClick()
|
||||
|
|
@ -414,6 +411,11 @@ internal class SwapViewModel @Inject constructor(
|
|||
analyticsEventHandler.send(SwapEvents.ButtonPermissionCancelClicked)
|
||||
},
|
||||
onAmountSelected = { onAmountSelected(it) },
|
||||
onSearchFocusChange = { focused ->
|
||||
if (focused) {
|
||||
analyticsEventHandler.send(SwapEvents.SearchTokenClicked)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue