Skip to content

Commit

Permalink
view: public init qrcodeview
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Sep 28, 2023
1 parent 8c2e369 commit 4caac5f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/BitcoinUI/QRCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public enum QRCodeType {
public struct QRCodeView: View {
@State private var viewState = CGSize.zero
let screenBounds = UIScreen.main.bounds
var qrCodeType: QRCodeType
public var qrCodeType: QRCodeType

public init(qrCodeType: QRCodeType) {
self.qrCodeType = qrCodeType
}

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

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

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

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

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

0 comments on commit 4caac5f

Please sign in to comment.