Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AIProject/iCo/Features/Base/SubheaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct SubheaderView: View {
.font(.ico15)
.foregroundStyle(fontColor)
.lineSpacing(6)
.fixedSize(horizontal: false, vertical: true)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,6 @@ extension CoinCarouselView {
}

#Preview {
RecommendCoinView()
RecommendCoinView(headerHeight: 140)
.environmentObject(RecommendCoinViewModel())
}
36 changes: 25 additions & 11 deletions AIProject/iCo/Features/Dashboard/View/DashboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,43 @@ import SwiftUI
/// 관심 코인 기반 추천, AI 브리핑으로 구성합니다.
struct DashboardView: View {
@Environment(\.horizontalSizeClass) var hSizeClass
@Environment(\.dynamicTypeSize) var typeSize

@Namespace var coordinateSpaceName: Namespace.ID
/// 스크롤의 위치를 저장하는 상태 변수
@State var scrollOffset: CGFloat = 0
/// 상단 여백을 저장하는 상태 변수: onAppear에서 실제 높이를 계산함
@State var topInset: CGFloat = 0
@State var currentTypeSize: DynamicTypeSize = .medium

/// 배경색의 높이를 저장하는 계산 속성: 헤더의 높이 + 여백 + 카드의 높이 / 2 + 상단 여백
/// 배경이 카드의 중앙까지만 깔리게 해야 하는데 뷰가 여러 계층으로 나눠져있어서 각 컴포넌트의 높이를 계산해서 사용함
var gradientHeight: CGFloat {
CardConst.headerHeight + CardConst.headerContentSpacing + (CardConst.cardHeight / 2) + topInset
/// 다이나믹 폰트 적용 후 헤더 컨텐츠 크기가 커질 때
/// 헤더 사이즈를 유동적으로 조정하기 위해 사용하는 계산 속성
/// 헤더뷰와 배경 그래디언트 크기에도 영향을 주기 때문에
/// 여기에서 계산 후 헤더뷰에게 전파
var dynamicHeaderHeight: CGFloat {
switch typeSize {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeSize라는게 있는 걸 처음봤네요
더 reponsive한 앱 같네요!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

소중한 리뷰 감사합니다~ :)

case .xSmall, .small, .medium: CardConst.headerHeight
case .large, .xLarge, .xxLarge, .xxxLarge: CardConst.headerHeight * 1.1
default: CardConst.headerHeight * 1.4
}
}

var body: some View {
/// 배경색에 Sticky 효과 적용을 위해 추가적인 높이: 스크롤 위치만큼 더해주기 위해 사용
/// 쫀득한 효과를 더 드라마틱하게 보여주기 위해 스크롤 위치의 1.2배만큼 늘리기
let extraHeight = max(0, -scrollOffset * 1.2)

/// 배경색의 높이를 저장하는 계산 속성: 헤더의 높이 + 여백 + 카드의 높이 / 2 + 상단 여백
/// 배경이 카드의 중앙까지만 깔리게 해야 하는데 뷰가 여러 계층으로 나눠져있어서 각 컴포넌트의 높이를 계산해서 사용함
var gradientHeight: CGFloat {
dynamicHeaderHeight + CardConst.headerContentSpacing + (CardConst.cardHeight / 2) + topInset
}

GeometryReader { outerProxy in
NavigationStack {
ScrollView {
VStack {
RecommendCoinView()
RecommendCoinView(headerHeight: dynamicHeaderHeight)
AIBriefingView()
}
.padding(.top, topInset)
Expand Down Expand Up @@ -112,12 +126,6 @@ struct DashboardView: View {
}
}

#Preview {
DashboardView()
.environmentObject(ThemeManager())
.environmentObject(RecommendCoinViewModel())
}

/// scrollOffset을 구하기 위한 PreferenceKey
private struct ScrollOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat { .zero }
Expand All @@ -126,3 +134,9 @@ private struct ScrollOffsetPreferenceKey: PreferenceKey {
value += nextValue()
}
}

#Preview {
DashboardView()
.environmentObject(ThemeManager())
.environmentObject(RecommendCoinViewModel())
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import SwiftUI
/// 컨텐츠 뷰에 코인 추천 상태별로 알맞은 뷰를 뿌려줍니다.
struct RecommendCoinView: View {
@StateObject private var viewModel = RecommendCoinViewModel()

let headerHeight: CGFloat

var body: some View {
ZStack(alignment: .top) {
VStack(alignment: .center, spacing: CardConst.headerContentSpacing) {
RecommendHeaderView()
.frame(height: headerHeight)

recommendContentView()
.frame(minHeight: CardConst.cardHeight)
Expand Down Expand Up @@ -69,7 +72,7 @@ struct RecommendCoinView: View {
}

#Preview {
RecommendCoinView()
RecommendCoinView(headerHeight: 140)
.environmentObject(RecommendCoinViewModel())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ struct RecommendHeaderView: View {
imageColor: .white,
fontColor: .white
)

Spacer()
}
.frame(height: CardConst.headerHeight)
}
}

#Preview() {
RecommendCoinView()
RecommendCoinView(headerHeight: 140)
.environmentObject(RecommendCoinViewModel())
.environmentObject(ThemeManager())
.background(.black.opacity(0.2))
}