Skip to content

Commit ee99421

Browse files
committed
fix: polish hw sheet interactions
1 parent 5d54e52 commit ee99421

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

app/src/main/java/to/bitkit/ui/sheets/hardware/HardwareSheet.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.Manifest
44
import android.bluetooth.BluetoothAdapter
55
import android.content.Intent
66
import android.os.Build
7+
import androidx.activity.compose.BackHandler
78
import androidx.activity.compose.rememberLauncherForActivityResult
89
import androidx.activity.result.contract.ActivityResultContracts
910
import androidx.compose.foundation.layout.Column
@@ -170,6 +171,10 @@ fun HardwareSheet(
170171
}
171172
}
172173

174+
BackHandler {
175+
appViewModel.hideSheet()
176+
}
177+
173178
if (showBlePermissionDialog) {
174179
AppAlertDialog(
175180
title = stringResource(R.string.hardware__bluetooth_permission_title),

app/src/main/java/to/bitkit/ui/sheets/hardware/HwPairPinSheet.kt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.compose.runtime.setValue
2222
import androidx.compose.ui.Alignment
2323
import androidx.compose.ui.Modifier
2424
import androidx.compose.ui.graphics.graphicsLayer
25+
import androidx.compose.ui.platform.LocalDensity
2526
import androidx.compose.ui.platform.testTag
2627
import androidx.compose.ui.res.stringResource
2728
import androidx.compose.ui.tooling.preview.Preview
@@ -42,7 +43,10 @@ import to.bitkit.ui.theme.AppThemeSurface
4243
import to.bitkit.ui.theme.Colors
4344

4445
private const val PAIRING_CODE_LENGTH = 6
46+
private const val PAIRING_CHAR_COLLAPSED_SCALE_X = 0.15f
47+
private const val PAIRING_CHAR_COLLAPSED_SCALE_Y = 0.85f
4548
private val PAIRING_CELL_WIDTH = 32.dp
49+
private val PAIRING_CELL_SPACING = 8.dp
4650

4751
@Composable
4852
fun HwPairCodeSheet(
@@ -123,22 +127,27 @@ private fun PinInput(
123127
animationSpec = tween(durationMillis = 350, easing = FastOutSlowInEasing),
124128
label = "pairCodeSubmit",
125129
)
130+
val cellStepPx = with(LocalDensity.current) {
131+
(PAIRING_CELL_WIDTH + PAIRING_CELL_SPACING).toPx()
132+
}
126133
Box(contentAlignment = Alignment.Center) {
127134
// Fixed-width cells so digits replace dots without the row shifting.
128135
Row(
129-
horizontalArrangement = Arrangement.spacedBy(8.dp),
130-
modifier = Modifier.graphicsLayer {
131-
alpha = 1f - submitProgress
132-
val cellsScale = 1f - 0.08f * submitProgress
133-
scaleX = cellsScale
134-
scaleY = cellsScale
135-
}
136+
horizontalArrangement = Arrangement.spacedBy(PAIRING_CELL_SPACING),
136137
) {
137138
repeat(PAIRING_CODE_LENGTH) { index ->
138139
val digit = code.getOrNull(index)?.toString()
140+
val centerOffset = (PAIRING_CODE_LENGTH - 1) / 2f - index
139141
Box(
140142
contentAlignment = Alignment.Center,
141-
modifier = Modifier.width(PAIRING_CELL_WIDTH)
143+
modifier = Modifier
144+
.width(PAIRING_CELL_WIDTH)
145+
.graphicsLayer {
146+
alpha = 1f - submitProgress
147+
translationX = centerOffset * cellStepPx * submitProgress
148+
scaleX = 1f - (1f - PAIRING_CHAR_COLLAPSED_SCALE_X) * submitProgress
149+
scaleY = 1f - (1f - PAIRING_CHAR_COLLAPSED_SCALE_Y) * submitProgress
150+
}
142151
) {
143152
Display(
144153
text = digit ?: "",

0 commit comments

Comments
 (0)