-
Notifications
You must be signed in to change notification settings - Fork 0
Implemented stretchy header #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2d3a6f9
Made fitness center images stretchy headers
caitlynjin 1b57c23
Modified gym images as stretchy headers
caitlynjin 18c2f6e
Merge branch 'caitlyn/issues' of github.com:cuappdev/uplift-ios-swift…
caitlynjin 5c3822b
Merge branch 'caitlyn/fix-hours' into caitlyn/stretchy-header
caitlynjin ae2f5f9
Update Package.resolved
caitlynjin c3b3301
Addressed Vin's comments
caitlynjin 5e71ee1
Addressed Vin's comments
caitlynjin 6932478
Create Package.resolved
caitlynjin 0017281
Merge branch 'main' into caitlyn/stretchy-header
caitlynjin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| .clipped() | ||
| .offset(y: minY > 0 ? -minY : 0) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| extension View { | ||
|
|
||
| @ViewBuilder | ||
| func stretchy(_ geometry: GeometryProxy) -> some View { | ||
| self | ||
| .modifier(StretchyModifier(geometry: geometry)) | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the
contentin 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.offsetmodifier sets the image's y-offset so that it stays at the top of the screen. This creates an "animated stretchy" effect.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1