Skip to content

Commit

Permalink
add sending confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xChqrles committed Jun 13, 2024
1 parent 61b9740 commit 8f494fd
Show file tree
Hide file tree
Showing 17 changed files with 551 additions and 160 deletions.
29 changes: 29 additions & 0 deletions app/App/Components/Avatar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Avatar.swift
// Vault
//
// Created by Charles Lanier on 04/06/2024.
//

import SwiftUI

struct Avatar: View {
var imageData: Data?
var name: String
var size: CGFloat = 42

var body: some View {
if
let imageData = self.imageData,
let uiImage = UIImage(data: imageData) {
Image(uiImage: uiImage)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: size, height: size)
.scaledToFit()
.clipShape(Circle())
} else {
NoAvatar(name: self.name)
}
}
}
91 changes: 91 additions & 0 deletions app/App/Components/Popover.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// Popover.swift
// Vault
//
// Created by Charles Lanier on 04/06/2024.
//

import SwiftUI

struct InnerHeightPreferenceKey: PreferenceKey {

static let defaultValue: CGFloat = .zero

static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}

struct PopoverModifier<PopoverContent>: ViewModifier where PopoverContent : View {

@State private var sheetHeight: CGFloat = .zero

@Binding var isPresented: Bool

var onDismiss: (() -> Void)?
var popoverContent: () -> PopoverContent

func body(content: Content) -> some View {
content
.sheet(isPresented: self.$isPresented) {
VStack {
VStack {
self.popoverContent()
}
.padding(EdgeInsets(top: 44, leading: 20, bottom: 32, trailing: 20))
.frame(maxWidth: .infinity)
.background(.background2)
.clipShape(RoundedRectangle(cornerRadius: 32))
}
.padding(EdgeInsets(top: 0, leading: 16, bottom: 16, trailing: 16))
.overlay {
GeometryReader { geometry in
Color.clear.preference(key: InnerHeightPreferenceKey.self, value: geometry.size.height)
}
}
.onPreferenceChange(InnerHeightPreferenceKey.self) { newHeight in
self.sheetHeight = newHeight
}
.presentationDetents([.height(self.sheetHeight)])
.presentationDragIndicator(.visible)
.presentationBackground(.clear)
}
}
}

extension View {
public func sheetPopover<Content>(
isPresented: Binding<Bool>,
onDismiss: (() -> Void)? = nil,
@ViewBuilder content: @escaping () -> Content
) -> some View where Content : View {
self.modifier(
PopoverModifier(
isPresented: isPresented,
onDismiss: onDismiss,
popoverContent: content
)
)
}
}

#if DEBUG
struct PopoverViewPreviews : PreviewProvider {

@State static var isPresented = true

static var previews: some View {
VStack {
Button("Open popover") {
self.isPresented = true
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.defaultBackground()
.sheetPopover(isPresented: self.$isPresented) {
Text("Holà, I'm the popover")
.textTheme(.headlineMedium)
}
}
}
#endif
74 changes: 58 additions & 16 deletions app/App/Components/SpinnerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,72 @@

import SwiftUI

struct CheckmarkShape: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()

path.move(to: CGPoint(x: rect.minX, y: rect.maxY * 0.5))
path.addLine(to: CGPoint(x: rect.maxX * 0.4, y: rect.maxY))
path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY))

return path
}
}

struct SpinnerView: View {

@State private var spinnerLength = 0.6
@State private var degree:Int = 270
@State private var isSpinning = false
@State private var isTrimming = false

@Binding var isComplete: Bool {
didSet {
self.isTrimming = false
}
}

var body: some View {
Circle()
.trim(from: 0.0,to: spinnerLength)
.stroke(.accent, style: StrokeStyle(lineWidth: 5.0,lineCap: .round,lineJoin:.round))
.rotationEffect(Angle(degrees: Double(degree)))
.frame(width: 48,height: 48)
.onAppear {
withAnimation(Animation.easeIn(duration: 1.5).repeatForever(autoreverses: true)) {
spinnerLength = 0.05
}
withAnimation(Animation.linear(duration: 1).repeatForever(autoreverses: false)) {
degree = 270 + 360
}
ZStack {
VStack {
Circle()
.trim(from: 0.0,to: self.isComplete ? 1 : self.isTrimming ? 0.05 : 0.6)
.stroke(.accent, style: StrokeStyle(lineWidth: 5.0,lineCap: .round,lineJoin:.round))
.frame(width: 48, height: 48)
.animation(.easeIn(duration: 1.5).repeatForever(autoreverses: true), value: self.isTrimming)
.animation(.linear(duration: 0.3), value: self.isComplete)
.onAppear {
self.isTrimming = true
self.isSpinning = true
}
}
.rotationEffect(Angle(degrees: isSpinning ? 360 : 0))
.animation(.linear(duration: 1.0).repeatForever(autoreverses: false), value: isSpinning)

CheckmarkShape()
.trim(from: 0, to: isComplete ? 1 : 0)
.stroke(style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round))
.frame(width: 20, height: 20)
.offset(y: 1)
.foregroundColor(.accent)
.animation(.easeIn(duration: 0.2).delay(0.3), value: isComplete)

}
}
}

#Preview {
ZStack {
SpinnerView()
struct Preview: View {

@State var isComplete = false

var body: some View {
SpinnerView(isComplete: $isComplete)
.background(.background1)
.onTapGesture {
// Simulate the completion of the task
self.isComplete = true
}
}
}

return Preview()
}
3 changes: 1 addition & 2 deletions app/App/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import Starknet

struct Constants {

static let usdcDecimals = 6
static let usdcDecimalPlaces: Double = pow(10, Double(usdcDecimals))
static let usdcDecimals: UInt8 = 6

static let gradient1 = Gradient(colors: [.gradient1A, .gradient1B])
static let linearGradient1 = LinearGradient(
Expand Down
Loading

0 comments on commit 8f494fd

Please sign in to comment.