Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Feature/panelview space #464

Merged
merged 13 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Campus-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
/* Begin PBXBuildFile section */
100803462764E2C50013ED0E /* ProfileToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 100803452764E2C50013ED0E /* ProfileToolbar.swift */; };
100803482764E37A0013ED0E /* ProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 100803472764E37A0013ED0E /* ProfileView.swift */; };
1F33B2ED282B084100C898E4 /* MockGradesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F33B2EC282B084100C898E4 /* MockGradesViewModel.swift */; };
1F4C836228300306006971C0 /* MapViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F4C836128300306006971C0 /* MapViewModel.swift */; };
1F4C836428300D25006971C0 /* MapViewModel+State.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F4C836328300D25006971C0 /* MapViewModel+State.swift */; };
1F4C836728300E79006971C0 /* CafeteriasService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F4C836628300E79006971C0 /* CafeteriasService.swift */; };
1F4C926F2882FD85003DC7D7 /* RoundedCorners.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F4C926E2882FD84003DC7D7 /* RoundedCorners.swift */; };
1F54244F285CA059008363BC /* token-tutorial.mov in Resources */ = {isa = PBXBuildFile; fileRef = 1F54244E285CA059008363BC /* token-tutorial.mov */; };
1F542450285CA059008363BC /* token-tutorial.mov in Resources */ = {isa = PBXBuildFile; fileRef = 1F54244E285CA059008363BC /* token-tutorial.mov */; };
1F542451285CA059008363BC /* token-tutorial.mov in Resources */ = {isa = PBXBuildFile; fileRef = 1F54244E285CA059008363BC /* token-tutorial.mov */; };
1FAF9F0C284D2ABC000ABE93 /* MapScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FAF9F0B284D2ABC000ABE93 /* MapScreenView.swift */; };
1F33B2ED282B084100C898E4 /* MockGradesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F33B2EC282B084100C898E4 /* MockGradesViewModel.swift */; };
1FBFA168285E5B2D00FC1515 /* PanelContentListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FBFA167285E5B2D00FC1515 /* PanelContentListView.swift */; };
1FBFA168285E5B2D00FC1515 /* PanelContentListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FBFA167285E5B2D00FC1515 /* PanelContentListView.swift */; };
226CB51E2798DF9C0043ABCA /* Snap in Frameworks */ = {isa = PBXBuildFile; productRef = 226CB51D2798DF9C0043ABCA /* Snap */; };
226CB51E2798DF9C0043ABCA /* Snap in Frameworks */ = {isa = PBXBuildFile; productRef = 226CB51D2798DF9C0043ABCA /* Snap */; settings = {ATTRIBUTES = (Required, ); }; };
36108BB627A3046B007DC62D /* LectureDetailsViewModel+State.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108B9E27A3046B007DC62D /* LectureDetailsViewModel+State.swift */; };
Expand Down Expand Up @@ -51,7 +52,6 @@
36108BE927A304B5007DC62D /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BD627A304B5007DC62D /* MenuView.swift */; };
36108BEB27A304B6007DC62D /* CafeteriaRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BD927A304B5007DC62D /* CafeteriaRowView.swift */; };
36108BED27A304B6007DC62D /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BDB27A304B5007DC62D /* MapView.swift */; };
36108BEE27A304B6007DC62D /* PanelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BDC27A304B5007DC62D /* PanelView.swift */; };
36108BEF27A304B6007DC62D /* MapContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BDD27A304B5007DC62D /* MapContentView.swift */; };
36108BF027A304B6007DC62D /* PanelContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BDE27A304B5007DC62D /* PanelContentView.swift */; };
36108BFA27A30517007DC62D /* Movie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36108BF327A30516007DC62D /* Movie.swift */; };
Expand Down Expand Up @@ -231,12 +231,13 @@
/* Begin PBXFileReference section */
100803452764E2C50013ED0E /* ProfileToolbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileToolbar.swift; sourceTree = "<group>"; };
100803472764E37A0013ED0E /* ProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileView.swift; sourceTree = "<group>"; };
1F33B2EC282B084100C898E4 /* MockGradesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockGradesViewModel.swift; sourceTree = "<group>"; };
1F4C836128300306006971C0 /* MapViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewModel.swift; sourceTree = "<group>"; };
1F4C836328300D25006971C0 /* MapViewModel+State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MapViewModel+State.swift"; sourceTree = "<group>"; };
1F4C836628300E79006971C0 /* CafeteriasService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CafeteriasService.swift; sourceTree = "<group>"; };
1F4C926E2882FD84003DC7D7 /* RoundedCorners.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedCorners.swift; sourceTree = "<group>"; };
1F54244E285CA059008363BC /* token-tutorial.mov */ = {isa = PBXFileReference; lastKnownFileType = video.quicktime; path = "token-tutorial.mov"; sourceTree = "<group>"; };
1FAF9F0B284D2ABC000ABE93 /* MapScreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapScreenView.swift; sourceTree = "<group>"; };
1F33B2EC282B084100C898E4 /* MockGradesViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockGradesViewModel.swift; sourceTree = "<group>"; };
1FBFA167285E5B2D00FC1515 /* PanelContentListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanelContentListView.swift; sourceTree = "<group>"; };
227FBB492762AC440062FEC3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
227FBB4A2762AC4C0062FEC3 /* Campus-iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Campus-iOS.entitlements"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -272,7 +273,6 @@
36108BD627A304B5007DC62D /* MenuView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuView.swift; sourceTree = "<group>"; };
36108BD927A304B5007DC62D /* CafeteriaRowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CafeteriaRowView.swift; sourceTree = "<group>"; };
36108BDB27A304B5007DC62D /* MapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = "<group>"; };
36108BDC27A304B5007DC62D /* PanelView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PanelView.swift; sourceTree = "<group>"; };
36108BDD27A304B5007DC62D /* MapContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapContentView.swift; sourceTree = "<group>"; };
36108BDE27A304B5007DC62D /* PanelContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PanelContentView.swift; sourceTree = "<group>"; };
36108BF327A30516007DC62D /* Movie.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Movie.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -611,7 +611,6 @@
36108BD127A304B5007DC62D /* Cafeterias */,
36108BDB27A304B5007DC62D /* MapView.swift */,
1FAF9F0B284D2ABC000ABE93 /* MapScreenView.swift */,
36108BDC27A304B5007DC62D /* PanelView.swift */,
36108BDD27A304B5007DC62D /* MapContentView.swift */,
36108BDE27A304B5007DC62D /* PanelContentView.swift */,
1FBFA167285E5B2D00FC1515 /* PanelContentListView.swift */,
Expand Down Expand Up @@ -788,6 +787,7 @@
children = (
3629BA3027A1D0AD0036AC80 /* ScrollableCardsViewModifier.swift */,
3629BA3227A1E4A90036AC80 /* RoundedCornersShape.swift */,
1F4C926E2882FD84003DC7D7 /* RoundedCorners.swift */,
);
path = Modifiers;
sourceTree = "<group>";
Expand Down Expand Up @@ -1488,7 +1488,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
36108BEE27A304B6007DC62D /* PanelView.swift in Sources */,
36BB6F6227AFCDFA00F224AB /* PersonSearchView.swift in Sources */,
97270F5A27AB2A4900BB25E4 /* Array+Rearrange.swift in Sources */,
3654F38428517260008AD5DC /* StudyRoomVIewModel.swift in Sources */,
Expand All @@ -1504,6 +1503,7 @@
36AF61EE27A2FD7800FEBD98 /* GroupBoxLabelView.swift in Sources */,
36108BFB27A30517007DC62D /* MoviesViewModel.swift in Sources */,
36E964AC277499860055777F /* CalendarDisplayView.swift in Sources */,
1F4C926F2882FD85003DC7D7 /* RoundedCorners.swift in Sources */,
36FAE365277472EF00628799 /* LoginViewModel.swift in Sources */,
36108BE927A304B5007DC62D /* MenuView.swift in Sources */,
36108C1D27A307FA007DC62D /* GradeView.swift in Sources */,
Expand Down
68 changes: 36 additions & 32 deletions Campus-iOS/MapComponent/View/Cafeterias/MealPlanView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,50 @@ struct MealPlanView: View {
@ObservedObject var viewModel: MealPlanViewModel

var body: some View {
HStack{
if viewModel.menus.count > 0 {
VStack{
HStack{
ForEach(viewModel.menus.prefix(7), id: \.id){ menu in
Button(action: {
viewModel.selectedMenu = menu
}){
VStack{
Circle()
.fill(menu === viewModel.selectedMenu ?
(Calendar.current.isDateInToday(menu.date) ? Color("tumBlue") : Color(UIColor.label)) : Color.clear)
.aspectRatio(contentMode: .fit)
.overlay(
Text(getFormattedDate(date: menu.date, format: "d"))
.fontWeight(.semibold).fixedSize()
.foregroundColor(menu === viewModel.selectedMenu ? Color(UIColor.systemBackground) : (Calendar.current.isDateInToday(menu.date) ? Color("tumBlue") : Color(UIColor.label)))
)
.frame(maxWidth: UIScreen.main.bounds.width, maxHeight: 35)
VStack {
HStack{
if viewModel.menus.count > 0 {
VStack{
HStack{
ForEach(viewModel.menus.prefix(7), id: \.id){ menu in
Button(action: {
viewModel.selectedMenu = menu
}){
VStack{
Circle()
.fill(menu === viewModel.selectedMenu ?
(Calendar.current.isDateInToday(menu.date) ? Color("tumBlue") : Color(UIColor.label)) : Color.clear)
.aspectRatio(contentMode: .fit)
.overlay(
Text(getFormattedDate(date: menu.date, format: "d"))
.fontWeight(.semibold).fixedSize()
.foregroundColor(menu === viewModel.selectedMenu ? Color(UIColor.systemBackground) : (Calendar.current.isDateInToday(menu.date) ? Color("tumBlue") : Color(UIColor.label)))
)
.frame(maxWidth: UIScreen.main.bounds.width, maxHeight: 35)

Text(getFormattedDate(date: menu.date, format: "EEE"))
.foregroundColor(Color(UIColor.label))
Text(getFormattedDate(date: menu.date, format: "EEE"))
.foregroundColor(Color(UIColor.label))
}
}
}
}
.padding(.horizontal, 5.0)

if let menu = viewModel.selectedMenu {
MenuView(viewModel: menu)
}else{
Spacer().frame(height: 20)
Text("No Menu available today").foregroundColor(Color.black.opacity(0.5))
}
}
.padding(.horizontal, 5.0)

if let menu = viewModel.selectedMenu {
MenuView(viewModel: menu)
}else{
Spacer().frame(height: 20)
Text("No Menu available today").foregroundColor(Color.black.opacity(0.5))
}
} else {
Text("No Menus available")
}
} else {
Text("No Menus available")
}
.navigationTitle(viewModel.title)
Spacer(minLength: 0.0)
}
.navigationTitle(viewModel.title)

}

func getFormattedDate(date: Date, format: String) -> String{
Expand Down
9 changes: 5 additions & 4 deletions Campus-iOS/MapComponent/View/MapContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ struct MapContentView: UIViewRepresentable {

let newCenter = screenHeight/3

if vm.panelPosition == "mid" || vm.panelPosition == "pushMid"{
if vm.panelPos == .middle {
view.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: newCenter, right: 0)
} else if vm.panelPosition == "down" || vm.panelPosition == "pushDown"{
} else if vm.panelPos == .bottom {
view.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}
Expand Down Expand Up @@ -205,7 +205,8 @@ class MapContentCoordinator: NSObject, MKMapViewDelegate {
control.vm.selectedAnnotationIndex = i
// Making the selected annotation (i.e. cafeteria) the selected cafeteria -> shows the MealPlanView inside the PanelContentView like tapping on a cafeteria in the PanelContentCafeteriasListView
control.vm.selectedCafeteria = control.vm.cafeterias[i]
control.vm.panelPosition = "pushMid"
//control.vm.panelPosition = "pushMid"
control.vm.panelPos = .middle
}
}
}
Expand All @@ -215,7 +216,7 @@ class MapContentCoordinator: NSObject, MKMapViewDelegate {
control.vm.selectedAnnotationIndex = i
// Making the selected annotation (i.e. study group) the selected study group -> shows the StudyRoomGroupView with inside the PanelContentView like tapping on a study group in the PanelContentStudyRoomGroupsListView
control.vm.selectedStudyGroup = groups[i]
control.vm.panelPosition = "pushMid"
control.vm.panelPos = .middle
}
}
}
Expand Down
75 changes: 71 additions & 4 deletions Campus-iOS/MapComponent/View/MapScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct MapScreenView: View {
let screenWidth = UIScreen.main.bounds.width
let screenHeight = UIScreen.main.bounds.width

@State var position = PanelPosition.bottom
@State var panelHeight: CGFloat = 0.0 // Start position of panel is defined in `MapViewModel` with the `panelPos` porperty.

init(vm: MapViewModel) {
self._vm = StateObject(wrappedValue: vm)
Expand All @@ -25,15 +25,82 @@ struct MapScreenView: View {
// -> Here check the status of the fetched cafeterias
ZStack {
MapContentView(vm: self.vm)
PanelView(vm: self.vm)
}.edgesIgnoringSafeArea(.vertical)
VStack{
Spacer()
ZStack {
VStack {
PanelContentView(vm: self.vm)
.background(Color(UIColor.systemBackground))
.cornerRadius(10, corners: [.topRight, .topLeft])
.shadow(radius: 10)
.frame(height: panelHeight, alignment: .bottomTrailing)
.task(id: vm.panelPos) {
if panelHeight != vm.panelPos.rawValue {
withAnimation(.interpolatingSpring(stiffness: 300.0, damping: 30.0, initialVelocity: 10.0)) {
panelHeight = vm.panelPos.rawValue
print(panelHeight)
}
}
}
// .onTapGesture { } /// VERY IMPORTANT: This was added in order to prevent the panel of jumping when scrolling inside the ScrollView; This is probably a bug in SwiftUI since the ScrollView should NOT trigger the gesture-Function (see the print()-Functions)!
}

VStack {
// Spacer()
let dragAreaHeight = PanelHeight.top*0.04
ZStack {
Rectangle()
.foregroundColor(Color(UIColor.systemBackground))
RoundedRectangle(cornerRadius: CGFloat(5.0) / 2.0)
.frame(width: 40, height: CGFloat(5.0))
.foregroundColor(Color.primary.opacity(0.2))
}
.cornerRadius(10, corners: [.topLeft, .topRight])
.frame(height: dragAreaHeight, alignment: .top)
.gesture(
DragGesture()
.onChanged { value in
if let newPanelHeight = check(panelHeight - value.translation.height) {
panelHeight = newPanelHeight
}
}
.onEnded { _ in
withAnimation(.interpolatingSpring(stiffness: 300.0, damping: 30.0, initialVelocity: 10.0)) {
snapPanel(from: panelHeight)
}
}
)
Spacer().frame(height: panelHeight-dragAreaHeight)
}
}
}
}.edgesIgnoringSafeArea(.top)
.navigationTitle("Map")
.navigationBarHidden(true)
}

func check(_ height: CGFloat) -> CGFloat? {
return height <= PanelHeight.top && height >= PanelHeight.bottom ? height : nil
}

func snapPanel(from height: CGFloat) {
print(height)
let snapHeights = [PanelPos.top, PanelPos.kbtop, PanelPos.middle, PanelPos.bottom]

vm.panelPos = closestMatch(values: snapHeights, inputValue: height)
panelHeight = vm.panelPos.rawValue
}

func closestMatch(values: [PanelPos], inputValue: CGFloat) -> PanelPos {
return (values.reduce(values[0]) { abs($0.rawValue-inputValue) < abs($1.rawValue-inputValue) ? $0 : $1 })
}
}

struct MapScreenView_Previews: PreviewProvider {
static var previews: some View {
MapScreenView(vm: MapViewModel(cafeteriaService: CafeteriasService(), studyRoomsService: StudyRoomsService(), mock: true))
TabView {
MapScreenView(vm: MapViewModel(cafeteriaService: CafeteriasService(), studyRoomsService: StudyRoomsService(), mock: true))
}
.preferredColorScheme(.dark)
}
}
Loading