Skip to content

Commit

Permalink
✨[feat]: 디자인 업데이트 #12
Browse files Browse the repository at this point in the history
* 카드 UI 수정
  • Loading branch information
Roy-wonji committed Aug 29, 2024
1 parent bfd757f commit decc2a0
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct FlippableCardView<Content: View, T>: View {
LazyVStack(spacing: 0) {
ForEach(data.indices, id: \.self) { index in
content(data[index])
.frame(width: geometry.size.width, height: 524)
.frame(width: geometry.size.width, height: 520)
.background(Color.clear)
.scrollTargetLayout()
.id(index)
Expand All @@ -50,12 +50,16 @@ public struct FlippableCardView<Content: View, T>: View {
}
.gesture(DragGesture()
.updating($dragOffset) { value, state, _ in
state = value.translation.height // Track the current drag offset
state = value.translation.height * 0.2 // Dampen the drag effect
}
.onEnded { value in
// Determine the nearest index based on the drag velocity and position
// Determine the nearest index based on drag velocity and position
let velocity = value.predictedEndLocation.y - value.startLocation.y
let nearestIndex = calculateNearestIndex(geometry: geometry, currentPage: currentPage, velocity: velocity)
let nearestIndex = calculateNearestIndex(
geometry: geometry,
currentPage: currentPage,
velocity: velocity
)
currentPage = nearestIndex
lastViewedPage = nearestIndex // Save the current page as the last viewed page
scrollToCenter(scrollViewProxy: scrollViewProxy, index: nearestIndex)
Expand All @@ -64,8 +68,7 @@ public struct FlippableCardView<Content: View, T>: View {
.scrollTargetBehavior(.viewAligned)
.scrollIndicators(.hidden)
.onAppear {
// Restore the last viewed page when the view appears
currentPage = min(lastViewedPage, data.count - 1) // Ensure the page doesn't exceed available indices
currentPage = min(lastViewedPage, data.count - 1)
scrollToCenter(scrollViewProxy: scrollViewProxy, index: currentPage)
}
.onChange(of: scenePhase) { oldValue, newValue in
Expand All @@ -86,10 +89,15 @@ public struct FlippableCardView<Content: View, T>: View {
}


private func calculateNearestIndex(geometry: GeometryProxy, currentPage: Int, velocity: CGFloat) -> Int {
if velocity > 0 {
private func calculateNearestIndex(
geometry: GeometryProxy,
currentPage: Int,
velocity: CGFloat
) -> Int {
let threshold: CGFloat = 30 // Minimum velocity needed to trigger a scroll change
if velocity > threshold {
return max(currentPage - 1, 0)
} else if velocity < 0 {
} else if velocity < -threshold {
return min(currentPage + 1, data.count - 1)
}
return currentPage
Expand All @@ -113,7 +121,6 @@ struct ScrollEffectModifier: ViewModifier {
func body(content: Content) -> some View {
content
.offset(y: calculateOffset())
// .animation(.easeOut(duration: 0.3), value: dragOffset)
}

private func calculateOffset() -> CGFloat {
Expand Down

0 comments on commit decc2a0

Please sign in to comment.