Skip to content

Commit

Permalink
Merge pull request #224 from APP-iOS2/refactor/homeView
Browse files Browse the repository at this point in the history
Refactor/homeview 컴포넌트 리팩토링
  • Loading branch information
hyeonghwan authored Jan 15, 2024
2 parents 53e5584 + 3a33ac1 commit c77e10f
Show file tree
Hide file tree
Showing 16 changed files with 345 additions and 503 deletions.
34 changes: 29 additions & 5 deletions Pickle/Pickle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@
967576552B0CDCA4004957AD /* NanumSquareNeoOTF-Rg.otf in Resources */ = {isa = PBXBuildFile; fileRef = 96CF08E52AD9098400648B59 /* NanumSquareNeoOTF-Rg.otf */; };
967576562B0CDCA4004957AD /* NanumSquareNeoOTF-Bd.otf in Resources */ = {isa = PBXBuildFile; fileRef = 96CF08E12AD9098400648B59 /* NanumSquareNeoOTF-Bd.otf */; };
967576572B0CDCA4004957AD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2137D57C2AC1459D00AFE225 /* Assets.xcassets */; };
9688ADDB2B516D3B000F2B3A /* TodoEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9688ADDA2B516D3B000F2B3A /* TodoEmptyView.swift */; };
9688ADDD2B5170E6000F2B3A /* PizzaSliceDescriptionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9688ADDC2B5170E6000F2B3A /* PizzaSliceDescriptionView.swift */; };
968EB22D2AEE63110025BEF8 /* NavigationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 968EB22C2AEE63110025BEF8 /* NavigationStore.swift */; };
96943B262ADFFDED0026D54F /* BackgroundModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96943B252ADFFDED0026D54F /* BackgroundModifier.swift */; };
96A1D4A32ACFD97A003BC207 /* BehaviorMissionRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A1D4A22ACFD97A003BC207 /* BehaviorMissionRepository.swift */; };
Expand Down Expand Up @@ -400,6 +402,8 @@
967575C02B0AB9AF004957AD /* SuccessUpdateKey-PreferenceKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SuccessUpdateKey-PreferenceKey.swift"; sourceTree = "<group>"; };
9675765B2B0CDCA4004957AD /* Pickle-release.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Pickle-release.app"; sourceTree = BUILT_PRODUCTS_DIR; };
9675765C2B0CDCA4004957AD /* Pickle-release-info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Pickle-release-info.plist"; path = "/Users/baghyeonghwan/final/final-pickle/Pickle/Pickle-release-info.plist"; sourceTree = "<absolute>"; };
9688ADDA2B516D3B000F2B3A /* TodoEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoEmptyView.swift; sourceTree = "<group>"; };
9688ADDC2B5170E6000F2B3A /* PizzaSliceDescriptionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PizzaSliceDescriptionView.swift; sourceTree = "<group>"; };
968EB22C2AEE63110025BEF8 /* NavigationStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationStore.swift; sourceTree = "<group>"; };
96943B252ADFFDED0026D54F /* BackgroundModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundModifier.swift; sourceTree = "<group>"; };
96A1D4A22ACFD97A003BC207 /* BehaviorMissionRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BehaviorMissionRepository.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -844,10 +848,6 @@
isa = PBXGroup;
children = (
96C64FE22ADC2C450042204A /* CustomSheetView.swift */,
965C9B992ADA866E0015ABBE /* PizzaSelectedView.swift */,
9619E9382B05921E0028348C /* PizzaItemView.swift */,
21CD68752AD31FC2006DAB62 /* PizzaView.swift */,
2137D5AF2AC176DB00AFE225 /* TodoCellView.swift */,
96CF08ED2AD933A400648B59 /* DotCircleView.swift */,
);
path = Component;
Expand All @@ -857,7 +857,8 @@
isa = PBXGroup;
children = (
2137D5892AC1473C00AFE225 /* HomeView.swift */,
966B031F2B07DEE7009B6293 /* PizzaPagingView.swift */,
9688ADDF2B517541000F2B3A /* Todo */,
9688ADDE2B51753A000F2B3A /* Pizza */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -932,6 +933,27 @@
path = Helper;
sourceTree = "<group>";
};
9688ADDE2B51753A000F2B3A /* Pizza */ = {
isa = PBXGroup;
children = (
966B031F2B07DEE7009B6293 /* PizzaPagingView.swift */,
9688ADDC2B5170E6000F2B3A /* PizzaSliceDescriptionView.swift */,
965C9B992ADA866E0015ABBE /* PizzaSelectedView.swift */,
9619E9382B05921E0028348C /* PizzaItemView.swift */,
21CD68752AD31FC2006DAB62 /* PizzaView.swift */,
);
path = Pizza;
sourceTree = "<group>";
};
9688ADDF2B517541000F2B3A /* Todo */ = {
isa = PBXGroup;
children = (
9688ADDA2B516D3B000F2B3A /* TodoEmptyView.swift */,
2137D5AF2AC176DB00AFE225 /* TodoCellView.swift */,
);
path = Todo;
sourceTree = "<group>";
};
96A1D4A82AD176AD003BC207 /* Key */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1337,6 +1359,7 @@
961488772AFD221200B87A37 /* HomeView-Routing.swift in Sources */,
2137D5932AC1478C00AFE225 /* CalendarView.swift in Sources */,
9619E93C2B0594210028348C /* ScrollEnableKey.swift in Sources */,
9688ADDD2B5170E6000F2B3A /* PizzaSliceDescriptionView.swift in Sources */,
96635F672ADFA0960072F21E /* BehaviorMission-extension.swift in Sources */,
2137D5A42AC14C6A00AFE225 /* CGFloat.swift in Sources */,
B7908DC12AE01BFC004C5221 /* PizzaSummaryView.swift in Sources */,
Expand All @@ -1354,6 +1377,7 @@
961296982AC17120009A9815 /* TextFieldModifier.swift in Sources */,
961488732AFD21D800B87A37 /* ScrollAnchor.swift in Sources */,
21FA267B2AC2ADFB00877122 /* Mission.swift in Sources */,
9688ADDB2B516D3B000F2B3A /* TodoEmptyView.swift in Sources */,
B063F5CE2ADD02DB008EF304 /* HealthKitStore.swift in Sources */,
B729A2492AC3FEB2008FF7C5 /* TaskRowView.swift in Sources */,
96943B262ADFFDED0026D54F /* BackgroundModifier.swift in Sources */,
Expand Down
8 changes: 0 additions & 8 deletions Pickle/Pickle/Screen/App/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ struct ContentView: View {
}
.task { /*await pizzaSetting()*/ } // 피자 첫 실행시 로컬에 저장
.onAppear {

#if DEBUG
print("안녕하세요 Debug 입니다.")
#elseif RELEASE
print("안녕하세요 Release 입니다.")
#else
print("안녕하세요 else 입니다.")
#endif
initUserSetting() // initUserSetting
}
.fullScreenCover(isPresented: $isOnboardingViewActive) {
Expand Down
142 changes: 64 additions & 78 deletions Pickle/Pickle/Screen/Home/HomeView/Component/CustomSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,6 @@

import SwiftUI

enum DragInfo {
case inactive
case active(translation: CGSize)

var translation: CGSize {
switch self {
case .inactive:
return .zero
case .active(let t):
return t
}
}

var isActive: Bool {
switch self {
case .inactive: return false
case .active: return true
}
}
}

struct CustomSheetView<Content: View>: View {

@Environment(\.colorScheme) var colorScheme
Expand All @@ -38,7 +17,6 @@ struct CustomSheetView<Content: View>: View {
@State private var lastOffset: CGFloat = 0

@GestureState private var gestureOffset: CGFloat = 0
@GestureState private var dragInfo = DragInfo.inactive
@State private var yVelocity: Double = 0.0
@State private var previousDragValue: DragGesture.Value?

Expand All @@ -47,23 +25,11 @@ struct CustomSheetView<Content: View>: View {
private let defaultHeight: CGFloat = CGFloat.screenHeight / 3
private let defaultMidHeight: CGFloat = CGFloat.screenHeight / 2 - 80
private let defaultTopHeight: CGFloat = 0

init( content: @escaping () -> Content) {

self.content = content
}

func calcDragVelocity(previousValue: DragGesture.Value, currentValue: DragGesture.Value) -> (Double, Double) {
let timeInterval = currentValue.time.timeIntervalSince(previousValue.time)

let diffXInTimeInterval = Double(currentValue.translation.width - previousValue.translation.width)
let diffYInTimeInterval = Double(currentValue.translation.height - previousValue.translation.height)

let velocityX = diffXInTimeInterval / timeInterval
let velocityY = diffYInTimeInterval / timeInterval
return (velocityX, velocityY)
}

var body: some View {
ZStack {
// For getting height for drag gesture
Expand All @@ -85,55 +51,75 @@ struct CustomSheetView<Content: View>: View {
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
}
}
.offset(y: yOffset_height)
.offset(y: -offset > 0 ? -offset <= (yOffset_height) ? offset : -(yOffset_height) : offset)
.gesture(
DragGesture().updating($gestureOffset, body: { value, state, _ in
// save previous value
DispatchQueue.main.async {
self.previousDragValue = value
}
state = value.translation.height
})
.onChanged { value in
self.offset = gestureOffset + lastOffset
if let previousValue = self.previousDragValue {
// 계산 velocity using currentValue and previousValue
let ( _, yOffset) = self.calcDragVelocity(previousValue: previousValue, currentValue: value)
self.yVelocity = yOffset
.offset(y: yOffset_height)
.offset(y: calaculate(height: yOffset_height))
.gesture(
DragGesture().updating($gestureOffset)
{ value, state, _ in
state = dragGestureBody(value)
}
}
.onEnded { _ in
let maxHeight = yOffset_height
withAnimation {

Log.debug("self.previousDragValue: \(String(describing: self.previousDragValue?.translation))")
Log.debug("yVelocity: \(String(describing: yVelocity)))")
Log.debug("-offset: \(String(describing: -offset)))")
Log.debug("gestureOffset: \(String(describing: gestureOffset)))")

// 탑
if -offset > maxHeight / 2 {
offset = -maxHeight
} else {
// 바텀
if offset > 120 {
withAnimation {
navigationStore.dismiss(home: .isPizzaSeleted(false))
}
}
offset = 0
}
}
// Storing last offset, so that the gesture can continue from the last position
lastOffset = offset
})
.onChanged { value in onChangedOffset(value) }
.onEnded { _ in onEndedOffset(yOffset_height) }
)
)
}
.ignoresSafeArea(.all, edges: .bottom)
}
}

func calaculate(height: CGFloat) -> CGFloat {
-offset > 0 ? -offset <= (height) ? offset : -(height) : offset
}

private func dragGestureBody(_ value: DragGesture.Value) -> CGFloat {
// save previous value
DispatchQueue.main.async {
self.previousDragValue = value
}
return value.translation.height
}

private func onChangedOffset(_ value: GestureStateGesture<DragGesture, CGFloat>.Value) {
self.offset = gestureOffset + lastOffset
if let previousValue = self.previousDragValue {
// 계산 velocity using currentValue and previousValue
let ( _, yOffset) = self.calcDragVelocity(previousValue: previousValue,
currentValue: value)
self.yVelocity = yOffset
}
}

private func onEndedOffset(_ yOffset_height: CGFloat) {
let maxHeight = yOffset_height
withAnimation {
// 탑
if -offset > maxHeight / 2 {
offset = -maxHeight
} else {
// 바텀
if offset > 120 {
withAnimation {
navigationStore.dismiss(home: .isPizzaSeleted(false))
}
}
offset = 0
}
}
// Storing last offset, so that the gesture can continue from the last position
lastOffset = offset
}

func calcDragVelocity(previousValue: DragGesture.Value, currentValue: DragGesture.Value) -> (Double, Double) {
let timeInterval = currentValue.time.timeIntervalSince(previousValue.time)

let diffXInTimeInterval = Double(currentValue.translation.width - previousValue.translation.width)
let diffYInTimeInterval = Double(currentValue.translation.height - previousValue.translation.height)

let velocityX = diffXInTimeInterval / timeInterval
let velocityY = diffYInTimeInterval / timeInterval
return (velocityX, velocityY)
}

// Blur radius for background
func getBlurRadius() -> CGFloat {
let progress = -offset / (UIScreen.main.bounds.height - 100)
Expand All @@ -146,7 +132,7 @@ struct CustomCorner: Shape {
var radius: CGFloat

func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect,
let path = UIBezierPath(roundedRect: rect,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))

Expand Down
Loading

0 comments on commit c77e10f

Please sign in to comment.