Skip to content

Commit

Permalink
Refactoring reminder list to use section headers - Related to #125
Browse files Browse the repository at this point in the history
This resulted in improved memory usage
  • Loading branch information
DamascenoRafael committed Apr 7, 2023
1 parent cea4a4f commit f12aa66
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
8 changes: 4 additions & 4 deletions reminders-menubar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
71032A8F24C21F0F00A8006C /* FormNewReminderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71032A8E24C21F0F00A8006C /* FormNewReminderView.swift */; };
71059DAB25CA5244001F3063 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71059DAA25CA5244001F3063 /* AppDelegate.swift */; };
71059DE125CA5C86001F3063 /* RemindersLauncher.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 71059DA825CA5244001F3063 /* RemindersLauncher.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
710980D22600419F001F69B2 /* UpcomingRemindersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710980D12600419F001F69B2 /* UpcomingRemindersView.swift */; };
710980D22600419F001F69B2 /* UpcomingRemindersContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710980D12600419F001F69B2 /* UpcomingRemindersContent.swift */; };
7115461324C0ADCB007781E2 /* ReminderItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7115461224C0ADCB007781E2 /* ReminderItemView.swift */; };
7115461924C0C280007781E2 /* RemindersService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7115461824C0C280007781E2 /* RemindersService.swift */; };
7119C2F025D85B75002C8013 /* SelectableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7119C2EF25D85B75002C8013 /* SelectableView.swift */; };
Expand Down Expand Up @@ -95,7 +95,7 @@
71059DAA25CA5244001F3063 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
71059DB625CA5245001F3063 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
71059DB725CA5245001F3063 /* RemindersLauncher.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RemindersLauncher.entitlements; sourceTree = "<group>"; };
710980D12600419F001F69B2 /* UpcomingRemindersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpcomingRemindersView.swift; sourceTree = "<group>"; };
710980D12600419F001F69B2 /* UpcomingRemindersContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpcomingRemindersContent.swift; sourceTree = "<group>"; };
7115461224C0ADCB007781E2 /* ReminderItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReminderItemView.swift; sourceTree = "<group>"; };
7115461824C0C280007781E2 /* RemindersService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemindersService.swift; sourceTree = "<group>"; };
71163AFB298A0169008FEDBD /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -327,8 +327,8 @@
71CEBF6728D6291C00B9A3FC /* UpcomingRemindersView */ = {
isa = PBXGroup;
children = (
710980D12600419F001F69B2 /* UpcomingRemindersView.swift */,
71D12FF525EA196F00A1A0E6 /* UpcomingRemindersTitle.swift */,
710980D12600419F001F69B2 /* UpcomingRemindersContent.swift */,
);
path = UpcomingRemindersView;
sourceTree = "<group>";
Expand Down Expand Up @@ -521,7 +521,7 @@
71E7126D2908EBD100DA97BD /* RemoveFocusFromFirstResponder.swift in Sources */,
715B4DD728D59BF2008C6683 /* SettingsBarFilterMenu.swift in Sources */,
71B6D1FB24C6511000E66EDB /* SettingsBarView.swift in Sources */,
710980D22600419F001F69B2 /* UpcomingRemindersView.swift in Sources */,
710980D22600419F001F69B2 /* UpcomingRemindersContent.swift in Sources */,
713F234524C130D400FF0BEC /* ReminderList.swift in Sources */,
7119C2F025D85B75002C8013 /* SelectableView.swift in Sources */,
712C32B624BF939100AC75E2 /* ContentView.swift in Sources */,
Expand Down
8 changes: 5 additions & 3 deletions reminders-menubar/Extensions/NSTableView+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import SwiftUI

// Workaround to present the list without the background transparency
// https://stackoverflow.com/questions/60454752/swiftui-background-color-of-list-mac-os

extension NSTableView {
open override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()

// Workaround to present the list without the background transparency
// https://stackoverflow.com/questions/60454752/swiftui-background-color-of-list-mac-os
backgroundColor = NSColor.clear
enclosingScrollView?.drawsBackground = false

// Removing sticky section header
floatsGroupRows = false
}
}
19 changes: 15 additions & 4 deletions reminders-menubar/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ struct ContentView: View {
if userPreferences.atLeastOneFilterIsSelected {
List {
if userPreferences.showUpcomingReminders {
UpcomingRemindersView()
Section(header: UpcomingRemindersTitle()) {
UpcomingRemindersContent()
}
.modifier(ListSectionSpacing())
}
ForEach(remindersData.filteredReminderLists) { reminderList in
VStack(alignment: .leading) {
CalendarTitle(calendar: reminderList.calendar)
Section(header: CalendarTitle(calendar: reminderList.calendar)) {
let reminders = filteredReminders(reminderList.reminders)
if reminders.isEmpty {
let calendarIsEmpty = reminderList.reminders.isEmpty
Expand All @@ -27,9 +29,10 @@ struct ContentView: View {
ReminderItemView(reminder: reminder)
}
}
.padding(.bottom, 5)
.modifier(ListSectionSpacing())
}
}
.listStyle(.plain)
} else {
VStack(spacing: 4) {
Text(rmbLocalized(.emptyListNoRemindersFilterTitle))
Expand Down Expand Up @@ -57,6 +60,14 @@ struct ContentView: View {
}
}

struct ListSectionSpacing: ViewModifier {
func body(content: Content) -> some View {
return content
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 8, trailing: 0))
.padding(.horizontal, 8)
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView().environmentObject(RemindersData())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import SwiftUI

struct UpcomingRemindersView: View {
struct UpcomingRemindersContent: View {
@EnvironmentObject var remindersData: RemindersData

var body: some View {
VStack(alignment: .leading) {
UpcomingRemindersTitle()
Group{
if remindersData.upcomingReminders.isEmpty {
NoReminderItemsView(emptyList: .noUpcomingReminders)
}
Expand All @@ -16,8 +15,8 @@ struct UpcomingRemindersView: View {
}
}

struct UpcomingRemindersList_Previews: PreviewProvider {
struct UpcomingRemindersContent_Previews: PreviewProvider {
static var previews: some View {
UpcomingRemindersView().environmentObject(RemindersData())
UpcomingRemindersContent().environmentObject(RemindersData())
}
}

0 comments on commit f12aa66

Please sign in to comment.