Skip to content

Commit

Permalink
Add swipe to dismiss fullscreen image view
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHearst committed Aug 18, 2022
1 parent ecad02b commit b0a8c31
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
4 changes: 4 additions & 0 deletions MTGWizard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
2A94C9BE287C79E700E25849 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A94C9BD287C79E700E25849 /* SearchView.swift */; };
2A9D3FC1288344DE005228CA /* SettingsTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9D3FC0288344DE005228CA /* SettingsTab.swift */; };
2A9E045028A9EE0400B81AAF /* RulesLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9E044F28A9EE0400B81AAF /* RulesLoader.swift */; };
2A9FE48C28ADD03F00769DAA /* CGPoint+Distance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A9FE48B28ADD03F00769DAA /* CGPoint+Distance.swift */; };
2AA021EE2882419600DDE976 /* ScryfallKit in Frameworks */ = {isa = PBXBuildFile; productRef = 2AA021ED2882419600DDE976 /* ScryfallKit */; };
2AAF8231289063040061243C /* SearchPersistable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AAF8230289063030061243C /* SearchPersistable.swift */; };
2AF0FA7E2883567B00769964 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AF0FA7D2883567B00769964 /* Router.swift */; };
Expand Down Expand Up @@ -138,6 +139,7 @@
2A94C9BD287C79E700E25849 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
2A9D3FC0288344DE005228CA /* SettingsTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsTab.swift; sourceTree = "<group>"; };
2A9E044F28A9EE0400B81AAF /* RulesLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RulesLoader.swift; sourceTree = "<group>"; };
2A9FE48B28ADD03F00769DAA /* CGPoint+Distance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGPoint+Distance.swift"; sourceTree = "<group>"; };
2AAF8230289063030061243C /* SearchPersistable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchPersistable.swift; sourceTree = "<group>"; };
2AF0FA7D2883567B00769964 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
2AF0FA862883729D00769964 /* CardPrintingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPrintingView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -289,6 +291,7 @@
2A2C898F2887153100C428FB /* StringRepresentable.swift */,
2A70406D28A03CDE00E8CE7E /* ObjectList+totalPages.swift */,
2A70406F28A043EE00E8CE7E /* Color+systemBackground.swift */,
2A9FE48B28ADD03F00769DAA /* CGPoint+Distance.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -479,6 +482,7 @@
2A9D3FC1288344DE005228CA /* SettingsTab.swift in Sources */,
062A5D73265F1802009FACCB /* LandingView.swift in Sources */,
06F77C0626E7F6D5005C35C0 /* CardDescription.swift in Sources */,
2A9FE48C28ADD03F00769DAA /* CGPoint+Distance.swift in Sources */,
06F77C1F26E84841005C35C0 /* ManaCostView.swift in Sources */,
2AF0FA7E2883567B00769964 /* Router.swift in Sources */,
2AAF8231289063040061243C /* SearchPersistable.swift in Sources */,
Expand Down
15 changes: 15 additions & 0 deletions MTGWizard/Common/Extensions/CGPoint+Distance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CGPoint+Distance.swift
// MTGWizard
//
// Created by Jacob Hearst on 8/17/22.
//

import Foundation

extension CGPoint {
// sqrt is slow
func distanceSquared(to: CGPoint) -> CGFloat {
return (x - to.x) * (x - to.x) + (y - to.y) * (y - to.y)
}
}
19 changes: 19 additions & 0 deletions MTGWizard/Components/FullScreenImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ScryfallKit

struct FullScreenImageView: View {
@Environment(\.dismiss) var dismiss
@State private var offset: CGSize = .zero

var card: Card
var viewingSecondFace = false
Expand All @@ -27,5 +28,23 @@ struct FullScreenImageView: View {
.padding()
}
}
.offset(offset)
.gesture(drag)
}

var drag: some Gesture {
DragGesture()
.onChanged { value in
offset = value.translation
}
.onEnded { value in
if value.startLocation.distanceSquared(to: value.location) > 110*110 {
dismiss()
} else {
withAnimation {
offset = .zero
}
}
}
}
}
9 changes: 0 additions & 9 deletions MTGWizard/ImageLoader.swift

This file was deleted.

0 comments on commit b0a8c31

Please sign in to comment.