Skip to content

Commit

Permalink
[Feat] #122 - 헤더 전환 기능 기기 대응
Browse files Browse the repository at this point in the history
- 각 기기별 화면 크기에 따라 전환 효과가 나타나야할 아이템 개수가 달라지므로 기기 화면 높이와 아이템 높이로 계산하여 전환 효과 조건 지정함
  • Loading branch information
JMM00 authored and yeniful committed Jun 25, 2023
1 parent 398307a commit c48150b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 63 deletions.
4 changes: 0 additions & 4 deletions Halmap.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
F9B3B7B729B842DD00232BB8 /* SongDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9B3B7B629B842DD00232BB8 /* SongDetailView.swift */; };
F9B95BB928F271A100728048 /* DataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9B95BB828F271A100728048 /* DataManager.swift */; };
F9B95BBB28F271B800728048 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9B95BBA28F271B800728048 /* Model.swift */; };
F9DAABB02A4190A4001168A9 /* CustomCorner.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9DAABAF2A4190A4001168A9 /* CustomCorner.swift */; };
F9E4642329E8089A009E12FC /* ScalingHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9E4642229E8089A009E12FC /* ScalingHeaderView.swift */; };
F9EB19C129168E45002DFE46 /* Song.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9EB19BD29168336002DFE46 /* Song.swift */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -111,7 +110,6 @@
F9B3B7B629B842DD00232BB8 /* SongDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongDetailView.swift; sourceTree = "<group>"; };
F9B95BB828F271A100728048 /* DataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataManager.swift; sourceTree = "<group>"; };
F9B95BBA28F271B800728048 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
F9DAABAF2A4190A4001168A9 /* CustomCorner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCorner.swift; sourceTree = "<group>"; };
F9E4642229E8089A009E12FC /* ScalingHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScalingHeaderView.swift; sourceTree = "<group>"; };
F9EB19BD29168336002DFE46 /* Song.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Song.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -229,7 +227,6 @@
87F6ECF0291677AC004533C4 /* Halmap+UIApplication.swift */,
87F6ECF42916B331004533C4 /* Halmap+UINavigationController.swift */,
87F6ECF62916BB44004533C4 /* Halmap+UIView.swift */,
F9DAABAF2A4190A4001168A9 /* CustomCorner.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -408,7 +405,6 @@
A81FFCA728F1B84A00B0FC7C /* Halmap+Color.swift in Sources */,
F98F622929B4C9BD0025F50E /* Themes.swift in Sources */,
20317FB228F2CCBB00A30E09 /* TeamChangingView.swift in Sources */,
F9DAABB02A4190A4001168A9 /* CustomCorner.swift in Sources */,
A81FFC7A28F15D9900B0FC7C /* HalmapApp.swift in Sources */,
F91BE5FD29B18D1E00F7E488 /* MainSongListTabView.swift in Sources */,
F939EBBA29D58FB2005ED8CA /* StorageContentView.swift in Sources */,
Expand Down
17 changes: 0 additions & 17 deletions Halmap/Extensions/CustomCorner.swift

This file was deleted.

104 changes: 62 additions & 42 deletions Halmap/View/ScalingHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import SwiftUI

struct ScalingHeaderView: View {
@EnvironmentObject var dataManager: DataManager
let maxHeight: CGFloat = 216
let maxHeight: CGFloat = UIScreen.getHeight(216)
var topEdge: CGFloat

@State var offset: CGFloat = 0
@State var isShowSheet = false
@State var collectedSongData: CollectedSong?
@State var isDraged = false

@FetchRequest(entity: CollectedSong.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \CollectedSong.date, ascending: true)], predicate: PlayListFilter(filter: "favorite").predicate, animation: .default) private var collectedSongs: FetchedResults<CollectedSong>

