mirror of https://github.com/lukechilds/damus.git
Swift
2 years ago
committed by
William Casarin
7 changed files with 256 additions and 33 deletions
@ -0,0 +1,20 @@ |
|||
// |
|||
// ImageView.swift |
|||
// damus |
|||
// |
|||
// Created by user232838 on 1/5/23. |
|||
// |
|||
|
|||
import SwiftUI |
|||
|
|||
struct ImageView: View { |
|||
var body: some View { |
|||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) |
|||
} |
|||
} |
|||
|
|||
struct ImageView_Previews: PreviewProvider { |
|||
static var previews: some View { |
|||
ImageView() |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
// |
|||
// MagnificationGestureView.swift |
|||
// damus |
|||
// |
|||
// Created by user232838 on 1/5/23. |
|||
// |
|||
|
|||
import SwiftUI |
|||
|
|||
struct MagnificationGestureView: View { |
|||
|
|||
@GestureState var magnifyBy = 1.0 |
|||
|
|||
var magnification: some Gesture { |
|||
MagnificationGesture() |
|||
.updating($magnifyBy) { currentState, gestureState, transaction in |
|||
gestureState = currentState |
|||
} |
|||
} |
|||
|
|||
var body: some View { |
|||
Circle() |
|||
.frame(width: 100, height: 100) |
|||
.scaleEffect(magnifyBy) |
|||
.gesture(magnification) |
|||
} |
|||
} |
|||
|
|||
struct MagnificationGestureView_Previews: PreviewProvider { |
|||
static var previews: some View { |
|||
MagnificationGestureView() |
|||
} |
|||
} |
@ -0,0 +1,95 @@ |
|||
// |
|||
// ProfileZoomView.swift |
|||
// damus |
|||
// |
|||
// Created by scoder1747 on 12/27/22. |
|||
// |
|||
import SwiftUI |
|||
|
|||
struct ProfileZoomView: View { |
|||
|
|||
@Environment(\.presentationMode) var presentationMode |
|||
let pubkey: String |
|||
let profiles: Profiles |
|||
|
|||
@GestureState private var scaleState: CGFloat = 1 |
|||
@GestureState private var offsetState = CGSize.zero |
|||
|
|||
@State private var offset = CGSize.zero |
|||
@State private var scale: CGFloat = 1 |
|||
|
|||
func resetStatus(){ |
|||
self.offset = CGSize.zero |
|||
self.scale = 1 |
|||
} |
|||
|
|||
var zoomGesture: some Gesture { |
|||
MagnificationGesture() |
|||
.updating($scaleState) { currentState, gestureState, _ in |
|||
gestureState = currentState |
|||
} |
|||
.onEnded { value in |
|||
scale *= value |
|||
} |
|||
} |
|||
|
|||
var dragGesture: some Gesture { |
|||
DragGesture() |
|||
.updating($offsetState) { currentState, gestureState, _ in |
|||
gestureState = currentState.translation |
|||
}.onEnded { value in |
|||
offset.height += value.translation.height |
|||
offset.width += value.translation.width |
|||
} |
|||
} |
|||
|
|||
var doubleTapGesture : some Gesture { |
|||
TapGesture(count: 2).onEnded { value in |
|||
resetStatus() |
|||
} |
|||
} |
|||
|
|||
var body: some View { |
|||
ZStack(alignment: .topLeading) { |
|||
Color("DamusDarkGrey") // Or Color("DamusBlack") |
|||
.edgesIgnoringSafeArea(.all) |
|||
|
|||
HStack() { |
|||
Button { |
|||
presentationMode.wrappedValue.dismiss() |
|||
} label: { |
|||
Image(systemName: "xmark") |
|||
.foregroundColor(.white) |
|||
.font(.largeTitle) |
|||
.frame(width: 40, height: 40) |
|||
.padding(20) |
|||
} |
|||
} |
|||
.zIndex(1) |
|||
|
|||
VStack(alignment: .center) { |
|||
Spacer() |
|||
.frame(height: 120) |
|||
|
|||
ProfilePicView(pubkey: pubkey, size: 200.0, highlight: .none, profiles: profiles) |
|||
.padding(100) |
|||
.scaledToFit() |
|||
.scaleEffect(self.scale * scaleState) |
|||
.offset(x: offset.width + offsetState.width, y: offset.height + offsetState.height) |
|||
.gesture(SimultaneousGesture(zoomGesture, dragGesture)) |
|||
.gesture(doubleTapGesture) |
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
struct ProfileZoomView_Previews: PreviewProvider { |
|||
static let pubkey = "ca48854ac6555fed8e439ebb4fa2d928410e0eef13fa41164ec45aaaa132d846" |
|||
|
|||
static var previews: some View { |
|||
ProfileZoomView( |
|||
pubkey: pubkey, |
|||
profiles: make_preview_profiles(pubkey)) |
|||
} |
|||
} |
Loading…
Reference in new issue