Skip to content

Commit f083389

Browse files
committed
Remove unnecessary HStack and public modifiers. Add preview for swipe to remove.
1 parent 9f3fadd commit f083389

File tree

5 files changed

+83
-53
lines changed

5 files changed

+83
-53
lines changed

Core/Core/Common/CommonUI/InstUI/Utils/SwipeToRemove.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,36 @@ private struct SwipeToRemoveModifier<Label: View>: ViewModifier {
192192
}
193193
}
194194
}
195+
196+
#if DEBUG
197+
198+
#Preview {
199+
ScrollView {
200+
VStack(spacing: 0) {
201+
ForEach(0..<5) { index in
202+
VStack(alignment: .leading, spacing: 4) {
203+
Text(verbatim: "Todo Item \(index + 1)")
204+
.font(.headline)
205+
Text(verbatim: "Swipe left to mark as done")
206+
.font(.subheadline)
207+
.foregroundStyle(.secondary)
208+
}
209+
.frame(maxWidth: .infinity, alignment: .leading)
210+
.padding()
211+
.background(.backgroundLightest)
212+
.swipeToRemove(
213+
backgroundColor: .backgroundSuccess,
214+
onSwipe: {},
215+
label: {
216+
Image(systemName: "checkmark.circle.fill")
217+
.font(.title)
218+
.foregroundStyle(.textLightest)
219+
.paddingStyle(.horizontal, .standard)
220+
}
221+
)
222+
}
223+
}
224+
}
225+
}
226+
227+
#endif

Core/Core/Features/Todos/Model/TodoInteractor.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,23 @@
1919
import Foundation
2020
import Combine
2121

