Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view: public qrcodeview #83

Merged
merged 1 commit into from
Sep 28, 2023
Merged
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
14 changes: 7 additions & 7 deletions Sources/BitcoinUI/QRCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import CoreImage.CIFilterBuiltins
import SwiftUI

enum QRCodeType {
public enum QRCodeType {
case bitcoin(String)
case lightning(String)

Expand All @@ -22,12 +22,12 @@ enum QRCodeType {
}
}

struct QRCodeView: View {
public struct QRCodeView: View {
@State private var viewState = CGSize.zero
let screenBounds = UIScreen.main.bounds
var qrCodeType: QRCodeType

var body: some View {
public var body: some View {
Image(uiImage: generateQRCode(from: qrCodeType.qrString))
.interpolation(.none)
.resizable()
Expand All @@ -37,7 +37,7 @@ struct QRCodeView: View {
.gesture(dragGesture())
}

private func generateQRCode(from string: String) -> UIImage {
func generateQRCode(from string: String) -> UIImage {
let context = CIContext()
let filter = CIFilter.qrCodeGenerator()
let data = Data(string.utf8)
Expand All @@ -51,20 +51,20 @@ struct QRCodeView: View {
return UIImage(systemName: "xmark.circle") ?? UIImage()
}

private func dragGesture() -> some Gesture {
func dragGesture() -> some Gesture {
DragGesture()
.onChanged(handleDragChanged(_:))
.onEnded(handleDragEnded(_:))
}

private func handleDragChanged(_ value: DragGesture.Value) {
func handleDragChanged(_ value: DragGesture.Value) {
let translation = value.translation
let multiplier: CGFloat = 0.05
viewState.width = -translation.width * multiplier
viewState.height = -translation.height * multiplier
}

private func handleDragEnded(_ value: DragGesture.Value) {
func handleDragEnded(_ value: DragGesture.Value) {
withAnimation {
self.viewState = .zero
}
Expand Down
Loading