Skip to content

Commit 94a4dd1

Browse files
committed
[Fix] TCalendarView 동적 높이 관련 UI 버그 수정
1 parent 9a897ef commit 94a4dd1

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

TnT/Projects/DesignSystem/Sources/Components/Calendar/TCalendarHeader.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public struct TCalendarHeader<RightView: View>: View {
5050
.frame(maxWidth: .infinity)
5151
.overlay(alignment: .trailing) {
5252
rightView?()
53-
.padding(.trailing, 20)
5453
}
54+
.padding(.vertical, 8)
55+
.padding(.horizontal, 20)
5556
}
5657

5758
private func movePage(_ direction: Int) {

TnT/Projects/DesignSystem/Sources/Components/Calendar/TCalendarRepresentable.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
import SwiftUI
1010
import FSCalendar
1111

12-
1312
public struct TCalendarRepresentable: UIViewRepresentable {
1413
/// 선택한 날짜
1514
@Binding private var selectedDate: Date
1615
/// 현재 페이지
1716
@Binding private var currentPage: Date
17+
/// 캘린더 높이
18+
@Binding var calendarHeight: CGFloat
1819
/// 주간/월간 표시 여부
1920
private var isWeekMode: Bool
2021
/// 캘린더 표시 이벤트 딕셔너리
@@ -23,11 +24,13 @@ public struct TCalendarRepresentable: UIViewRepresentable {
2324
public init(
2425
selectedDate: Binding<Date>,
2526
currentPage: Binding<Date>,
27+
calendarHeight: Binding<CGFloat>,
2628
isWeekMode: Bool = false,
2729
events: [Date: Int] = [:]
2830
) {
2931
self._selectedDate = selectedDate
3032
self._currentPage = currentPage
33+
self._calendarHeight = calendarHeight
3134
self.isWeekMode = isWeekMode
3235
self.events = events
3336
}
@@ -38,6 +41,7 @@ public struct TCalendarRepresentable: UIViewRepresentable {
3841

3942
public func makeUIView(context: Context) -> FSCalendar {
4043
let calendar: FSCalendar = FSCalendar()
44+
4145
// Cell 설정
4246
calendar.register(TCalendarCell.self, forCellReuseIdentifier: TCalendarCell.identifier)
4347
calendar.collectionView.contentSize = TCalendarCell.cellSize
@@ -50,6 +54,8 @@ public struct TCalendarRepresentable: UIViewRepresentable {
5054
// UI 설정
5155
calendar.placeholderType = .none
5256
calendar.headerHeight = 0
57+
calendar.weekdayHeight = 18
58+
calendar.rowHeight = TCalendarCell.cellSize.height
5359
calendar.appearance.weekdayTextColor = UIColor(.neutral400)
5460
calendar.appearance.weekdayFont = Typography.FontStyle.label2Medium.uiFont
5561
calendar.appearance.selectionColor = .clear
@@ -76,6 +82,11 @@ public struct TCalendarRepresentable: UIViewRepresentable {
7682
uiView.scope = targetScope
7783
}
7884

85+
DispatchQueue.main.async {
86+
uiView.bounds.size.height = self.calendarHeight
87+
uiView.frame.size.height = self.calendarHeight
88+
}
89+
7990
uiView.reloadData()
8091
}
8192
}
@@ -103,6 +114,16 @@ public extension TCalendarRepresentable {
103114
}
104115
}
105116

117+
// Week/Month 모드 전환
118+
public func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
119+
DispatchQueue.main.async {
120+
calendar.bounds.size.height = bounds.height
121+
calendar.frame.size.height = bounds.height
122+
calendar.setNeedsLayout()
123+
calendar.layoutIfNeeded()
124+
}
125+
}
126+
106127
// 캘린더 셀 주입
107128
public func calendar(_ calendar: FSCalendar, cellFor date: Date, at position: FSCalendarMonthPosition) -> FSCalendarCell {
108129

TnT/Projects/DesignSystem/Sources/Components/Calendar/TCalendarView.swift

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import SwiftUI
1212
/// 주간/월간 표시를 포함합니다.
1313
public struct TCalendarView: View {
1414

15+
/// 주간 캘린더 높이
16+
static let weeklyCalendarHeight: CGFloat = 80
17+
/// 월간 캘린더 높이
18+
static let monthlyCalendarHeight: CGFloat = 340
1519
/// 선택한 날짜
1620
@Binding var selectedDate: Date
1721
/// 현재 페이지
1822
@Binding var currentPage: Date
1923
/// 업데이트 플래그
2024
@State private var forceUpdate: UUID = UUID()
25+
/// 캘린더 높이
26+
@State private var calendarHeight: CGFloat = monthlyCalendarHeight
2127
/// 주간/월간 표시 여부
2228
private var isWeekMode: Bool
2329
/// 캘린더 표시 이벤트 딕셔너리
@@ -38,15 +44,31 @@ public struct TCalendarView: View {
3844
}
3945

4046
public var body: some View {
41-
TCalendarRepresentable(
42-
selectedDate: $selectedDate,
43-
currentPage: $currentPage,
44-
isWeekMode: isWeekMode,
45-
events: events
46-
)
47-
.id(forceUpdate)
48-
.onChange(of: events) {
49-
forceUpdate = UUID()
47+
GeometryReader { proxy in
48+
TCalendarRepresentable(
49+
selectedDate: $selectedDate,
50+
currentPage: $currentPage,
51+
calendarHeight: $calendarHeight,
52+
isWeekMode: isWeekMode,
53+
events: events
54+
)
55+
.frame(width: proxy.size.width, height: TCalendarView.monthlyCalendarHeight)
56+
.id(forceUpdate)
57+
.onChange(of: events) {
58+
forceUpdate = UUID()
59+
}
60+
.onAppear {
61+
calendarHeight = isWeekMode
62+
? TCalendarView.weeklyCalendarHeight
63+
: TCalendarView.monthlyCalendarHeight
64+
}
65+
.onChange(of: isWeekMode) {
66+
calendarHeight = isWeekMode
67+
? TCalendarView.weeklyCalendarHeight
68+
: TCalendarView.monthlyCalendarHeight
69+
}
5070
}
71+
.frame(height: calendarHeight)
72+
.clipped()
5173
}
5274
}

0 commit comments

Comments
 (0)