Updated on 2026-08-14
This commit is contained in:
parent
54ab95bb11
commit
9baa0a556b
28 changed files with 691 additions and 50 deletions
|
|
@ -3,6 +3,7 @@ package com.tangem.core.ui.components
|
|||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.PixelFormat
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import androidx.compose.runtime.*
|
||||
|
|
@ -18,7 +19,12 @@ import androidx.savedstate.setViewTreeSavedStateRegistryOwner
|
|||
import java.util.UUID
|
||||
|
||||
@Composable
|
||||
fun FullScreen(notTouchable: Boolean = false, content: @Composable (() -> Unit) -> Unit) {
|
||||
fun FullScreen(
|
||||
notTouchable: Boolean = false,
|
||||
focusable: Boolean = false,
|
||||
onBackClick: () -> Unit = {},
|
||||
content: @Composable (() -> Unit) -> Unit,
|
||||
) {
|
||||
val view = LocalView.current
|
||||
val parentComposition = rememberCompositionContext()
|
||||
val currentContent by rememberUpdatedState(content)
|
||||
|
|
@ -27,7 +33,9 @@ fun FullScreen(notTouchable: Boolean = false, content: @Composable (() -> Unit)
|
|||
val fullScreenLayout = remember {
|
||||
FullScreenLayout(
|
||||
notTouchable = notTouchable,
|
||||
focusable = focusable,
|
||||
composeView = view,
|
||||
onBackClick = onBackClick,
|
||||
uniqueId = id,
|
||||
).apply {
|
||||
setContent(parentComposition) {
|
||||
|
|
@ -45,7 +53,9 @@ fun FullScreen(notTouchable: Boolean = false, content: @Composable (() -> Unit)
|
|||
@SuppressLint("ViewConstructor", "ClickableViewAccessibility")
|
||||
private class FullScreenLayout(
|
||||
private val notTouchable: Boolean,
|
||||
private val focusable: Boolean,
|
||||
private val composeView: View,
|
||||
private val onBackClick: () -> Unit,
|
||||
uniqueId: UUID,
|
||||
) : AbstractComposeView(composeView.context) {
|
||||
|
||||
|
|
@ -97,7 +107,10 @@ private class FullScreenLayout(
|
|||
fun show() {
|
||||
if (viewShowing) dismiss()
|
||||
windowManager.addView(this, params)
|
||||
params.flags = params.flags or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||
|
||||
if (focusable.not()) {
|
||||
params.flags = params.flags or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
|
||||
}
|
||||
|
||||
if (notTouchable) {
|
||||
params.flags = params.flags or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
|
||||
|
|
@ -107,6 +120,19 @@ private class FullScreenLayout(
|
|||
viewShowing = true
|
||||
}
|
||||
|
||||
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
|
||||
if (focusable.not()) {
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
if (event.keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_UP) {
|
||||
onBackClick()
|
||||
return true
|
||||
}
|
||||
|
||||
return super.dispatchKeyEvent(event)
|
||||
}
|
||||
|
||||
fun dismiss() {
|
||||
if (!viewShowing) return
|
||||
disposeComposition()
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ fun PinTextField(
|
|||
isPasswordVisual: Boolean,
|
||||
onValueChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
wrongCode: Boolean = false,
|
||||
) {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val textFieldValue = remember(value) {
|
||||
|
|
@ -71,6 +72,7 @@ fun PinTextField(
|
|||
CellDecoration(
|
||||
length = length,
|
||||
isPasswordVisual = isPasswordVisual,
|
||||
wrongCode = wrongCode,
|
||||
value = value,
|
||||
)
|
||||
},
|
||||
|
|
@ -86,6 +88,7 @@ fun PinTextField(
|
|||
@Composable
|
||||
private fun CellDecoration(
|
||||
length: Int,
|
||||
wrongCode: Boolean,
|
||||
value: String,
|
||||
modifier: Modifier = Modifier,
|
||||
isPasswordVisual: Boolean = false,
|
||||
|
|
@ -128,7 +131,11 @@ private fun CellDecoration(
|
|||
modifier = Modifier.sizeIn(minWidth = width.size.width.dp + 8.dp, minHeight = 48.dp),
|
||||
text = text,
|
||||
style = TangemTheme.typography.h3,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
color = if (wrongCode) {
|
||||
TangemTheme.colors.text.warning
|
||||
} else {
|
||||
TangemTheme.colors.text.primary1
|
||||
},
|
||||
textAlign = TextAlign.Center,
|
||||
lineHeight = 48.sp,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue