Updated on 2026-08-14
This commit is contained in:
parent
7141c0e6ee
commit
91ec85c3eb
12 changed files with 269 additions and 93 deletions
|
|
@ -3,19 +3,20 @@ package com.tangem.tap.features.tokens.impl.presentation.ui
|
|||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.key
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.tap.features.tokens.impl.presentation.states.NetworkItemState
|
||||
|
|
@ -69,11 +70,21 @@ internal fun BriefNetworksList(
|
|||
*/
|
||||
@Composable
|
||||
internal fun BriefNetworkItem(model: NetworkItemState, modifier: Modifier = Modifier) {
|
||||
val isAdded = model is NetworkItemState.ManageContent && model.isAdded.value
|
||||
Box(modifier = modifier.size(size = TangemTheme.dimens.size20)) {
|
||||
Image(
|
||||
if (!isAdded) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(TangemTheme.dimens.size20)
|
||||
.clip(CircleShape)
|
||||
.background(TangemTheme.colors.control.unchecked),
|
||||
)
|
||||
}
|
||||
Icon(
|
||||
painter = painterResource(id = model.iconResId.value),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(size = TangemTheme.dimens.size20),
|
||||
tint = if (isAdded) Color.Unspecified else TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
|
||||
if (model.isMainNetwork) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.tap.features.tokens.impl.presentation.ui
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
|
|
@ -20,16 +19,15 @@ import androidx.compose.ui.text.style.TextAlign
|
|||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.constraintlayout.compose.ConstraintLayout
|
||||
import androidx.constraintlayout.compose.Dimension
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.palette.graphics.Palette
|
||||
import coil.compose.SubcomposeAsyncImage
|
||||
import coil.request.ImageRequest
|
||||
import com.tangem.core.ui.components.CurrencyPlaceholderIcon
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.utils.ImageBackgroundContrastChecker
|
||||
import com.tangem.tap.common.compose.extensions.toPx
|
||||
import com.tangem.tap.features.tokens.impl.presentation.states.TokenItemState
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -130,6 +128,7 @@ private fun Icon(name: String, iconUrl: String, onContrastCalculate: (Color) ->
|
|||
val iconModifier = modifier.size(size = TangemTheme.dimens.size46)
|
||||
val screenBackgroundColor = TangemTheme.colors.background.primary.toArgb()
|
||||
val isDarkTheme = isSystemInDarkTheme()
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
SubcomposeAsyncImage(
|
||||
modifier = iconModifier,
|
||||
|
|
@ -141,11 +140,13 @@ private fun Icon(name: String, iconUrl: String, onContrastCalculate: (Color) ->
|
|||
.listener(
|
||||
onSuccess = { _, result ->
|
||||
if (isDarkTheme) {
|
||||
setContrastBackgroundIfNeeded(
|
||||
drawable = result.drawable,
|
||||
screenBackgroundColor = screenBackgroundColor,
|
||||
onContrastCalculate = onContrastCalculate,
|
||||
)
|
||||
coroutineScope.launch {
|
||||
val color = ImageBackgroundContrastChecker(
|
||||
drawable = result.drawable,
|
||||
backgroundColor = screenBackgroundColor,
|
||||
).getContrastColorIfNeeded(isDarkTheme)
|
||||
onContrastCalculate(color)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
@ -156,26 +157,6 @@ private fun Icon(name: String, iconUrl: String, onContrastCalculate: (Color) ->
|
|||
)
|
||||
}
|
||||
|
||||
private fun setContrastBackgroundIfNeeded(
|
||||
drawable: Drawable,
|
||||
screenBackgroundColor: Int,
|
||||
onContrastCalculate: (Color) -> Unit,
|
||||
) {
|
||||
Palette.Builder(drawable.toBitmap()).generate { palette ->
|
||||
val color = palette?.getDominantColor(screenBackgroundColor) ?: screenBackgroundColor
|
||||
val contrast = ColorUtils.calculateContrast(color, screenBackgroundColor)
|
||||
val colorToSet = if (contrast > LOW_CONTRAST_RATIO) {
|
||||
Color.Transparent
|
||||
} else {
|
||||
Color.White
|
||||
}
|
||||
onContrastCalculate(colorToSet)
|
||||
}
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
|
||||
private const val LOW_CONTRAST_RATIO = 1.5f
|
||||
|
||||
@Composable
|
||||
private fun Title(title: String, modifier: Modifier = Modifier) {
|
||||
Text(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue