Skip to content

Commit

Permalink
[Feat] #51 - DateTimePickerSectionView 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa-e1 committed Jan 18, 2025
1 parent 5052ce3 commit 7959f50
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions Memento-iOS/Memento-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Source/Presentation/Add/AddSchedule/Model/RepeatType.swift,
Source/Presentation/Add/AddSchedule/View/AddEventTitleView.swift,
Source/Presentation/Add/AddSchedule/View/AddScheduleView.swift,
Source/Presentation/Add/AddSchedule/View/DateTimePickerSectionView.swift,
Source/Presentation/Add/AddSchedule/ViewModel/AddEventTitleViewModel.swift,
Source/Presentation/Add/AddSchedule/ViewModel/DateTimePickerViewModel.swift,
Source/Presentation/Add/Common/PickerButton/Model/PickerButtonType.swift,
Expand Down
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
}
}

0 comments on commit 7959f50

Please sign in to comment.