-
Notifications
You must be signed in to change notification settings - Fork 0
/
FratListRow.swift
81 lines (61 loc) · 2.44 KB
/
FratListRow.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// FratListRow.swift
// Frat Maps
//
// Created by Spencer Byrne on 9/27/22.
//
import Kingfisher
import CoreLocation
import SwiftUI
struct FratListRow: View {
@StateObject var locationManager = newLocationManager()
var frat: Location
@State var showSheet: Bool = false
var body: some View {
var formattedDistance: String?
let locationCoordinate = self.locationManager.location != nil ? self.locationManager.location! : CLLocation()
let fratCoordinate: CLLocation = .init(latitude: frat.latitude, longitude: frat.longitude)
let distanceInMeters = fratCoordinate.distance(from: locationCoordinate)
let distanceInMiles = distanceInMeters/1609.34
let distanceInFeet = distanceInMeters * 3.28084
if distanceInFeet > 1500 {formattedDistance = String(format: "%.2f mi", distanceInMiles)}
else if distanceInFeet < 50 {formattedDistance = "Here"}
else{formattedDistance = String(format: "%.0f ft", distanceInFeet)}
return HStack {
KFImage.url(URL(string: frat.logo))
.resizable()
.frame(width: 75, height: 50)
Text(frat.name)
.font(.headline)
.foregroundColor(.primary)
Spacer()
if formattedDistance != nil{
Text(formattedDistance!)
.font(.subheadline)
.foregroundColor(.primary)
.padding(6)
.background(.thinMaterial)
.cornerRadius(10)
}
else{
ProgressView()
}
}.onTapGesture {
showSheet.toggle()
}
.padding()
.background(.thickMaterial)
.cornerRadius(30)
.halfSheet(showSheet: $showSheet){
FratCombinedView(frat: frat)
.ignoresSafeArea()
}onEnd: {
print("dismissed")
}
}
}
struct FratListRow_Preview: PreviewProvider {
static var previews: some View {
FratListRow(frat: Location(id: "1", name: "TKE", address: "1408 Ronne", latitude: 40.0079023, longitude: -105.2756287, logo: "https://firebasestorage.googleapis.com/v0/b/fratmaps.appspot.com/o/FratLogos%2Ftau-kappa-epsilon2-29.png?alt=media&token=056ea870-a701-4443-b3b6-828756d04b13"))
}
}