Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ suspend fun getData(): Result<Data> = withContext(Dispatchers.IO) {
- ALWAYS use `remember` for expensive Compose computations
- ALWAYS add modifiers to the last place in the argument list when calling composable functions
- NEVER add parameters with default values BEFORE the `modifier` parameter in composable functions - modifier must be the FIRST optional parameter
- ALWAYS use `navController.navigateTo(route)` for simple navigation; NEVER use raw `navController.navigate(route)` — `navigateTo` prevents duplicate destinations
- ALWAYS prefer `VerticalSpacer`, `HorizontalSpacer`, `FillHeight` and `FillWidth` over `Spacer` when applicable
- PREFER declaring small dependant classes, constants, interfaces or top-level functions in the same file with the core class where these are used
- ALWAYS create data classes for state AFTER viewModel class in same file
Expand Down
255 changes: 101 additions & 154 deletions app/src/main/java/to/bitkit/ui/ContentView.kt

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions app/src/main/java/to/bitkit/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,17 @@ private fun OnboardingNav(
composable<StartupRoutes.Terms> {
TermsOfUseScreen(
onNavigateToIntro = {
startupNavController.navigate(StartupRoutes.Intro)
startupNavController.navigateTo(StartupRoutes.Intro)
}
)
}
composableWithDefaultTransitions<StartupRoutes.Intro> {
IntroScreen(
onStartClick = {
startupNavController.navigate(StartupRoutes.Slides())
startupNavController.navigateTo(StartupRoutes.Slides())
},
onSkipClick = {
startupNavController.navigate(StartupRoutes.Slides(StartupRoutes.LAST_SLIDE_INDEX))
startupNavController.navigateTo(StartupRoutes.Slides(StartupRoutes.LAST_SLIDE_INDEX))
},
)
}
Expand All @@ -257,7 +257,7 @@ private fun OnboardingNav(
OnboardingSlidesScreen(
currentTab = route.tab,
isGeoBlocked = isGeoBlocked,
onAdvancedSetupClick = { startupNavController.navigate(StartupRoutes.Advanced) },
onAdvancedSetupClick = { startupNavController.navigateTo(StartupRoutes.Advanced) },
onCreateClick = {
scope.launch {
runCatching {
Expand All @@ -270,7 +270,7 @@ private fun OnboardingNav(
}
},
onRestoreClick = {
startupNavController.navigate(
startupNavController.navigateTo(
StartupRoutes.WarningMultipleDevices
)
},
Expand All @@ -282,7 +282,7 @@ private fun OnboardingNav(
startupNavController.popBackStack()
},
onConfirmClick = {
startupNavController.navigate(StartupRoutes.Restore)
startupNavController.navigateTo(StartupRoutes.Restore)
}
)
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/to/bitkit/ui/NodeInfoScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import to.bitkit.ui.scaffold.AppTopBar
import to.bitkit.ui.scaffold.DrawerNavIcon
import to.bitkit.ui.scaffold.ScreenColumn
import to.bitkit.ui.shared.modifiers.clickableAlpha
import to.bitkit.ui.shared.modifiers.rememberDebouncedClick
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.ui.theme.Shapes
Expand Down Expand Up @@ -438,7 +439,7 @@ private fun PeerCard(
maxLines = 1,
)
}
IconButton(onClick = { onDisconnectPeer(peer.peerDetails) }) {
IconButton(onClick = rememberDebouncedClick { onDisconnectPeer(peer.peerDetails) }) {
Icon(
imageVector = Icons.Default.RemoveCircleOutline,
contentDescription = stringResource(R.string.common__close),
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/java/to/bitkit/ui/components/AuthCheckScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
import androidx.navigation.navOptions
import to.bitkit.ui.Routes
import to.bitkit.ui.appViewModel
import to.bitkit.ui.navigateTo
import to.bitkit.ui.settingsViewModel

@Composable
Expand Down Expand Up @@ -44,10 +44,9 @@ fun AuthCheckScreen(
}

AuthCheckAction.NAV_TO_RESET -> {
navController.navigate(
route = Routes.ResetAndRestoreSettings,
navOptions = navOptions { popUpTo(Routes.BackupSettings) }
)
navController.navigateTo(Routes.ResetAndRestoreSettings) {
popUpTo(Routes.BackupSettings)
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import to.bitkit.ui.shared.modifiers.swipeToHide
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors

@Suppress("CyclomaticComplexMethod")
@Composable
fun BalanceHeaderView(
sats: Long,
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/to/bitkit/ui/components/Button.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import to.bitkit.ui.shared.modifiers.alphaFeedback
import to.bitkit.ui.shared.modifiers.rememberDebouncedClick
import to.bitkit.ui.shared.util.primaryButtonStyle
import to.bitkit.ui.theme.AppButtonDefaults
import to.bitkit.ui.theme.AppThemeSurface
Expand Down Expand Up @@ -70,7 +71,7 @@ fun PrimaryButton(
val buttonShape = MaterialTheme.shapes.large

Button(
onClick = onClick,
onClick = rememberDebouncedClick(onClick = onClick),
enabled = enabled && !isLoading,
colors = AppButtonDefaults.primaryColors.copy(
containerColor = Color.Transparent,
Expand Down Expand Up @@ -139,7 +140,7 @@ fun SecondaryButton(
val contentPadding = PaddingValues(horizontal = size.horizontalPadding.takeIf { text != null } ?: 0.dp)
val border = BorderStroke(2.dp, if (enabled) Colors.Gray4 else Color.Transparent)
OutlinedButton(
onClick = onClick,
onClick = rememberDebouncedClick(onClick = onClick),
enabled = enabled && !isLoading,
colors = AppButtonDefaults.secondaryColors,
contentPadding = contentPadding,
Expand Down Expand Up @@ -197,7 +198,7 @@ fun TertiaryButton(
) {
val contentPadding = PaddingValues(horizontal = size.horizontalPadding.takeIf { text != null } ?: 0.dp)
TextButton(
onClick = onClick,
onClick = rememberDebouncedClick(onClick = onClick),
enabled = enabled && !isLoading,
colors = AppButtonDefaults.tertiaryColors,
contentPadding = contentPadding,
Expand Down
25 changes: 9 additions & 16 deletions app/src/main/java/to/bitkit/ui/components/DrawerMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -25,7 +23,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -45,14 +42,20 @@ import androidx.navigation.compose.rememberNavController
import kotlinx.coroutines.launch
import to.bitkit.R
import to.bitkit.ui.Routes
import to.bitkit.ui.navigateIfNotCurrent
import to.bitkit.ui.navigateTo
import to.bitkit.ui.navigateToHome
import to.bitkit.ui.shared.modifiers.clickableAlpha
import to.bitkit.ui.shared.util.blockPointerInputPassthrough
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.ui.theme.InterFontFamily

private inline fun <reified T : Any> NavController.navigateIfNotCurrent(route: T) {
if (currentBackStackEntry?.destination?.hasRoute<T>() != true) {
navigateTo(route)
}
}

private const val Z_INDEX_SCRIM = 10f
private const val Z_INDEX_MENU = 11f
private val bgScrim = Colors.Black50
Expand Down Expand Up @@ -243,11 +246,7 @@ private fun Scrim(
modifier = Modifier
.fillMaxSize()
.background(bgScrim)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = onClick,
)
.clickableAlpha(pressedAlpha = 1f, onClick = onClick)
)
}
}
Expand All @@ -261,13 +260,7 @@ private fun DrawerItem(
) {
Column(
modifier = modifier
.then(
if (onClick != null) {
Modifier.clickable { onClick() }
} else {
Modifier
}
)
.clickableAlpha(onClick = onClick)
.padding(horizontal = 16.dp)
) {
VerticalSpacer(16.dp)
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/to/bitkit/ui/components/EmptyWalletView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import to.bitkit.R
import to.bitkit.ui.shared.modifiers.rememberDebouncedClick
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.ui.utils.withAccent
Expand Down Expand Up @@ -66,9 +67,7 @@ fun EmptyStateView(
}
if (onClose != null) {
IconButton(
onClick = {
onClose()
},
onClick = rememberDebouncedClick(onClick = onClose),
modifier = Modifier
.size(40.dp)
.align(Alignment.TopEnd)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/to/bitkit/ui/components/Money.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fun MoneyCaptionB(
}
}

@Suppress("CyclomaticComplexMethod")
@Composable
fun rememberMoneyText(
sats: Long,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/to/bitkit/ui/components/NumberPad.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.viewmodels.AmountInputViewModel
import to.bitkit.viewmodels.previewAmountInputViewModel
import kotlin.time.Duration

const val KEY_DELETE = "delete"
const val KEY_000 = "000"
Expand Down Expand Up @@ -228,7 +229,7 @@ fun NumberPadKey(
modifier = modifier
.height(height)
.fillMaxWidth()
.clickableAlpha(ALPHA_PRESSED) {
.clickableAlpha(ALPHA_PRESSED, debounce = Duration.ZERO) {
haptics.performHapticFeedback(haptic)
onClick()
},
Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/to/bitkit/ui/components/QrCodeImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
Expand Down Expand Up @@ -46,6 +45,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import to.bitkit.R
import to.bitkit.ext.setClipboardText
import to.bitkit.ui.shared.modifiers.clickableAlpha
import to.bitkit.ui.theme.AppShapes
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
Expand Down Expand Up @@ -95,12 +95,18 @@ fun QrCodeImage(
contentDescription = content,
contentScale = ContentScale.Inside,
modifier = Modifier
.clickable(enabled = tipMessage.isNotBlank()) {
coroutineScope.launch {
context.setClipboardText(copyContent ?: content)
tooltipState.show()
.clickableAlpha(
onClick = if (tipMessage.isNotBlank()) {
{
coroutineScope.launch {
context.setClipboardText(copyContent ?: content)
tooltipState.show()
}
}
} else {
null
}
}
)
.then(testTag?.let { Modifier.testTag(it) } ?: Modifier)
)
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/to/bitkit/ui/components/RectangleButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import to.bitkit.R
import to.bitkit.ui.shared.modifiers.alphaFeedback
import to.bitkit.ui.shared.modifiers.rememberDebouncedClick
import to.bitkit.ui.theme.AppThemeSurface
import to.bitkit.ui.theme.Colors
import to.bitkit.ui.theme.Shapes
Expand All @@ -45,7 +47,7 @@ fun RectangleButton(
onClick: () -> Unit = {},
) {
Button(
onClick = onClick,
onClick = rememberDebouncedClick(onClick = onClick),
colors = ButtonDefaults.buttonColors(
containerColor = Colors.Gray6,
),
Expand All @@ -54,6 +56,7 @@ fun RectangleButton(
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 0.dp),
modifier = modifier
.alpha(if (enabled) 1f else 0.5f)
.alphaFeedback(enabled = enabled)
.height(80.dp)
.fillMaxWidth()
) {
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/to/bitkit/ui/components/SheetHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -24,6 +23,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import to.bitkit.ui.shared.modifiers.clickableAlpha
import to.bitkit.ui.sheets.BackupRoute
import to.bitkit.ui.sheets.PinRoute
import to.bitkit.ui.sheets.SendRoute
Expand Down Expand Up @@ -136,11 +136,7 @@ private fun Scrim(
modifier = Modifier
.fillMaxSize()
.background(Colors.Black.copy(alpha = scrimAlpha))
.clickable(
interactionSource = null,
indication = null,
onClick = onClick,
)
.clickableAlpha(pressedAlpha = 1f, onClick = onClick)
)
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/to/bitkit/ui/components/SuggestionCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.ui.unit.dp
import to.bitkit.R
import to.bitkit.models.Suggestion
import to.bitkit.ui.shared.modifiers.clickableAlpha
import to.bitkit.ui.shared.modifiers.rememberDebouncedClick
import to.bitkit.ui.shared.util.gradientBackground
import to.bitkit.ui.theme.Colors

Expand Down Expand Up @@ -127,7 +128,7 @@ fun SuggestionCard(

if (onClose != null) {
IconButton(
onClick = onClose,
onClick = rememberDebouncedClick(onClick = onClose),
modifier = Modifier
.size(16.dp)
.testTag("SuggestionDismiss")
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/to/bitkit/ui/components/TabBar.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package to.bitkit.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -83,7 +82,7 @@ fun BoxScope.TabBar(
.weight(1f)
.height(60.dp)
.clip(buttonLeftShape)
.clickable { onSendClick() }
.clickableAlpha(ripple = true) { onSendClick() }
.testTag("Send")
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Expand All @@ -104,7 +103,7 @@ fun BoxScope.TabBar(
.weight(1f)
.height(60.dp)
.clip(buttonRightShape)
.clickable { onReceiveClick() }
.clickableAlpha(ripple = true) { onReceiveClick() }
.testTag("Receive")
) {
Row(verticalAlignment = Alignment.CenterVertically) {
Expand Down Expand Up @@ -179,7 +178,7 @@ fun BoxScope.TabBar(
blendMode = BlendMode.DstIn
)
}
.clickableAlpha { onScanClick() }
.clickableAlpha(ripple = true) { onScanClick() }
.testTag("Scan")
) {
Icon(
Expand Down
Loading
Loading