Skip to content

Commit

Permalink
[Feat] Bottom Sheet 위로 슬라이딩 할 떄, InfoDetailView FullCoverPresent - #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin0331 committed Feb 1, 2025
1 parent f8f79bc commit 6eecda1
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct StudyMapFeature {

var isSpecificLocation : Bool = false
var specificLocation : SearchMockData = .init()

var showBottomSheet : Bool = false
}

enum Action : BindableAction {
Expand All @@ -30,6 +32,7 @@ struct StudyMapFeature {
enum ViewTransition {
case onAppear
case goToSearch
case goToInfoDetail
}

enum NetworkReponse {
Expand Down Expand Up @@ -100,7 +103,8 @@ extension StudyMapFeature {
case let .mapProvider(.onMoveToSpecificLocation(location)):
Logger.debug("studyMapFeature onMoveToSpecificLocation \(location) ✅✅✅✅")
state.isSpecificLocation = true
state.specificLocation = location
state.showBottomSheet = true
state.specificLocation = location

default:
break
Expand Down
29 changes: 26 additions & 3 deletions Whidy-iOS/Presentation/Main/StudyMap/View/Info/InfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,33 @@ import SwiftUI

struct InfoView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
ScrollView {
GeometryReader { geometry in
Color.clear
.preference(key: ScrollOffsetPreferenceKey.self, value: geometry.frame(in: .global).minY)
}
.frame(height: 0)

VStack {
Text("hi")
Text("hi")
Text("hi")
Text("hi")
Text("hi")
}
}
.padding(.top, 30)
.cornerRadius(17)
.background(Color.white)
}
}

#Preview {
InfoView()
struct ScrollOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = 0

static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value += nextValue()

Logger.debug(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension SearchView {
)
}
}
}.opacity(store.isHideLatestSearch ? 0 : 1)
}.opacity(store.isHideLatestSearch || store.isSearchSuccess ? 0 : 1)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import ComposableArchitecture
struct StudyMapView: View {
@Perception.Bindable var store: StoreOf<StudyMapFeature>
@State var text = ""
@State private var dragOffset: CGFloat = 0
@State private var currentOffset: CGFloat = 0
@State private var isBottomSheetFull : Bool = false

var body: some View {
WithPerceptionTracking {
Expand All @@ -33,7 +36,55 @@ struct StudyMapView: View {
}
.onAppear {
store.send(.viewTransition(.onAppear))
dragOffset = SheetHeight.bottom
currentOffset = SheetHeight.bottom
}
.overlay {
if store.showBottomSheet {
InfoView()
.disabled(true)
.frame(height: UIScreen.main.bounds.size.height)
.offset(y: dragOffset)
.gesture(DragGesture()
.onChanged { gesture in
Logger.debug("onChanged - \(gesture.translation.height)")
dragOffset = gesture.translation.height + currentOffset
}
.onEnded { gesture in
Logger.debug("onEnded - \(gesture.translation.height)")
dragOffset = gesture.translation.height + currentOffset
decideSheetHeight()
}
)
}
}
}
}
}

extension StudyMapView {
enum SheetHeight {
static let bottom = UIScreen.main.bounds.size.height * (5/7)
}
enum SheetBoundary {
static let high = UIScreen.main.bounds.size.height * (1/4)
static let middle = UIScreen.main.bounds.size.height * (1/2)
static let low = UIScreen.main.bounds.size.height * (3/4)
}

private func decideSheetHeight() {
withAnimation(.easeInOut) {
if dragOffset > SheetBoundary.low {
dragOffset = SheetHeight.bottom
isBottomSheetFull = false
} else if dragOffset > SheetBoundary.middle {
dragOffset = SheetHeight.bottom
} else {
isBottomSheetFull = true
dragOffset = SheetHeight.bottom
store.send(.viewTransition(.goToInfoDetail))
}
}
currentOffset = dragOffset
}
}

0 comments on commit 6eecda1

Please sign in to comment.