Updated on 2026-08-14
This commit is contained in:
parent
545932dca3
commit
da4a76eff1
4 changed files with 36 additions and 63 deletions
|
|
@ -9,7 +9,6 @@ import android.content.Context
|
|||
import android.content.ContextWrapper
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -91,12 +90,6 @@ fun Context.dpToPixels(dp: Int): Int =
|
|||
this.resources.displayMetrics,
|
||||
).toInt()
|
||||
|
||||
fun Context.pixelsToDp(pixels: Int): Int {
|
||||
return (pixels.toFloat() /
|
||||
(resources.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT))
|
||||
.toInt()
|
||||
}
|
||||
|
||||
tailrec fun Context?.getActivity(): Activity? = this as? Activity
|
||||
?: (this as? ContextWrapper)?.baseContext?.getActivity()
|
||||
|
||||
|
|
@ -118,7 +111,7 @@ fun MaterialCardView.setMargins(
|
|||
|
||||
fun View.hideKeyboard() {
|
||||
val inputMethodManager =
|
||||
context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
inputMethodManager?.hideSoftInputFromWindow(this.windowToken, 0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,11 @@ import androidx.compose.foundation.layout.BoxScope
|
|||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.tangem.core.ui.components.Keyboard
|
||||
import com.tangem.tangem_sdk_new.extensions.pxToDp
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -22,13 +21,10 @@ fun HangingOverKeyboardView(
|
|||
spaceBetweenKeyboard: Dp = 0.dp,
|
||||
content: @Composable (BoxScope.() -> Unit)
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val padding = when (keyboardState.value) {
|
||||
Keyboard.Closed -> 0.dp
|
||||
is Keyboard.Opened -> {
|
||||
val keyboardHeight = (keyboardState.value as Keyboard.Opened).height
|
||||
val keyboardPadding = context.pxToDp(keyboardHeight.toFloat()).dp
|
||||
keyboardPadding + spaceBetweenKeyboard
|
||||
val padding = remember(keyboardState) {
|
||||
when (val state = keyboardState.value) {
|
||||
is Keyboard.Closed -> 0.dp
|
||||
is Keyboard.Opened -> state.height + spaceBetweenKeyboard
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ import androidx.compose.runtime.remember
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.core.analytics.Analytics
|
||||
import com.tangem.core.ui.components.Keyboard
|
||||
|
|
@ -40,7 +38,6 @@ import com.tangem.tap.common.analytics.events.ManageTokens
|
|||
import com.tangem.tap.common.compose.extensions.addAndNotify
|
||||
import com.tangem.tap.common.compose.extensions.removeAndNotify
|
||||
import com.tangem.tap.common.extensions.dispatchDialogShow
|
||||
import com.tangem.tap.common.extensions.pixelsToDp
|
||||
import com.tangem.tap.common.redux.AppDialog
|
||||
import com.tangem.tap.domain.tokens.Currency
|
||||
import com.tangem.tap.features.tokens.redux.ContractAddress
|
||||
|
|
@ -65,7 +62,7 @@ fun CurrenciesScreen(
|
|||
val addedTokensState = remember { mutableStateOf(tokensState.value.addedTokens) }
|
||||
val addedBlockchainsState = remember { mutableStateOf(tokensState.value.addedBlockchains) }
|
||||
|
||||
val isKeyboardOpen by keyboardAsState()
|
||||
val keyboardState by keyboardAsState()
|
||||
|
||||
val onAddCurrencyToggleClick = { currency: Currency, token: TokenWithBlockchain? ->
|
||||
val blockchain = Blockchain.fromNetworkId(currency.id)
|
||||
|
|
@ -94,7 +91,7 @@ fun CurrenciesScreen(
|
|||
Scaffold(
|
||||
floatingActionButton = {
|
||||
if (tokensState.value.allowToAdd) {
|
||||
SaveChangesButton(isKeyboardOpen) {
|
||||
SaveChangesButton(keyboardState) {
|
||||
onSaveChanges(addedTokensState.value, addedBlockchainsState.value)
|
||||
}
|
||||
}
|
||||
|
|
@ -224,15 +221,9 @@ private fun AnalyticsParam.CurrencyType.sendOff() {
|
|||
|
||||
@Composable
|
||||
fun SaveChangesButton(keyboardState: Keyboard, onSaveChanges: () -> Unit) {
|
||||
val padding = if (keyboardState is Keyboard.Opened) {
|
||||
LocalContext.current.pixelsToDp(keyboardState.height)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
||||
PrimaryButton(
|
||||
modifier = Modifier
|
||||
.padding(bottom = padding.dp)
|
||||
.padding(bottom = keyboardState.height)
|
||||
.padding(horizontal = TangemTheme.dimens.spacing16)
|
||||
.fillMaxWidth(),
|
||||
text = stringResource(id = R.string.common_save_changes),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue