Skip to content
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
4 changes: 4 additions & 0 deletions Uplift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
2EE5F3E42B12EDB6008E0299 /* ApolloAPI in Frameworks */ = {isa = PBXBuildFile; productRef = 2EE5F3E32B12EDB6008E0299 /* ApolloAPI */; };
2EF1A2582B129EEB007A299F /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EF1A2572B129EEB007A299F /* Network.swift */; };
842FB0CCD71C3202DE5836F1 /* Pods_Uplift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E86AC23F1B9AFB11552390BF /* Pods_Uplift.framework */; };
89ECDA892B79885C0006A160 /* StretchyModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89ECDA882B79885C0006A160 /* StretchyModifier.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -145,6 +146,7 @@
2EE5F3C92B12E34D008E0299 /* Apollo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Apollo.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2EF1A2572B129EEB007A299F /* Network.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = "<group>"; };
61B508C772C15943F0FDB2E8 /* Pods-Uplift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Uplift.debug.xcconfig"; path = "Target Support Files/Pods-Uplift/Pods-Uplift.debug.xcconfig"; sourceTree = "<group>"; };
89ECDA882B79885C0006A160 /* StretchyModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StretchyModifier.swift; sourceTree = "<group>"; };
D6EB08EC41E957E55D918532 /* Pods-Uplift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Uplift.release.xcconfig"; path = "Target Support Files/Pods-Uplift/Pods-Uplift.release.xcconfig"; sourceTree = "<group>"; };
E86AC23F1B9AFB11552390BF /* Pods_Uplift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Uplift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -333,6 +335,7 @@
2E6785BD2B3A513000DD3ADA /* SemiCircleShape.swift */,
2E15F5012B396EC500414BEC /* ShadowModifier.swift */,
2E5726C62B4A63AE00D3DB36 /* ShimmerModifier.swift */,
89ECDA882B79885C0006A160 /* StretchyModifier.swift */,
2E15F5112B3A3D0000414BEC /* TriangleShape.swift */,
);
path = Custom;
Expand Down Expand Up @@ -670,6 +673,7 @@
2E090EC52B12EF2600BAE982 /* Publishers.swift in Sources */,
2E39D8222B3B631200AD238B /* DividerLine.swift in Sources */,
2E15F5062B39F81B00414BEC /* MainView.swift in Sources */,
89ECDA892B79885C0006A160 /* StretchyModifier.swift in Sources */,
2E39D82A2B3B9F3D00AD238B /* FacilityExpandedView.swift in Sources */,
2E39D82C2B3BB35000AD238B /* FacilityExpandedViewModel.swift in Sources */,
2E3D6C202B1285D200B51BB2 /* UpliftEnvironment.swift in Sources */,
Expand Down
37 changes: 37 additions & 0 deletions Uplift/Utils/Custom/StretchyModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// StretchyModifier.swift
// Uplift
//
// Created by Caitlyn Jin on 2/11/24.
// Copyright © 2024 Cornell AppDev. All rights reserved.
//

import SwiftUI

/// A view modifier that applies a stretchy effect to the header image.
struct StretchyModifier: ViewModifier {

var geometry: GeometryProxy

func body(content: Content) -> some View {
let minY = geometry.frame(in: .global).minY
let originY = geometry.frame(in: .global).origin.y
let height = geometry.size.height

content
.frame(height: minY > 0 ? height + originY : height)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this logic do? I think that if some vertical delta component is non-negative, we change our height, otherwise we keep it the same. Is the purpose of this for making the header have more "range"/more animated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the content in this case is the image itself, and we are adjusting the height of the image based on the view's frame relative to the whole screen. If we scroll up, the image is lower on the screen, so we increase the height of the image and the .offset modifier sets the image's y-offset so that it stays at the top of the screen. This creates an "animated stretchy" effect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

.clipped()
.offset(y: minY > 0 ? -minY : 0)
}

}

extension View {

@ViewBuilder
func stretchy(_ geometry: GeometryProxy) -> some View {
self
.modifier(StretchyModifier(geometry: geometry))
}

}
18 changes: 10 additions & 8 deletions Uplift/Views/Home/GymDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ struct GymDetailView: View {
@MainActor
private var heroSection: some View {
ZStack(alignment: .center) {
KFImage(gym.imageUrl)
.placeholder {
Constants.Colors.gray01
}
.resizable()
.scaledToFill()
.frame(height: 330)
.clipped()
GeometryReader { geometry in
KFImage(gym.imageUrl)
.placeholder {
Constants.Colors.gray01
}
.resizable()
.aspectRatio(contentMode: .fill)
.stretchy(geometry)
}
.frame(height: 330)

if viewModel.showHours {
hoursView
Expand Down