-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] #51 - DateTimePickerSectionView 구현
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...-iOS/Memento-iOS/Source/Presentation/Add/AddSchedule/View/DateTimePickerSectionView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// DateTimePickerSectionView.swift | ||
// Memento-iOS | ||
// | ||
// Created by RAFA on 1/18/25. | ||
// | ||
|
||
import SwiftUI | ||
|
||
import MDSKit | ||
|
||
struct DateTimePickerSectionView: View { | ||
|
||
// MARK: - Properties | ||
|
||
let title: String | ||
@ObservedObject var viewModel: PickerButtonViewModel | ||
let sectionType: AddScheduleSectionType | ||
|
||
@StateObject private var datePickerViewModel = PickerButtonViewModel() | ||
@StateObject private var timePickerViewModel = PickerButtonViewModel() | ||
|
||
// MARK: - Body | ||
|
||
var body: some View { | ||
HStack { | ||
Text(title) | ||
.applyFont(.body_r_16) | ||
.foregroundColor(.gray05) | ||
|
||
Spacer() | ||
|
||
datePickerButton | ||
timePickerButton | ||
} | ||
} | ||
|
||
// MARK: - UI Components | ||
|
||
private var datePickerButton: some View { | ||
PickerButton( | ||
type: .date, | ||
title: formattedDate, | ||
titleColor: .gray02, | ||
width: 124, | ||
action: { datePickerViewModel.togglePresentation() }, | ||
viewModel: datePickerViewModel | ||
) | ||
.sheet( | ||
isPresented: $datePickerViewModel.isPresented, | ||
onDismiss: { datePickerViewModel.dismiss() } | ||
) { | ||
BaseSheetView( | ||
selection: sectionType == .start ? $viewModel.startsDate : $viewModel.endsDate, | ||
isPresented: $datePickerViewModel.isPresented, | ||
type: .date, | ||
isStartsDate: sectionType == .start, | ||
minimumDate: sectionType == .end ? viewModel.startsDate : nil | ||
) | ||
} | ||
} | ||
|
||
private var timePickerButton: some View { | ||
PickerButton( | ||
type: .time, | ||
title: formattedTime, | ||
titleColor: .gray02, | ||
width: 96, | ||
action: { timePickerViewModel.togglePresentation() }, | ||
viewModel: timePickerViewModel | ||
) | ||
.disabled(viewModel.isAllDay) | ||
.opacity(viewModel.isAllDay ? 0.3 : 1.0) | ||
.sheet( | ||
isPresented: $timePickerViewModel.isPresented, | ||
onDismiss: { timePickerViewModel.dismiss() } | ||
) { | ||
BaseSheetView( | ||
selection: sectionType == .start ? $viewModel.selectedStartTime : $viewModel.selectedEndTime, | ||
isPresented: $timePickerViewModel.isPresented, | ||
type: .time, | ||
onDismiss: viewModel.confirmSelection | ||
) | ||
} | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
private var formattedDate: String { | ||
let date = | ||
sectionType == .start | ||
? viewModel.startsDate | ||
: viewModel.endsDate | ||
|
||
return date.formattedDate(with: "MMM d, yyyy") | ||
} | ||
|
||
private var formattedTime: String { | ||
sectionType == .start | ||
? viewModel.formattedStartTime | ||
: viewModel.formattedEndTime | ||
} | ||
} |