Expand All @@ -25,28 +26,43 @@ struct ScalingHeaderView: View {
VStack(spacing: 15) {
GeometryReader { proxy in
VStack(spacing: 0) {
TopBar(topEdge: topEdge, offset: $offset)
topBar
.frame(maxWidth: .infinity)
.frame(height: getHeaderHeight(), alignment: .bottom)
.overlay(
topTitle
.opacity(topTitleOpacity())
.opacity(checkScrollRequirement(listCount: collectedSongs.count) && isDraged ? 1 : 0)
)
HStack() {
Text("\(collectedSongs.count)")
.font(Font.Halmap.CustomCaptionBold)
.foregroundColor(.customDarkGray)
Spacer()
Button {
withAnimation {
isDraged.toggle()
}
} label: {
HStack(spacing: 5) {
Image(systemName: "play.circle.fill")
.foregroundColor(.mainGreen)
.font(.system(size: 20))
Text("전체 재생하기")
.font(Font.Halmap.CustomCaptionBold)
.foregroundColor(.mainGreen)
}
.opacity(checkScrollRequirement(listCount: collectedSongs.count) && isDraged ? 1 : 0)
}
}
.padding(.horizontal, 20)
.padding(.vertical, 17)
.padding(.vertical, UIScreen.getHeight(17))
Divider()
.overlay(Color.customGray.opacity(0.6))
.padding(.horizontal, 20)
}
.background(Color.systemBackground)
}
.frame(height: maxHeight + 48)
.frame(height: maxHeight + UIScreen.getHeight(48))
.offset(y: -offset)
.zIndex(1)

Expand Down Expand Up @@ -125,10 +141,48 @@ struct ScalingHeaderView: View {
}
}
.modifier(OffsetModifier(offset: $offset))
.onChange(of: offset) { _ in
if offset > -UIScreen.getHeight(90) {
withAnimation {
isDraged = false
}
} else if offset < 0 {
withAnimation {
isDraged = true
}
}
}
}
.coordinateSpace(name: "StorageScroll")
.background(Color.systemBackground)

}

var topBar: some View {
ZStack(alignment: .bottom) {
Image("storageTop")
.resizable()
HStack {
Text("보관함")
.font(Font.Halmap.CustomLargeTitle)
Spacer()
Button {
withAnimation {
isDraged.toggle()
}
} label: {
Image(systemName: "play.circle.fill")
.foregroundColor(.mainGreen)
.font(.system(size: 50))
}
}
.padding(EdgeInsets(top: 0, leading: 20, bottom: 20, trailing: 20))
}
.opacity(checkScrollRequirement(listCount: collectedSongs.count) && isDraged ? 0 : 1)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.background(Color.systemBackground)
}

var topTitle: some View {
VStack{
HStack {
Expand All @@ -143,45 +197,11 @@ struct ScalingHeaderView: View {
}

func getHeaderHeight() -> CGFloat {
let topHeight = maxHeight + offset

return topHeight >= (59 + topEdge) ? topHeight : (59 + topEdge)
isDraged ? (59 + topEdge) : maxHeight + offset
}
func topTitleOpacity() -> CGFloat {
let progress = -offset*2 / (maxHeight - (59 + topEdge))
return progress
}
func getOpacity() -> CGFloat {
let progress = -offset*2 / 40
let opacity = 1 - progress
return offset < 0 ? opacity : 1
}
}

struct TopBar: View {

let topEdge: CGFloat
@Binding var offset: CGFloat

var body: some View {
ZStack(alignment: .bottom) {
Image("storageTop")
.resizable()
HStack {
Text("보관함")
.font(Font.Halmap.CustomLargeTitle)
Spacer()
}
.padding(EdgeInsets(top: 0, leading: 20, bottom: 20, trailing: 20))
}
.opacity(getOpacity())
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.background(Color.systemBackground)
}
func getOpacity() -> CGFloat {
let progress = -offset / 40
let opacity = 1 - progress
return offset < 0 ? opacity : 1
func checkScrollRequirement(listCount: Int) -> Bool{
UIScreen.screenHeight - (59 + topEdge) - CGFloat(75 * listCount) <= 0 ? true : false
}
}

Expand Down

0 comments on commit c48150b

Please sign in to comment.