diff --git a/Application/Presentation/HomeTab/Sources/Goal/TodoSelection/GoalCreateTodoSelectionSheet.swift b/Application/Presentation/HomeTab/Sources/Goal/TodoSelection/GoalCreateTodoSelectionSheet.swift index 223ad63f..90830f09 100644 --- a/Application/Presentation/HomeTab/Sources/Goal/TodoSelection/GoalCreateTodoSelectionSheet.swift +++ b/Application/Presentation/HomeTab/Sources/Goal/TodoSelection/GoalCreateTodoSelectionSheet.swift @@ -37,29 +37,27 @@ struct GoalCreateTodoSelectionSheet: View { .frame(maxWidth: .infinity) .padding(.vertical, 40) } else if store.hasLoadFailure, store.todos.isEmpty { - ContentUnavailableView { - Label( - RecordPresentation.text("common_error_title"), - systemImage: "exclamationmark.triangle" - ) - } description: { - Text(RecordPresentation.text("development_goal_todo_load_error_message")) - } actions: { + EmptyStateView( + RecordPresentation.text("common_error_title"), + systemImage: "exclamationmark.triangle", + message: RecordPresentation.text("development_goal_todo_load_error_message") + ) { Button(RecordPresentation.text("development_goal_todo_retry")) { store.send(.view(.retry)) } - .buttonStyle(.borderedProminent) + .buttonStyle(RecordButtonStyle()) } } else if store.todos.isEmpty { - ContentUnavailableView( + EmptyStateView( RecordPresentation.text("development_goal_todo_available_empty_title"), systemImage: "checklist", - description: Text( - RecordPresentation.text("development_goal_todo_available_empty_message") - ) + message: RecordPresentation.text("development_goal_todo_available_empty_message") ) } else if store.filteredTodos.isEmpty { - ContentUnavailableView.search(text: store.searchText) + EmptyStateView( + String(localized: "todo_list_search_empty", bundle: PresentationResources.bundle), + systemImage: "magnifyingglass" + ) } else { ForEach(store.sections) { section in GoalTodoSelectionSection( diff --git a/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift b/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift index d9c2933f..4f3c099f 100644 --- a/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift +++ b/Application/Presentation/HomeTab/Sources/Home/DevelopmentGoalSection.swift @@ -45,36 +45,22 @@ struct DevelopmentGoalSection: View { .frame(maxWidth: .infinity) .padding(.vertical, 32) } else if !hasLoaded && hasLoadFailure { - ContentUnavailableView { - Label( - String(localized: "common_error_title", bundle: PresentationResources.bundle), - systemImage: "exclamationmark.triangle" - ) - } description: { - Text(String(localized: "common_error_message", bundle: PresentationResources.bundle)) - } actions: { + EmptyStateView( + String(localized: "common_error_title", bundle: PresentationResources.bundle), + systemImage: "exclamationmark.triangle", + message: String(localized: "common_error_message", bundle: PresentationResources.bundle) + ) { Button(String(localized: "development_record_timeline_retry", bundle: PresentationResources.bundle)) { onRetry() } - .buttonStyle(.borderedProminent) + .buttonStyle(RecordButtonStyle()) } } else if items.isEmpty { - ContentUnavailableView { - Label( - String( - localized: "home_development_goal_empty_title", - bundle: PresentationResources.bundle - ), - systemImage: "flag.checkered" - ) - } description: { - Text( - String( - localized: "home_development_goal_empty_message", - bundle: PresentationResources.bundle - ) - ) - } + EmptyStateView( + String(localized: "home_development_goal_empty_title", bundle: PresentationResources.bundle), + systemImage: "flag.checkered", + message: String(localized: "home_development_goal_empty_message", bundle: PresentationResources.bundle) + ) } else { LazyVStack(spacing: 0) { ForEach(items) { item in diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift b/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift index 961a7052..cb591993 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeFeature.swift @@ -29,6 +29,8 @@ struct HomeFeature { var selectedTodoCategory: TodoCategory? // 홈 제목 줄 아래 보이는 높이, 새로 만들기 팝오버가 화면 밖으로 넘치지 않게 사용 var visibleHeight = CGFloat.infinity + // 새로 만들기 시트 목록 높이, 시트를 내용 높이에 맞추는 데 사용 + var contentPickerHeight = CGFloat.zero var loading = LoadingFeature.State() var showContentPicker: Bool { diff --git a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift index d219393a..545dbf61 100644 --- a/Application/Presentation/HomeTab/Sources/Home/HomeView.swift +++ b/Application/Presentation/HomeTab/Sources/Home/HomeView.swift @@ -630,145 +630,80 @@ private struct HomeTodoCategoryLink: View { } } +// 새로 만들기 화면 +// 위쪽 닫기 버튼과 제목 줄, 작은 제목 아래 구분선으로 나눈 TODO 카테고리와 새 개발 목표 배치 +// 좁은 창은 시트, 사이드바가 있는 iPad 창은 손가락 크기 팝오버, Mac은 Mac 크기 팝오버 모양 private struct HomeContentPicker: View { @Environment(\.isiOSAppOnMac) private var isiOSAppOnMac + @Environment(\.usesPaneLayout) private var usesPaneLayout let store: StoreOf let onSelect: (TodoCategory) -> Void var body: some View { - if isiOSAppOnMac { - HomeDesktopContentPicker(store: store, onSelect: onSelect) - } else { - mobileContent - } - } + let scale = AdaptiveSize.boardScale + let headerHeight = isiOSAppOnMac ? 44 * scale : usesPaneLayout ? 52 : 48 + // 시트는 위쪽 손잡이 아래에 제목 줄을 둠 + let grabberInset = isiOSAppOnMac || usesPaneLayout ? 0 : CGFloat(11) - private var mobileContent: some View { - NavigationStack { - List { - Section { - if store.isPreferencesLoading { - LoadingView() - } else { - let items = store.preferences.filter(\.isVisible) - ForEach(items, id: \.id) { item in + VStack(spacing: 0) { + if isiOSAppOnMac || usesPaneLayout { + // 팝오버와 Mac은 X 닫기 버튼과 가운데 제목 + ZStack { + Text("home_create_title", bundle: PresentationResources.bundle) + .font(isiOSAppOnMac ? .system(size: 14 * scale, weight: .bold) : .adaptive(.headline).bold()) + HStack { + if isiOSAppOnMac { Button { - onSelect(item.category) + store.send(.sheet(.presented(.tapCloseButton))) } label: { - HomeContentPickerLabel( - text: item.localizedName, - systemName: item.symbolName, - imageColor: item.color - ) + Image(systemName: "xmark") + .font(.adaptive(.body)) + .foregroundStyle(Color.label) + .frame(width: 28 * scale, height: 28 * scale) + .contentShape(.rect) } - .listRowInsets(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) + .buttonStyle(.plain) + } else { + Button { + store.send(.sheet(.presented(.tapCloseButton))) + } label: { + Image(systemName: "xmark") + } + .topBarButtonStyle() } + Spacer() } - } header: { - Text("TODO", bundle: PresentationResources.bundle) - .foregroundStyle(Color(.label)) - } - - Section { - Button { - store.send(.view(.tapCreateDevelopmentGoal)) - } label: { - HomeContentPickerLabel( - text: String( - localized: "development_goal_create_title", - bundle: PresentationResources.bundle - ), - systemName: "flag.checkered", - imageColor: Color.label, - iconColor: Color.background - ) - } - .listRowInsets(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) - } header: { - Text("development_goal_title", bundle: PresentationResources.bundle) - .foregroundStyle(Color(.label)) } - } - .navigationTitle(Text(verbatim: "DevLog")) - .navigationBarTitleDisplayMode(.inline) // 설정 안하면 섹션 위에 내비게이션 large 만큼 영역 먹음 - .toolbar { - ToolbarItem(placement: .topBarLeading) { - Button { - store.send(.sheet(.presented(.tapCloseButton))) - } label: { - Image(systemName: "xmark") - .bold() - } + .padding(.horizontal, 10 * scale) + .frame(height: headerHeight) + .overlay(alignment: .bottom) { + Rectangle() + .fill(Color.separator) + .frame(height: 1) } - } - } - } -} - -private struct HomeContentPickerLabel: View { - @ScaledMetric(relativeTo: .largeTitle) private var labelWidth = CGFloat(34) - let text: String - let systemName: String - let imageColor: Color - var iconColor = Color.white - - var body: some View { - HStack { - RoundedRectangle(cornerRadius: CornerRadius.control) - .fill(imageColor) - .frame(width: labelWidth, height: labelWidth) - .overlay { - Image(systemName: systemName) - .foregroundStyle(iconColor) - .font(.adaptive(.title3)) - } - Text(text) - .foregroundStyle(Color.label) - Spacer() - } - .contentShape(.rect) - } -} - -// Mac 새로 만들기 팝오버 -// 위쪽 닫기·제목 줄, 작은 제목 아래 구분선으로 나눈 TODO 카테고리와 새 개발 목표 배치 -private struct HomeDesktopContentPicker: View { - let store: StoreOf - let onSelect: (TodoCategory) -> Void - - var body: some View { - VStack(spacing: 0) { - ZStack { - Text("home_create_title", bundle: PresentationResources.bundle) - .font(.system(size: 14 * AdaptiveSize.boardScale, weight: .bold)) - HStack { - Button { + } else { + // 시트는 다른 시트처럼 손잡이 아래부터 글자 닫기 버튼과 가운데 제목 + RecordTopBar( + String(localized: "home_create_title", bundle: PresentationResources.bundle), + background: .secondaryBackground + ) { + RecordTopBarTextButton(RecordPresentation.text("common_close")) { store.send(.sheet(.presented(.tapCloseButton))) - } label: { - Image(systemName: "xmark") - .font(.adaptive(.body)) - .foregroundStyle(Color.label) - .frame(width: 28 * AdaptiveSize.boardScale, height: 28 * AdaptiveSize.boardScale) - .contentShape(.rect) } - .buttonStyle(.plain) - Spacer() + } trailing: { + EmptyView() } - } - .padding(.horizontal, 10 * AdaptiveSize.boardScale) - .frame(height: 44 * AdaptiveSize.boardScale) - .overlay(alignment: .bottom) { - Rectangle() - .fill(Color.separator) - .frame(height: 1) + .padding(.top, grabberInset) + // 아래에서 올라온 시트라 창 컨트롤 여백을 더하지 않음 + .environment(\.windowControlsInset, 0) } ScrollView { - VStack(alignment: .leading, spacing: 16 * AdaptiveSize.boardScale) { - section(Text(verbatim: "TODO")) { + VStack(alignment: .leading, spacing: isiOSAppOnMac ? 16 * scale : 24) { + section(Text("TODO", bundle: PresentationResources.bundle)) { if store.isPreferencesLoading { LoadingView() - .frame(maxWidth: .infinity, minHeight: 38 * AdaptiveSize.boardScale) + .frame(maxWidth: .infinity, minHeight: isiOSAppOnMac ? 38 * scale : 50) } else { ForEach(store.preferences.filter(\.isVisible), id: \.id) { item in row(title: Text(item.localizedName), symbolName: item.symbolName, color: item.color) { @@ -788,14 +723,25 @@ private struct HomeDesktopContentPicker: View { } } } - .padding(.horizontal, 14 * AdaptiveSize.boardScale) - .padding(.vertical, 8 * AdaptiveSize.boardScale) + .padding(.horizontal, isiOSAppOnMac ? 14 * scale : 16) + .padding(.vertical, isiOSAppOnMac ? 8 * scale : 12) + .onGeometryChange(for: CGFloat.self) { proxy in + proxy.size.height + } action: { height in + store.send(.binding(.set(\.contentPickerHeight, height))) + } } .scrollBounceBehavior(.basedOnSize) } + // 좁은 화면 시트는 목록 높이에 맞추고, 화면보다 길면 목록을 스크롤 + .sheetDetent( + isiOSAppOnMac || store.contentPickerHeight == 0 + ? .large : .height(grabberInset + headerHeight + store.contentPickerHeight) + ) } - // 작은 제목 아래 바탕·테두리 없이 행 사이 구분선으로 나눈 묶음 + // 작은 제목 아래 바탕과 테두리 없이 행 사이 구분선으로 나눈 묶음 + // 시트는 이름 앞에서 시작하는 구분선, 팝오버는 행 폭 전체 구분선 private func section(_ header: Text, @ViewBuilder content: () -> Content) -> some View { VStack(alignment: .leading, spacing: 0) { header @@ -810,8 +756,9 @@ private struct HomeDesktopContentPicker: View { if subview.id != subviews.last?.id { Rectangle() - .fill(Color.secondarySeparator) + .fill(isiOSAppOnMac || usesPaneLayout ? Color.secondarySeparator : .separator) .frame(height: 1) + .padding(.leading, isiOSAppOnMac || usesPaneLayout ? 0 : 28 + 10) } } } @@ -821,12 +768,19 @@ private struct HomeDesktopContentPicker: View { // 테두리 있는 아이콘 사각형과 이름 행 private func row(title: Text, symbolName: String, color: Color, action: @escaping () -> Void) -> some View { - Button(action: action) { - HStack(spacing: 10 * AdaptiveSize.boardScale) { + let scale = AdaptiveSize.boardScale + let iconSize = isiOSAppOnMac ? 25 * scale : 28 + + return Button(action: action) { + HStack(spacing: 10 * scale) { Image(systemName: symbolName) + .font(.adaptive(isiOSAppOnMac ? .body : .footnote)) .foregroundStyle(color) - .frame(width: 25 * AdaptiveSize.boardScale, height: 25 * AdaptiveSize.boardScale) - .background(Color.tertiaryBackground, in: .rect(cornerRadius: CornerRadius.control)) + .frame(width: iconSize, height: iconSize) + .background( + isiOSAppOnMac ? Color.tertiaryBackground : .background, + in: .rect(cornerRadius: CornerRadius.control) + ) .overlay { RoundedRectangle(cornerRadius: CornerRadius.control) .strokeBorder(Color.secondarySeparator) @@ -835,8 +789,8 @@ private struct HomeDesktopContentPicker: View { .foregroundStyle(Color.label) .frame(maxWidth: .infinity, alignment: .leading) } - .font(.adaptive(.body)) - .frame(minHeight: 38 * AdaptiveSize.boardScale) + .font(.adaptive(isiOSAppOnMac ? .body : .subheadline)) + .frame(minHeight: isiOSAppOnMac ? 38 * scale : 50) .hoverHighlight() } .buttonStyle(.plain) diff --git a/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift index f3bc2caf..8f92c003 100644 --- a/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/Detail/RecordDetailView.swift @@ -166,23 +166,16 @@ public struct RecordDetailView: View { } private var failureContent: some View { - VStack(spacing: 20) { - ContentUnavailableView( - RecordPresentation.text("common_error_title"), - systemImage: "exclamationmark.triangle", - description: Text( - RecordPresentation.text("development_record_detail_error_message") - ) - ) - + EmptyStateView( + RecordPresentation.text("common_error_title"), + systemImage: "exclamationmark.triangle", + message: RecordPresentation.text("development_record_detail_error_message") + ) { Button(RecordPresentation.text("development_record_detail_retry")) { store.send(.view(.fetch)) } - .buttonStyle(.borderedProminent) + .buttonStyle(RecordButtonStyle()) } - .frame(maxWidth: .infinity) - .padding(24) - .background(Color.secondaryBackground, in: .rect) } // 기록 정정과 버전 이력 버튼, 한 줄에 들어가지 않으면 세로로 표시 diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift index c0dc7314..474fe11b 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalDetailView.swift @@ -223,30 +223,27 @@ public struct GoalDetailView: View { } if !store.hasLoaded, store.hasLoadFailure { - ContentUnavailableView { - Label( - RecordPresentation.text("common_error_title"), - systemImage: "exclamationmark.triangle" - ) - } description: { - Text(RecordPresentation.text("development_record_timeline_error_message")) - } actions: { + EmptyStateView( + RecordPresentation.text("common_error_title"), + systemImage: "exclamationmark.triangle", + message: RecordPresentation.text("development_record_timeline_error_message") + ) { Button { store.send(.view(.refresh)) } label: { Text(RecordPresentation.text("development_record_timeline_retry")) } - .buttonStyle(.borderedProminent) + .buttonStyle(RecordButtonStyle()) } } else if !store.hasLoaded || store.isLoading, store.items.isEmpty { ProgressView() .frame(maxWidth: .infinity) .padding(.vertical, 32) } else if store.items.isEmpty { - ContentUnavailableView( + EmptyStateView( RecordPresentation.text("development_record_empty_title"), systemImage: "doc.badge.plus", - description: Text(RecordPresentation.text("development_record_empty_message")) + message: RecordPresentation.text("development_record_empty_message") ) } else { LazyVStack(spacing: 0) { diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalLinkedTodoCard.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalLinkedTodoCard.swift index ac3b060a..3f05c962 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalLinkedTodoCard.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalLinkedTodoCard.swift @@ -55,27 +55,22 @@ struct GoalLinkedTodoCard: View { .frame(maxWidth: .infinity) .padding(.vertical, 20) } else if hasLoadFailure, todos.isEmpty { - ContentUnavailableView { - Label( - RecordPresentation.text("common_error_title"), - systemImage: "exclamationmark.triangle" - ) - } description: { - Text(RecordPresentation.text("development_goal_todo_load_error_message")) - } actions: { + EmptyStateView( + RecordPresentation.text("common_error_title"), + systemImage: "exclamationmark.triangle", + message: RecordPresentation.text("development_goal_todo_load_error_message") + ) { Button( RecordPresentation.text("development_goal_todo_retry"), action: onRetry ) - .buttonStyle(.borderedProminent) + .buttonStyle(RecordButtonStyle()) } } else if todos.isEmpty { - ContentUnavailableView( + EmptyStateView( RecordPresentation.text("development_goal_todo_empty_title"), systemImage: "checklist", - description: Text( - RecordPresentation.text("development_goal_todo_empty_message") - ) + message: RecordPresentation.text("development_goal_todo_empty_message") ) } else { LazyVStack(spacing: 0) { diff --git a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalTodoLinkSheet.swift b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalTodoLinkSheet.swift index b1636811..5e8896b4 100644 --- a/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalTodoLinkSheet.swift +++ b/Application/Presentation/HomeTab/Sources/Record/GoalDetail/GoalTodoLinkSheet.swift @@ -109,29 +109,27 @@ struct GoalTodoLinkSheet: View { .frame(maxWidth: .infinity) .padding(.vertical, 40) } else if store.hasLoadFailure, store.todos.isEmpty { - ContentUnavailableView { - Label( - RecordPresentation.text("common_error_title"), - systemImage: "exclamationmark.triangle" - ) - } description: { - Text(RecordPresentation.text("development_goal_todo_load_error_message")) - } actions: { + EmptyStateView( + RecordPresentation.text("common_error_title"), + systemImage: "exclamationmark.triangle", + message: RecordPresentation.text("development_goal_todo_load_error_message") + ) { Button(RecordPresentation.text("development_goal_todo_retry")) { store.send(.view(.retry)) } - .buttonStyle(.borderedProminent) + .buttonStyle(RecordButtonStyle()) } } else if store.todos.isEmpty { - ContentUnavailableView( + EmptyStateView( RecordPresentation.text("development_goal_todo_available_empty_title"), systemImage: "checklist", - description: Text( - RecordPresentation.text("development_goal_todo_available_empty_message") - ) + message: RecordPresentation.text("development_goal_todo_available_empty_message") ) } else if store.filteredTodos.isEmpty { - ContentUnavailableView.search(text: store.searchText) + EmptyStateView( + String(localized: "todo_list_search_empty", bundle: PresentationResources.bundle), + systemImage: "magnifyingglass" + ) } else { ForEach(store.sections) { section in GoalTodoSelectionSection( diff --git a/Application/Presentation/PresentationShared/Sources/Common/Component/EmptyStateView.swift b/Application/Presentation/PresentationShared/Sources/Common/Component/EmptyStateView.swift index e3aef825..bfe4c391 100644 --- a/Application/Presentation/PresentationShared/Sources/Common/Component/EmptyStateView.swift +++ b/Application/Presentation/PresentationShared/Sources/Common/Component/EmptyStateView.swift @@ -7,18 +7,26 @@ import SwiftUI -public struct EmptyStateView: View { +// 아이콘 원, 제목, 설명 아래에 다시 시도 같은 버튼을 두는 빈 화면 +public struct EmptyStateView: View { @ScaledMetric(relativeTo: .title2) private var iconSize = CGFloat(52) @ScaledMetric(relativeTo: .footnote) private var messageSize = CGFloat(13.5) @ScaledMetric(relativeTo: .footnote) private var messageWidth = CGFloat(280) private let title: String private let systemImage: String private let message: String? + private let actions: Actions - public init(_ title: String, systemImage: String, message: String? = nil) { + public init( + _ title: String, + systemImage: String, + message: String? = nil, + @ViewBuilder actions: () -> Actions + ) { self.title = title self.systemImage = systemImage self.message = message + self.actions = actions() } public var body: some View { @@ -37,6 +45,10 @@ public struct EmptyStateView: View { .foregroundStyle(Color.secondaryLabel) .frame(maxWidth: messageWidth) } + if Actions.self != EmptyView.self { + actions + .padding(.top, 12) + } } .multilineTextAlignment(.center) .frame(maxWidth: .infinity) @@ -44,3 +56,9 @@ public struct EmptyStateView: View { .padding(.top, 72) } } + +public extension EmptyStateView where Actions == EmptyView { + init(_ title: String, systemImage: String, message: String? = nil) { + self.init(title, systemImage: systemImage, message: message) { EmptyView() } + } +} diff --git a/Application/Presentation/PresentationShared/Sources/Todo/Detail/PreviewView.swift b/Application/Presentation/PresentationShared/Sources/Todo/Detail/PreviewView.swift index 6087c239..39cbc849 100644 --- a/Application/Presentation/PresentationShared/Sources/Todo/Detail/PreviewView.swift +++ b/Application/Presentation/PresentationShared/Sources/Todo/Detail/PreviewView.swift @@ -21,14 +21,11 @@ struct PreviewView: View { onOpenTodoID: nil ) } else if store.alert != nil { - ContentUnavailableView { - Label( - String(localized: "common_error_title", bundle: PresentationResources.bundle), - systemImage: "exclamationmark.triangle" - ) - } description: { - Text(String(localized: "common_error_message", bundle: PresentationResources.bundle)) - } + EmptyStateView( + String(localized: "common_error_title", bundle: PresentationResources.bundle), + systemImage: "exclamationmark.triangle", + message: String(localized: "common_error_message", bundle: PresentationResources.bundle) + ) } else { LoadingView() }