-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushNotificationSettingsView.swift
More file actions
111 lines (105 loc) · 4.12 KB
/
Copy pathPushNotificationSettingsView.swift
File metadata and controls
111 lines (105 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// PushNotificationSettingsView.swift
// DevLog
//
// Created by opfic on 5/14/25.
//
import SwiftUI
struct PushNotificationSettingsView: View {
@StateObject var viewModel: PushNotificationSettingsViewModel
var body: some View {
List {
Section(content: {
Toggle(isOn:
Binding(
get: { viewModel.state.pushNotificationEnable },
set: { viewModel.send(.setPushNotificationEnable($0)) }
)) {
Text("푸시 알람 활성화")
}
}, footer: {
Text("설정에서의 푸시 알람 설정과 별개입니다.")
})
Section {
ForEach([9, 15, 18, 21], id: \.self) { hour in
if let date = Calendar.current.date(bySettingHour: hour, minute: 0, second: 0, of: Date()) {
HStack {
Text(formattedTimeString(date))
Spacer()
if viewModel.state.pushNotificationHour == hour &&
viewModel.state.pushNotificationMinute == 0 {
Image(systemName: "checkmark")
.foregroundStyle(Color.accentColor)
}
}
.contentShape(Rectangle())
.onTapGesture {
viewModel.send(.setPushNotificationHour(hour))
}
}
}
HStack {
Text("사용자 설정")
Spacer()
Text(formattedTimeString(viewModel.state.pushNotificationTime))
.foregroundStyle(.secondary)
if viewModel.state.pushNotificationMinute != 0 {
Image(systemName: "checkmark")
.foregroundStyle(Color.accentColor)
}
}
.contentShape(Rectangle())
.onTapGesture {
viewModel.send(.setShowTimePicker(true))
}
}
.disabled(!viewModel.state.pushNotificationEnable)
.opacity(viewModel.state.pushNotificationEnable ? 1.0 : 0.2)
}
.listStyle(.insetGrouped)
.navigationTitle("알람")
.onAppear {
viewModel.send(.onAppear)
}
.sheet(isPresented: Binding(
get: { viewModel.state.showTimePicker },
set: { _ in viewModel.send(.setShowTimePicker(false)) }
)) {
DatePicker(
"",
selection: Binding(
get: { viewModel.state.pushNotificationTime },
set: { viewModel.send(.setPushNotificationTime($0)) }
),
displayedComponents: .hourAndMinute
)
.datePickerStyle(.wheel)
.labelsHidden()
.presentationDragIndicator(.hidden)
.presentationDetents([.height(viewModel.state.sheetHeight)])
.onAppear {
UIDatePicker.appearance().minuteInterval = 5
}
.onDisappear {
UIDatePicker.appearance().minuteInterval = 1 // 기본값으로 복원
}
.background(
GeometryReader { geometry in
Color.clear.onAppear {
viewModel.send(.setSheetHeight(geometry.size.height))
}
}
)
}
}
private func formattedTimeString(_ date: Date) -> String {
let minuteValue = Calendar.current.component(.minute, from: date)
let formatStyle: Date.FormatStyle = .dateTime.hour(.twoDigits(amPM: .wide))
if minuteValue == 0 {
return "\(date.formatted(formatStyle))"
}
let hourText = date.formatted(formatStyle)
let minuteText = date.formatted(.dateTime.minute(.twoDigits))
return "\(hourText) \(minuteText)분"
}
}