22-
public protocol TodoInteractor {
22+
protocol TodoInteractor {
2323
var todoGroups: CurrentValueSubject<[TodoGroupViewModel], Never> { get }
2424
func refresh(ignoreCache: Bool) -> AnyPublisher<Void, Error>
2525
func markItemAsDone(_ item: TodoItemViewModel, done: Bool) -> AnyPublisher<Void, Error>
2626
}
2727

28-
public final class TodoInteractorLive: TodoInteractor {
29-
public var todoGroups = CurrentValueSubject<[TodoGroupViewModel], Never>([])
28+
final class TodoInteractorLive: TodoInteractor {
29+
var todoGroups = CurrentValueSubject<[TodoGroupViewModel], Never>([])
3030

3131
private let env: AppEnvironment
32-
3332
private var subscriptions = Set<AnyCancellable>()
3433

3534
init(env: AppEnvironment) {
3635
self.env = env
3736
}
3837

39-
public func refresh(ignoreCache: Bool) -> AnyPublisher<Void, Error> {
38+
func refresh(ignoreCache: Bool) -> AnyPublisher<Void, Error> {
4039
let startDate = Clock.now.addDays(-28)
4140
let endDate = Clock.now.addDays(28)
4241
let currentUserID = env.currentSession?.userID
@@ -77,7 +76,7 @@ public final class TodoInteractorLive: TodoInteractor {
7776
.eraseToAnyPublisher()
7877
}
7978

80-
public func markItemAsDone(_ item: TodoItemViewModel, done: Bool) -> AnyPublisher<Void, Error> {
79+
func markItemAsDone(_ item: TodoItemViewModel, done: Bool) -> AnyPublisher<Void, Error> {
8180
let useCase = MarkPlannableItemDone(
8281
plannableId: item.plannableId,
8382
plannableType: item.plannableType,
@@ -119,10 +118,10 @@ public final class TodoInteractorLive: TodoInteractor {
119118

120119
#if DEBUG
121120

122-
public final class TodoInteractorPreview: TodoInteractor {
123-
public let todoGroups: CurrentValueSubject<[TodoGroupViewModel], Never>
121+
final class TodoInteractorPreview: TodoInteractor {
122+
let todoGroups: CurrentValueSubject<[TodoGroupViewModel], Never>
124123

125-
public init(todoGroups: [TodoGroupViewModel]? = nil) {
124+
init(todoGroups: [TodoGroupViewModel]? = nil) {
126125
if let todoGroups {
127126
self.todoGroups = CurrentValueSubject<[TodoGroupViewModel], Never>(todoGroups)
128127
return
@@ -147,11 +146,11 @@ public final class TodoInteractorPreview: TodoInteractor {
147146
self.todoGroups = CurrentValueSubject<[TodoGroupViewModel], Never>([todayGroup, tomorrowGroup])
148147
}
149148

150-
public func refresh(ignoreCache: Bool) -> AnyPublisher<Void, Error> {
149+
func refresh(ignoreCache: Bool) -> AnyPublisher<Void, Error> {
151150
Publishers.typedJust(())
152151
}
153152

154-
public func markItemAsDone(_ item: TodoItemViewModel, done: Bool) -> AnyPublisher<Void, Error> {
153+
func markItemAsDone(_ item: TodoItemViewModel, done: Bool) -> AnyPublisher<Void, Error> {
155154
Publishers.typedJust(())
156155
}
157156
}

Core/Core/Features/Todos/View/TodoListItemCell.swift

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,36 @@ struct TodoListItemCell: View {
2929
let isSwiping: Binding<Bool>?
3030

3131
var body: some View {
32-
VStack(spacing: 0) {
33-
HStack(spacing: 0) {
34-
TodoItemContentView(item: item, isCompactLayout: false)
32+
HStack(spacing: 0) {
33+
TodoItemContentView(item: item, isCompactLayout: false)
3534

36-
checkboxButton
37-
.paddingStyle(.leading, .cellAccessoryPadding)
38-
.accessibilityHidden(true)
39-
}
40-
.padding(.vertical, 8)
41-
.paddingStyle(.trailing, .standard)
42-
.background(.backgroundLightest)
43-
.contentShape(Rectangle())
44-
.onTapGesture {
45-
guard isSwiping?.wrappedValue != true else { return }
46-
onTap(item, viewController)
47-
}
48-
.accessibilityElement(children: .combine)
49-
.accessibilityAddTraits(.isButton)
50-
.accessibilityActions {
51-
if let label = item.markAsDoneAccessibilityLabel {
52-
Button(label) {
53-
onMarkAsDone(item)
54-
}
35+
checkboxButton
36+
.paddingStyle(.leading, .cellAccessoryPadding)
37+
.accessibilityHidden(true)
38+
}
39+
.padding(.vertical, 8)
40+
.paddingStyle(.trailing, .standard)
41+
.background(.backgroundLightest)
42+
.contentShape(Rectangle())
43+
.onTapGesture {
44+
guard isSwiping?.wrappedValue != true else { return }
45+
onTap(item, viewController)
46+
}
47+
.accessibilityElement(children: .combine)
48+
.accessibilityAddTraits(.isButton)
49+
.accessibilityActions {
50+
if let label = item.markAsDoneAccessibilityLabel {
51+
Button(label) {
52+
onMarkAsDone(item)
5553
}
5654
}
57-
.swipeToRemove(
58-
backgroundColor: .backgroundSuccess,
59-
isSwiping: isSwiping,
60-
onSwipe: { onSwipeMarkAsDone(item) },
61-
label: { swipeActionView }
62-
)
6355
}
56+
.swipeToRemove(
57+
backgroundColor: .backgroundSuccess,
58+
isSwiping: isSwiping,
59+
onSwipe: { onSwipeMarkAsDone(item) },
60+
label: { swipeActionView }
61+
)
6462
}
6563

6664
private var swipeActionView: some View {

Core/Core/Features/Todos/View/TodoListScreen.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818

1919
import SwiftUI
2020

21-
public struct TodoListScreen: View {
21+
struct TodoListScreen: View {
2222
@Environment(\.viewController) private var viewController
2323
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
2424
@ObservedObject var viewModel: TodoListViewModel
2525
/// The sticky section header grows horizontally, so we need to increase paddings here not to let the header overlap the cell content.
2626
@ScaledMetric private var uiScale: CGFloat = 1
2727
@State private var isCellSwiping = false
2828

29-
public init(viewModel: TodoListViewModel) {
29+
init(viewModel: TodoListViewModel) {
3030
self.viewModel = viewModel
3131
}
3232

33-
public var body: some View {
33+
var body: some View {
3434
InstUI.BaseScreen(
3535
state: viewModel.state,
3636
config: viewModel.screenConfig,

Core/Core/Features/Todos/ViewModel/TodoGroupViewModel.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
import Foundation
2020

21-
public struct TodoGroupViewModel: Identifiable, Equatable, Comparable {
22-
public let id: String
23-
public let date: Date
24-
public let items: [TodoItemViewModel]
25-
public let weekdayAbbreviation: String
26-
public let dayNumber: String
27-
public let isToday: Bool
28-
public let displayDate: String
29-
public let accessibilityLabel: String
21+
struct TodoGroupViewModel: Identifiable, Equatable, Comparable {
22+
let id: String
23+
let date: Date
24+
let items: [TodoItemViewModel]
25+
let weekdayAbbreviation: String
26+
let dayNumber: String
27+
let isToday: Bool
28+
let displayDate: String
29+
let accessibilityLabel: String
3030

31-
public init(date: Date, items: [TodoItemViewModel]) {
31+
init(date: Date, items: [TodoItemViewModel]) {
3232
self.id = date.isoString()
3333
self.date = date
3434
self.items = items
@@ -45,7 +45,7 @@ public struct TodoGroupViewModel: Identifiable, Equatable, Comparable {
4545

4646
// MARK: - Comparable
4747

48-
public static func < (lhs: TodoGroupViewModel, rhs: TodoGroupViewModel) -> Bool {
48+
static func < (lhs: TodoGroupViewModel, rhs: TodoGroupViewModel) -> Bool {
4949
lhs.date < rhs.date
5050
}
5151
}

0 commit comments

Comments
 (0)