Skip to content

Commit

Permalink
Animation and Spacing Fixes (#317)
Browse files Browse the repository at this point in the history
* Remove extra whitespace between the menu underline and the menu items

* Match horizontal scroll animation duration with the vertical scroll animation time

* Fix bug with extra animation with "Menu" label

* Adjust animation timing

* Adjust delay constant

* Fix spacing and update docstring

* Factor out translate y constant
  • Loading branch information
NgaiJustin authored Nov 14, 2021
1 parent e965f7d commit 7510747
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 47 deletions.
10 changes: 7 additions & 3 deletions Eatery.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
95DA17B225B72203008631BF /* ExpandedMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95DA17B125B72203008631BF /* ExpandedMenu.swift */; };
95DA17B325B72203008631BF /* ExpandedMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95DA17B125B72203008631BF /* ExpandedMenu.swift */; };
95F661FA1E2E9F3D00591A54 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F661F91E2E9F3D00591A54 /* LaunchScreen.storyboard */; };
A27FC025273BBCA900969B34 /* ExpandedMenuHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A27FC024273BBCA900969B34 /* ExpandedMenuHeaderView.swift */; };
BDED220CF98246CF49570C52 /* Pods_Eatery.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 19538C3B4917B0F73E5B6D62 /* Pods_Eatery.framework */; };
C0497B131B64AA1800AC1C6C /* UIColor+ColorScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0497AF11B64AA1800AC1C6C /* UIColor+ColorScheme.swift */; };
C0497B161B64AA1800AC1C6C /* TimeFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0497AF51B64AA1800AC1C6C /* TimeFactory.swift */; };
Expand Down Expand Up @@ -370,6 +371,7 @@
95DA17B125B72203008631BF /* ExpandedMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpandedMenu.swift; sourceTree = "<group>"; };
95F661F91E2E9F3D00591A54 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
977293368558D040AFA7B199 /* Pods-Eatery Watch App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Eatery Watch App.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Eatery Watch App/Pods-Eatery Watch App.debug.xcconfig"; sourceTree = "<group>"; };
A27FC024273BBCA900969B34 /* ExpandedMenuHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpandedMenuHeaderView.swift; sourceTree = "<group>"; };
BD082688B710875CB59FA212 /* Pods-Eatery.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Eatery.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Eatery/Pods-Eatery.debug.xcconfig"; sourceTree = "<group>"; };
C007CABF19E1BEAC00E3BD46 /* Eatery Debug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Eatery Debug.app"; sourceTree = BUILT_PRODUCTS_DIR; };
C0497AF11B64AA1800AC1C6C /* UIColor+ColorScheme.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+ColorScheme.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -735,6 +737,7 @@
95587BB925C3B75C0099D24E /* ExpandedMenus */ = {
isa = PBXGroup;
children = (
A27FC024273BBCA900969B34 /* ExpandedMenuHeaderView.swift */,
95D4858D259D0B0700B312D3 /* ExpandedMenuCategoryView.swift */,
952341BC2565272000674187 /* ExpandedMenuRow.swift */,
95CEB2D72595083F00582E34 /* ExpandedFilterButton.swift */,
Expand Down Expand Up @@ -1504,6 +1507,7 @@
5D94B90B238B27DB0043BE1A /* PopularTimesAccuracyPrompt.swift in Sources */,
5D5B8CC12450F1B2004E05EF /* SearchResultsTableViewCell.swift in Sources */,
D956DCB42187B4B1001BB9B0 /* NetworkManager.swift in Sources */,
A27FC025273BBCA900969B34 /* ExpandedMenuHeaderView.swift in Sources */,
5D6BF06B22126D1700AA36CD /* LookAheadViewController.swift in Sources */,
95DA17B225B72203008631BF /* ExpandedMenu.swift in Sources */,
5DF17737231C5CAE00194D14 /* BRBPrivacyStatementViewController.swift in Sources */,
Expand Down Expand Up @@ -1904,7 +1908,7 @@
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = ZGMCXU7X3U;
DEVELOPMENT_TEAM = N85YZLFRGD;
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
Expand Down Expand Up @@ -2082,7 +2086,7 @@
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = ZGMCXU7X3U;
DEVELOPMENT_TEAM = N85YZLFRGD;
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
Expand Down Expand Up @@ -2167,7 +2171,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = ZGMCXU7X3U;
DEVELOPMENT_TEAM = N85YZLFRGD;
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,16 @@
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "8"
notificationPayloadFile = "Eatery Watch App Extension/PushNotificationPayload.apns">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Eatery">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5D05FF3123C2C14400EF8CC9"
BuildableName = "Eatery Watch App.app"
BlueprintName = "Eatery Watch App"
ReferencedContainer = "container:Eatery.xcodeproj">
</BuildableReference>
</RemoteRunnable>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Debug"
Expand All @@ -77,27 +75,16 @@
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "8"
notificationPayloadFile = "Eatery Watch App Extension/PushNotificationPayload.apns">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Eatery">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5D05FF3123C2C14400EF8CC9"
BuildableName = "Eatery Watch App.app"
BlueprintName = "Eatery Watch App"
ReferencedContainer = "container:Eatery.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5D05FF3123C2C14400EF8CC9"
BuildableName = "Eatery Watch App.app"
BlueprintName = "Eatery Watch App"
ReferencedContainer = "container:Eatery.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
25 changes: 6 additions & 19 deletions Eatery.xcodeproj/xcshareddata/xcschemes/Eatery Watch App.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
notificationPayloadFile = "Eatery Watch App Extension/PushNotificationPayload.apns">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Eatery">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5D05FF3123C2C14400EF8CC9"
BuildableName = "Eatery Watch App.app"
BlueprintName = "Eatery Watch App"
ReferencedContainer = "container:Eatery.xcodeproj">
</BuildableReference>
</RemoteRunnable>
</BuildableProductRunnable>
<LocationScenarioReference
identifier = "New York, NY, USA"
referenceType = "1">
Expand All @@ -78,27 +76,16 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/Eatery">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5D05FF3123C2C14400EF8CC9"
BuildableName = "Eatery Watch App.app"
BlueprintName = "Eatery Watch App"
ReferencedContainer = "container:Eatery.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5D05FF3123C2C14400EF8CC9"
BuildableName = "Eatery Watch App.app"
BlueprintName = "Eatery Watch App"
ReferencedContainer = "container:Eatery.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ScrollableViewController: UIViewController {
tabBar.backgroundColor = .white

tabBar.snp.makeConstraints { make in
make.height.equalTo(40)
make.height.equalTo(30)
}

tabBarStack = UIStackView(arrangedSubviews: [headerContainer, tabBar])
Expand Down Expand Up @@ -130,7 +130,7 @@ class ScrollableViewController: UIViewController {
let viewPos = categoryViews[tabBar.selectedSegmentIndex].frame.minY
let targetPos = viewPos - scrollOffset + viewControllerPosOnParent + minOffset
let topOfSelf = viewControllerPosOnParent - scrollOffset
let duration = animationDuration(from: currentPos, to: targetPos, withConst: 0.03)
let duration = animationDuration(from: currentPos, to: targetPos, withConst: 0.01)

if currentPos > topOfSelf {
UIView.animate(withDuration: duration, delay: 0, options: .curveEaseInOut) {
Expand Down
2 changes: 1 addition & 1 deletion Eatery/Controllers/Eateries/CampusMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class CampusMenuViewController: EateriesMenuViewController {

addToStackView(containerView)

menuLabel.hero.modifiers = createHeroModifiers(.fade, .translate)
menuLabel.hero.modifiers = createHeroModifiers(.fade)
}

private func addTabbedMenuViewController() {
Expand Down
16 changes: 14 additions & 2 deletions Eatery/Controllers/Eateries/EateriesMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class EateriesMenuViewController: ImageParallaxScrollViewController {

}

// Hero animation constants
private let Y_TRANSLATE_OFFSET: CGFloat = 32

private let eatery: Eatery
let userLocation: CLLocation?

Expand Down Expand Up @@ -99,7 +102,8 @@ class EateriesMenuViewController: ImageParallaxScrollViewController {
menuHeaderView.titleHero.id = EateriesViewController.AnimationKey.title.id(eatery: eatery)
menuHeaderView.paymentHero.id = EateriesViewController.AnimationKey.paymentView.id(eatery: eatery)

menuHeaderView.favoriteHero.modifiers = createHeroModifiers(.fade)
// Header hero animation
menuHeaderView.favoriteHero.modifiers = createHeroModifiersWithDelay(delay: 0.05, .fade)

menuHeaderView.exceptionsView.alpha = 0
}
Expand Down Expand Up @@ -140,7 +144,15 @@ class EateriesMenuViewController: ImageParallaxScrollViewController {
func createHeroModifiers(_ groups: HeroModifierGroups...) -> [HeroModifier] {
[.useGlobalCoordinateSpace, .whenPresenting(.delay(0.15))]
+ (groups.contains(.fade) ? [.fade] : [])
+ (groups.contains(.translate) ? [.translate(y: 32), .timingFunction(.deceleration)] : [])
+ (groups.contains(.translate) ? [.translate(y: Y_TRANSLATE_OFFSET), .timingFunction(.deceleration)] : [])
}

// 0.15 is default delay used across all presenting hero animations
/// Creates hero animation modifiers with custom delay—useful when adjusting animation timings
func createHeroModifiersWithDelay(delay: Double = 0.15, _ groups: HeroModifierGroups...) -> [HeroModifier] {
[.useGlobalCoordinateSpace, .whenPresenting(.delay(delay))]
+ (groups.contains(.fade) ? [.fade] : [])
+ (groups.contains(.translate) ? [.translate(y: Y_TRANSLATE_OFFSET), .timingFunction(.deceleration)] : [])
}

// MARK: Actions
Expand Down
6 changes: 6 additions & 0 deletions Eatery/Controllers/Eateries/EateriesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ class EateriesViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
collectionView.reloadData()
// navigationController?.setNavigationBarHidden(false, animated: animated)
}
// override func viewWillDisappear(_ animated: Bool) {
// super.viewWillDisappear(animated)
// print("DEBUG: bye bye")
// navigationController?.setNavigationBarHidden(true, animated: animated)
// }

private func setUpNavigationBar() {
navigationItem.title = "Eateries"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ExpandedMenuHeaderView.swift
// Eatery
//
// Created by Justin Ngai on 10/11/2021.
// Copyright © 2021 Cornell AppDev. All rights reserved.
//

import UIKit
import SnapKit

class ExpandedMenuHeaderView: UIView {

let titleLabel = UILabel()

/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/

}
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 140139abd90d706e363575916285d1606d900221

COCOAPODS: 1.10.2
COCOAPODS: 1.11.2

0 comments on commit 7510747

Please sign in to comment.