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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct HomeFeature {
var isTodoCategoryExpanded = false
var isNetworkConnected = true
var selectedTodoCategory: TodoCategory?
// 홈 제목 줄 아래 보이는 높이, 새로 만들기 팝오버가 화면 밖으로 넘치지 않게 사용
// 홈 제목 줄 아래 보이는 높이, 새로 만들기 판이 화면 밖으로 넘치지 않게 사용
var visibleHeight = CGFloat.infinity
// 새로 만들기 시트 목록 높이, 시트를 내용 높이에 맞추는 데 사용
var contentPickerHeight = CGFloat.zero
Expand Down
10 changes: 4 additions & 6 deletions Application/Presentation/HomeTab/Sources/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ public struct HomeView: View {
.sharedBackgroundHidden()
}
}
// 좁은 창은 새로 만들기를 시트로, 칸으로 나눈 화면은 만들기 버튼 옆 팝오버로 표시
// 버튼 옆으로 붙으면 위쪽이 상태 표시 영역에 가려지므로 버튼 아래로 표시
// 좁은 창은 새로 만들기를 시트로, 칸으로 나눈 화면은 만들기 버튼 아래 판으로 표시
.compositionPicker(
isPresented: $store.showContentPicker,
isActive: isSelected,
arrowEdge: .top,
maxHeight: min(640, store.visibleHeight)
) {
HomeContentPicker(store: store) { store.send(.view(.tapTodoCategory($0))) }
Expand Down Expand Up @@ -428,7 +426,7 @@ private struct HomeTodoCategoryLink: View {

// 새로 만들기 화면
// 위쪽 닫기 버튼과 제목 줄, 작은 제목 아래 구분선으로 나눈 TODO 카테고리와 새 개발 목표 배치
// 좁은 창은 시트, 사이드바가 있는 iPad 창은 손가락 크기 팝오버, Mac은 Mac 크기 팝오버 모양
// 좁은 창은 시트, 사이드바가 있는 iPad 창은 손가락 크기 판, Mac은 Mac 크기 판 모양
private struct HomeContentPicker: View {
@Environment(\.isiOSAppOnMac) private var isiOSAppOnMac
@Environment(\.usesPaneLayout) private var usesPaneLayout
Expand All @@ -443,7 +441,7 @@ private struct HomeContentPicker: View {

VStack(spacing: 0) {
if isiOSAppOnMac || usesPaneLayout {
// 팝오버와 Mac은 X 닫기 버튼과 가운데 제목
// 판과 Mac은 X 닫기 버튼과 가운데 제목
ZStack {
Text("home_create_title", bundle: PresentationResources.bundle)
.font(isiOSAppOnMac ? .system(size: 14 * scale, weight: .bold) : .adaptive(.headline).bold())
Expand Down Expand Up @@ -537,7 +535,7 @@ private struct HomeContentPicker: View {
}

// 작은 제목 아래 바탕과 테두리 없이 행 사이 구분선으로 나눈 묶음
// 시트는 이름 앞에서 시작하는 구분선, 팝오버는 행 폭 전체 구분선
// 시트는 이름 앞에서 시작하는 구분선, 판은 행 폭 전체 구분선
private func section<Content: View>(_ header: Text, @ViewBuilder content: () -> Content) -> some View {
VStack(alignment: .leading, spacing: 0) {
header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,23 @@ public extension View {
}

// 고르는 화면
// 좁은 창은 시트로 띄우고, 칸으로 나눈 화면은 compositionPickerAnchor를 붙인 버튼 옆 팝오버로 띄움
// maxHeight가 없으면 팝오버를 내용 높이에 맞춤
// 좁은 창은 시트로 띄우고, 칸으로 나눈 화면은 compositionPickerAnchor를 붙인 버튼 아래에 직접 그린 판으로 띄움
// maxHeight가 없으면 판을 내용 높이에 맞춤
func compositionPicker<Content: View>(
isPresented: Binding<Bool>,
isActive: Bool = true,
arrowEdge: Edge? = nil,
maxHeight: CGFloat? = nil,
@ViewBuilder content: @escaping () -> Content
) -> some View {
modifier(CompositionPickerModifier(
isPresented: isPresented,
isActive: isActive,
arrowEdge: arrowEdge,
maxHeight: maxHeight,
picker: content
))
}

// 바깥의 compositionPicker가 칸으로 나눈 화면에서 띄우는 팝오버를 붙일 버튼
// 바깥의 compositionPicker가 칸으로 나눈 화면에서 띄우는 판을 붙일 버튼
func compositionPickerAnchor() -> some View {
modifier(CompositionPickerAnchorModifier())
}
Expand Down Expand Up @@ -356,10 +354,9 @@ private struct CompositionSheetModifier<Item: Identifiable, Sheet: View, Right:
}
}

// compositionPicker가 compositionPickerAnchor에 넘기는 팝오버 내용
// compositionPicker가 compositionPickerAnchor에 넘기는 판 내용
private struct CompositionPickerContent {
let isPresented: Binding<Bool>
let arrowEdge: Edge?
let maxHeight: CGFloat?
let content: () -> AnyView
}
Expand All @@ -380,12 +377,11 @@ private struct CompositionPickerModifier<Picker: View>: ViewModifier {
@State private var layout = LiveLayout()
let isPresented: Binding<Bool>
let isActive: Bool
let arrowEdge: Edge?
let maxHeight: CGFloat?
let picker: () -> Picker

func body(content: Content) -> some View {
// 창 폭이 바뀌어 팝오버와 시트를 오가면 같은 상태를 바뀐 쪽에 다시 그리고, 빠지는 쪽의 늦은 닫힘은 거름
// 창 폭이 바뀌어 판과 시트를 오가면 같은 상태를 바뀐 쪽에 다시 그리고, 빠지는 쪽의 늦은 닫힘은 거름
let layout = layout.update(usesPaneLayout: usesPaneLayout)
let sheetBinding = Binding(
get: { !layout.usesPaneLayout && isPresented.wrappedValue },
Expand All @@ -395,7 +391,7 @@ private struct CompositionPickerModifier<Picker: View>: ViewModifier {
}
}
)
let popoverBinding = Binding(
let panelBinding = Binding(
get: { layout.usesPaneLayout && isPresented.wrappedValue },
set: { value in
if layout.usesPaneLayout {
Expand All @@ -411,8 +407,7 @@ private struct CompositionPickerModifier<Picker: View>: ViewModifier {
.environment(
\.compositionPicker,
CompositionPickerContent(
isPresented: popoverBinding.activePresentation(when: isActive),
arrowEdge: arrowEdge,
isPresented: panelBinding.activePresentation(when: isActive),
maxHeight: maxHeight
) {
AnyView(picker())
Expand All @@ -423,26 +418,83 @@ private struct CompositionPickerModifier<Picker: View>: ViewModifier {

private struct CompositionPickerAnchorModifier: ViewModifier {
@Environment(\.compositionPicker) private var picker
@State private var anchor = CGRect.zero

func body(content: Content) -> some View {
let isPresented = picker?.isPresented ?? .constant(false)

content
.popover(isPresented: picker?.isPresented ?? .constant(false), arrowEdge: picker?.arrowEdge) {
if let picker {
Group {
// 화면이 낮거나 Duo 접는 선에 걸리면 팝오버 높이를 줄이고 목록을 스크롤
if let maxHeight = picker.maxHeight {
picker.content()
.frame(width: 320 * AdaptiveSize.boardScale)
.frame(minHeight: 0, idealHeight: maxHeight, maxHeight: maxHeight)
} else {
.onGeometryChange(for: CGRect.self) { proxy in
proxy.frame(in: .global)
} action: { frame in
anchor = frame
}
// 시스템 팝오버 대신 탭 바, 사이드바까지 덮는 투명한 자리에 판을 직접 그림
.modifier(
ProminentPresentation(
item: Binding(
get: { isPresented.wrappedValue ? SheetPresence() : nil },
set: { isPresented.wrappedValue = $0 != nil }
)
) { _, _, dismiss in
if let picker {
CompositionPickerPanel(anchor: anchor, maxHeight: picker.maxHeight, dismiss: dismiss) {
picker.content()
.frame(width: 320 * AdaptiveSize.boardScale)
.fixedSize(horizontal: false, vertical: true)
}
}
.presentationBackground(Color.secondaryBackground)
.presentationCompactAdaptation(.popover)
}
)
}
}

// OS와 상관없이 같은 모양으로 버튼 아래에 직접 그리는 화살표 없는 판
private struct CompositionPickerPanel<Content: View>: View {
@Environment(\.colorScheme) private var colorScheme
let anchor: CGRect
let maxHeight: CGFloat?
let dismiss: () -> Void
@ViewBuilder let content: Content

var body: some View {
let width = 320 * AdaptiveSize.boardScale
let spacing = CGFloat(6)
let margin = CGFloat(16)

ZStack(alignment: .topLeading) {
Color.clear
.contentShape(.rect)
.ignoresSafeArea()
.onTapGesture {
dismiss()
}

GeometryReader { proxy in
let frame = proxy.frame(in: .global)
// 버튼 가운데 아래에 두고, 창 끝에 걸리면 여백 안쪽으로 밀어 넣음
let leading = min(max(anchor.midX - width / 2 - frame.minX, margin), frame.width - width - margin)
let top = anchor.maxY - frame.minY + spacing
let available = max(frame.height - top - margin, 0)

Group {
// 화면이 낮으면 판 높이를 줄이고 목록을 스크롤
if let maxHeight {
content
.frame(height: min(maxHeight, available))
} else {
content
.fixedSize(horizontal: false, vertical: true)
}
}
.frame(width: width)
.background(Color.secondaryBackground)
.clipShape(.rect(cornerRadius: CornerRadius.dialog))
.overlay {
RoundedRectangle(cornerRadius: CornerRadius.dialog)
.strokeBorder(Color.separator)
}
.shadow(color: Color.black.opacity(colorScheme == .dark ? 0.5 : 0.12), radius: 30, y: 24)
.offset(x: leading, y: top)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public extension View {
}
}

private struct SheetPresence: Identifiable {
// 참거짓 표시 상태를 ProminentPresentation의 항목으로 바꾼 값
struct SheetPresence: Identifiable {
var id: Bool { true }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct ActivityCard: View {
.foregroundStyle(Color.label)
}
.buttonStyle(.plain)
// 칸으로 나눈 화면은 분기 선택을 시트 대신 버튼 옆 팝오버로 표시
// 칸으로 나눈 화면은 분기 선택을 시트 대신 버튼 아래 판으로 표시
.compositionPickerAnchor()
Spacer()
Button {
Expand Down Expand Up @@ -212,15 +212,15 @@ struct QuarterPickerSheet: View {
@Bindable var store: StoreOf<ProfileFeature>

var body: some View {
// 칸으로 나눈 iPad 화면의 팝오버도 Mac과 같은 배치, 크기만 손가락 기준
// 칸으로 나눈 iPad 화면의 판도 Mac과 같은 배치, 크기만 손가락 기준
if isiOSAppOnMac || usesPaneLayout {
desktopContent
} else {
mobileContent
}
}

// Mac·iPad 넓은 화면 분기 선택 팝오버
// Mac, iPad 넓은 화면 분기 선택 판
// 위쪽 제목·완료 줄, 바탕 없는 연도 행, 1~4분기 두 줄 격자 배치
private var desktopContent: some View {
VStack(spacing: 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public struct ProfileView: View {
@Environment(\.windowControlsInset) private var windowControlsInset
@Environment(\.usesPaneLayout) private var usesPaneLayout
@Environment(\.deviceType) private var deviceType
@Environment(\.isiOSAppOnMac) private var isiOSAppOnMac
@State private var store: StoreOf<ProfileFeature>
@Bindable private var settingsStore: StoreOf<SettingsFeature>
private let isSelected: Bool
Expand Down Expand Up @@ -132,11 +131,10 @@ public struct ProfileView: View {
settingsStore.send(.startObserving)
}
.prominentAlert(store, state: \.alert, action: \.alert)
// 좁은 창은 분기 선택을 시트로, 칸으로 나눈 화면은 분기 표시 옆 팝오버로 표시하고 Mac은 분기 표시 아래로 표시
// 좁은 창은 분기 선택을 시트로, 칸으로 나눈 화면은 분기 표시 아래 판으로 표시
.compositionPicker(
isPresented: $store.showQuarterPicker,
isActive: isSelected,
arrowEdge: isiOSAppOnMac ? .top : nil
isActive: isSelected
) {
QuarterPickerSheet(store: store)
}
Expand Down