Skip to content

Commit

Permalink
ui: fidgetqrcodeview
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Sep 14, 2023
1 parent a27e71b commit 34c1102
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 3 deletions.
4 changes: 4 additions & 0 deletions LDKNodeMonday.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
AE001CDD29F5EBEC006CA7D1 /* SendConfirmationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE001CDC29F5EBEC006CA7D1 /* SendConfirmationView.swift */; };
AE01C5AD2AB3BC4F00F28C7E /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE01C5AC2AB3BC4F00F28C7E /* View+Extensions.swift */; };
AE0A02242A0AD71900F2479E /* LogView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0A02232A0AD71900F2479E /* LogView.swift */; };
AE17E8DA29A402E30058C9C9 /* LDKNodeMondayApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17E8D929A402E30058C9C9 /* LDKNodeMondayApp.swift */; };
AE17E8DC29A402E30058C9C9 /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE17E8DB29A402E30058C9C9 /* AddressView.swift */; };
Expand Down Expand Up @@ -65,6 +66,7 @@

/* Begin PBXFileReference section */
AE001CDC29F5EBEC006CA7D1 /* SendConfirmationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendConfirmationView.swift; sourceTree = "<group>"; };
AE01C5AC2AB3BC4F00F28C7E /* View+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extensions.swift"; sourceTree = "<group>"; };
AE0A02232A0AD71900F2479E /* LogView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogView.swift; sourceTree = "<group>"; };
AE17E8D629A402E30058C9C9 /* LDKNodeMonday.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LDKNodeMonday.app; sourceTree = BUILT_PRODUCTS_DIR; };
AE17E8D929A402E30058C9C9 /* LDKNodeMondayApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LDKNodeMondayApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -424,6 +426,7 @@
isa = PBXGroup;
children = (
AEE8FDDE29F8579600406DD9 /* Date+Extensions.swift */,
AE01C5AC2AB3BC4F00F28C7E /* View+Extensions.swift */,
AEE8FDDC29F855E700406DD9 /* String+Extensions.swift */,
AE6BB56E2A008CBA009E16E3 /* UInt64+Extensions.swift */,
AE49E84D2A24FDD7002623E8 /* FileManager+Extensions.swift */,
Expand Down Expand Up @@ -535,6 +538,7 @@
AE17E8DC29A402E30058C9C9 /* AddressView.swift in Sources */,
AEBAA48D2A01A93B0042EA82 /* PeerView.swift in Sources */,
AE49E8622A25378C002623E8 /* ReceiveViewModel.swift in Sources */,
AE01C5AD2AB3BC4F00F28C7E /* View+Extensions.swift in Sources */,
AE6BB5712A00947B009E16E3 /* ReceiveView.swift in Sources */,
AE49E8582A2536B4002623E8 /* ChannelsListViewModel.swift in Sources */,
AEE4CD0129ABC0DB00BF1BF9 /* QRCodeViewBitcoin.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions LDKNodeMonday/Bitcoin/View/AddressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ struct AddressView: View {
Spacer()

if viewModel.address != "" {
QRCodeViewBitcoin(address: viewModel.address)
FidgetQRCodeViewBitcoin(address: viewModel.address)
.animation(.default, value: viewModel.address)
} else {
QRCodeViewBitcoin(address: viewModel.address)
FidgetQRCodeViewBitcoin(address: viewModel.address)
.blur(radius: 15)
}

Expand Down
31 changes: 31 additions & 0 deletions LDKNodeMonday/Bitcoin/View/QRCodeViewBitcoin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@ extension QRCodeViewBitcoin {
}
}

struct FidgetQRCodeViewBitcoin: View {
@State private var viewState = CGSize.zero
let screenBounds = UIScreen.main.bounds
var address: String

var body: some View {
QRCodeViewBitcoin(address: address)
.applyFidgetEffect(viewState: $viewState)
.gesture(dragGesture())
}

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

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
}

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

struct QRCodeView_Previews: PreviewProvider {
static var previews: some View {
QRCodeViewBitcoin(address: "tb1qz9hhk2qlsmdanrzgl38uv86hqnqe5vyszrld7s")
Expand Down
20 changes: 20 additions & 0 deletions LDKNodeMonday/Extensions/View+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// View+Extensions.swift
// LDKNodeMonday
//
// Created by Matthew Ramsden on 9/14/23.
//

import Foundation
import SwiftUI

extension View {
func applyFidgetEffect(viewState: Binding<CGSize>) -> some View {
self
.offset(x: -viewState.wrappedValue.width, y: -viewState.wrappedValue.height)
.rotation3DEffect(
.degrees(viewState.wrappedValue.width),
axis: (x: 0, y: 1, z: 0)
)
}
}
31 changes: 31 additions & 0 deletions LDKNodeMonday/Lightning/Receive/View/QRCodeViewLightning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,37 @@ extension QRCodeViewLightning {
}
}

struct FidgetQRCodeViewLightning: View {
@State private var viewState = CGSize.zero
let screenBounds = UIScreen.main.bounds
var invoice: String

var body: some View {
QRCodeViewLightning(invoice: invoice)
.applyFidgetEffect(viewState: $viewState)
.gesture(dragGesture())
}

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

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
}

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

struct QRCodeViewLightning_Previews: PreviewProvider {
static var previews: some View {
QRCodeViewLightning(
Expand Down
2 changes: 1 addition & 1 deletion LDKNodeMonday/Lightning/Receive/View/ReceiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct ReceiveView: View {

if viewModel.invoice != "" {

QRCodeViewLightning(invoice: viewModel.invoice)
FidgetQRCodeViewLightning(invoice: viewModel.invoice)

VStack {

Expand Down

0 comments on commit 34c1102

Please sign in to comment.