Skip to content

Commit

Permalink
QR code image logic refactor
Browse files Browse the repository at this point in the history
The QR code image logic of the `QrCode` and `Request` screens has been refactored to work upon the newer `ZashiQr` component
  • Loading branch information
HonzaR committed Jan 15, 2025
1 parent db983c6 commit 86b2195
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 219 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this application adheres to [Semantic Versioning](https://semver.org/spec/v2

## [Unreleased]

### Changed
- The QR code image logic of the `QrCode` and `Request` screens has been refactored to work upon the newer `ZashiQr`
component

### Fixed
- The Disconnected popup trigger when the app is backgrounded has been fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package co.electriccoin.zcash.ui.design.component

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
Expand All @@ -26,7 +30,10 @@ fun ZashiQr(
qrData: String,
modifier: Modifier = Modifier,
qrSize: Dp = ZashiQrDefaults.width,
colors: QrCodeColors = QrCodeDefaults.colors()
colors: QrCodeColors = QrCodeDefaults.colors(),
contentDescription: String? = null,
onQrCodeClick: () -> Unit = {},
centerImage: Painter? = null
) {
val qrSizePx = with(LocalDensity.current) { qrSize.roundToPx() }
val bitmap = getQrCode(qrData, qrSizePx, colors)
Expand All @@ -35,15 +42,25 @@ fun ZashiQr(
modifier = modifier,
shape = RoundedCornerShape(ZashiDimensions.Radius.radius4xl),
border = BorderStroke(width = 1.dp, color = ZashiColors.Surfaces.strokePrimary),
color = ZashiColors.Surfaces.bgPrimary
color = ZashiColors.Surfaces.bgPrimary,
) {
Box(
modifier = Modifier.padding(all = 12.dp)
) {
Image(
bitmap = bitmap,
contentDescription = null,
contentDescription = contentDescription,
Modifier.clickable { onQrCodeClick() }
)
if (centerImage != null) {
Image(
modifier = Modifier
.size(64.dp)
.align(Alignment.Center),
painter = centerImage,
contentDescription = contentDescription,
)
}
}
}
}
Expand Down
13 changes: 0 additions & 13 deletions ui-lib/src/main/java/co/electriccoin/zcash/ui/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -541,20 +541,7 @@ fun NavHostController.popBackStackJustOnce(currentRouteToBePopped: String) {
object NavigationArguments {
const val SEND_SCAN_RECIPIENT_ADDRESS = "send_scan_recipient_address"
const val SEND_SCAN_ZIP_321_URI = "send_scan_zip_321_uri"

const val SEND_CONFIRM_RECIPIENT_ADDRESS = "send_confirm_recipient_address"
const val SEND_CONFIRM_AMOUNT = "send_confirm_amount"
const val SEND_CONFIRM_MEMO = "send_confirm_memo"
const val SEND_CONFIRM_PROPOSAL = "send_confirm_proposal"
const val SEND_CONFIRM_INITIAL_STAGE = "send_confirm_initial_stage"

const val MULTIPLE_SUBMISSION_CLEAR_FORM = "multiple_submission_clear_form"

const val PAYMENT_REQUEST_ADDRESS = "payment_request_address"
const val PAYMENT_REQUEST_AMOUNT = "payment_request_amount"
const val PAYMENT_REQUEST_MEMO = "payment_request_memo"
const val PAYMENT_REQUEST_PROPOSAL = "payment_request_proposal"
const val PAYMENT_REQUEST_URI = "payment_request_uri"
}

object NavigationTargets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package co.electriccoin.zcash.ui.screen.exchangerate.widget
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -93,7 +92,6 @@ fun StyledExchangeBalance(
}

@Suppress("LongParameterList", "LongMethod")
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun ExchangeAvailableRateLabelInternal(
style: TextStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package co.electriccoin.zcash.ui.screen.qrcode.model
import androidx.compose.ui.graphics.ImageBitmap
import cash.z.ecc.android.sdk.model.WalletAddress

internal sealed class QrCodeState {
sealed class QrCodeState {
data object Loading : QrCodeState()

data class Prepared(
val qrCodeType: QrCodeType,
val walletAddress: WalletAddress,
val onAddressCopy: (String) -> Unit,
val onQrCodeShare: (ImageBitmap) -> Unit,
val onQrCodeClick: () -> Unit,
val onBack: () -> Unit,
) : QrCodeState()
}
Expand Down
Loading

0 comments on commit 86b2195

Please sign in to comment.