Skip to content

Commit 3c384d8

Browse files
committed
fixes
1 parent fa50270 commit 3c384d8

File tree

5 files changed

+106
-177
lines changed

5 files changed

+106
-177
lines changed

Sources/Resources/Localizable.xcstrings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
}
9191
}
9292
}
93+
},
94+
"Demo: Replace the renderView computed property in LinkListsContainerView" : {
95+
9396
},
9497
"link-detail-nfc-sharing.device.other" : {
9598
"comment" : "Label for other device in NFC sharing",
@@ -2135,6 +2138,9 @@
21352138
}
21362139
}
21372140
}
2141+
},
2142+
"To use the UIKit implementation, replace this line in LinkListsContainerView:\n\nvar renderView: some View {\n LinkListsRenderView(...)\n}\n\nWith:\n\nvar renderView: some View {\n UIKitLinkListsRenderView(...)\n}\n\nThe API is identical, so no other changes are needed!" : {
2143+
21382144
}
21392145
},
21402146
"version" : "1.0"

Sources/UI/LinkLists/LinkListsContainerView.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ struct LinkListsContainerView: View {
108108

109109
var renderView: some View {
110110
LinkListsRenderView(
111-
pinnedLists: pinnedListDisplayItems,
112-
unpinnedLists: listDisplayItems,
111+
pinnedLists: allPinnedListDisplayItems,
112+
unpinnedLists: allUnpinnedListDisplayItems,
113113
searchText: $searchText,
114114
presentCreateList: {
115115
isCreateListPresented = true
@@ -205,6 +205,19 @@ struct LinkListsContainerView: View {
205205
mapToDisplayItem(list)
206206
}
207207
}
208+
209+
// Unfiltered data for UIKit implementation (which handles search internally)
210+
var allPinnedListDisplayItems: [LinkListsDisplayItem] {
211+
pinnedLists.map { list in
212+
mapToDisplayItem(list)
213+
}
214+
}
215+
216+
var allUnpinnedListDisplayItems: [LinkListsDisplayItem] {
217+
unpinnedLists.map { list in
218+
mapToDisplayItem(list)
219+
}
220+
}
208221

209222
private var filteredPinnedLists: [LinkListModel] {
210223
if searchText.isEmpty {

Sources/UI/LinkLists/LinkListsRenderView.swift

Lines changed: 12 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -19,97 +19,20 @@ struct LinkListsRenderView<Destination: View>: View {
1919
@ViewBuilder let destination: (LinkListsDisplayItem) -> Destination
2020

2121
var body: some View {
22-
VStack(spacing: 16) {
23-
if !pinnedLists.isEmpty {
24-
PinnedLinkListsRenderView(
25-
items: pinnedLists,
26-
editAction: { item in
27-
editListAction(item)
28-
},
29-
unpinAction: { item in
30-
unpinListAction(item)
31-
},
32-
deleteAction: { item in
33-
deleteUnpinnedListAction(item)
34-
},
35-
destination: destination
36-
)
37-
.padding(.horizontal, 16)
38-
}
39-
List {
40-
Section {
41-
ForEach(unpinnedLists, id: \.self) { list in
42-
itemViewForList(list)
43-
}
44-
.onDelete(perform: deleteUnpinnedListsAction)
45-
} header: {
46-
if !pinnedLists.isEmpty {
47-
HStack {
48-
Text(L10n.LinkLists.myListsSection)
49-
.font(.title2)
50-
.fontWeight(.bold)
51-
Spacer()
52-
}
53-
}
54-
}
55-
}
56-
}
57-
.background(Color(UIColor.systemGroupedBackground))
58-
.headerProminence(.increased)
59-
.navigationTitle(L10n.App.title)
60-
.searchable(text: $searchText, prompt: L10n.Search.listsAndLinks)
61-
.overlay {
62-
if pinnedLists.isEmpty && unpinnedLists.isEmpty {
63-
ContentUnavailableView(
64-
L10n.LinkLists.noListsTitle,
65-
systemSymbol: .trayFill,
66-
description: Text(L10n.LinkLists.noListsDescription)
67-
)
68-
}
69-
}
70-
.toolbar {
71-
if !pinnedLists.isEmpty || !unpinnedLists.isEmpty {
72-
ToolbarItem(placement: .navigationBarTrailing) {
73-
EditButton()
74-
}
75-
}
76-
ToolbarItem(placement: .bottomBar) {
77-
Button(
78-
action: {
79-
presentCreateLink()
80-
},
81-
label: {
82-
Label(L10n.LinkLists.CreateLink.title, systemSymbol: .plusCircleFill)
83-
.bold()
84-
.imageScale(.large)
85-
.labelStyle(.titleAndIcon)
86-
}
87-
)
88-
.buttonStyle(.borderless)
89-
.accessibilityLabel(L10n.LinkLists.CreateLink.Accessibility.label)
90-
.accessibilityHint(L10n.LinkLists.CreateLink.Accessibility.hint)
91-
}
92-
ToolbarItem(placement: .bottomBar) {
93-
Spacer()
94-
}
95-
ToolbarItem(placement: .bottomBar) {
96-
Button(
97-
action: {
98-
presentCreateList()
99-
},
100-
label: {
101-
Label(L10n.LinkLists.CreateList.title, systemSymbol: .plusCircleFill)
102-
.imageScale(.large)
103-
.labelStyle(.titleOnly)
104-
}
105-
)
106-
.buttonStyle(.borderless)
107-
.accessibilityLabel(L10n.LinkLists.CreateList.Accessibility.label)
108-
.accessibilityHint(L10n.LinkLists.CreateList.Accessibility.hint)
109-
}
110-
}
22+
UIKitLinkListsRenderView(
23+
pinnedLists: pinnedLists,
24+
unpinnedLists: unpinnedLists,
25+
presentCreateList: presentCreateList,
26+
presentCreateLink: presentCreateLink,
27+
pinListAction: pinListAction,
28+
unpinListAction: unpinListAction,
29+
deleteUnpinnedListAction: deleteUnpinnedListAction,
30+
editListAction: editListAction,
31+
destination: destination
32+
)
11133
}
11234

35+
// Keep the itemViewForList method for backwards compatibility in case it's used elsewhere
11336
func itemViewForList(_ list: LinkListsDisplayItem) -> some View {
11437
NavigationLink(destination: destination(list)) {
11538
LinkListsItemView(

Sources/UI/LinkLists/UIKitLinkListsRepresentable.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ struct UIKitLinkListsRepresentable: UIViewControllerRepresentable {
7575
private var pinnedLists: [LinkListsDisplayItem]
7676
private var unpinnedLists: [LinkListsDisplayItem]
7777

78-
private var presentCreateList: () -> Void
79-
private var presentCreateLink: () -> Void
80-
78+
private var _presentCreateList: () -> Void
79+
private var _presentCreateLink: () -> Void
80+
8181
private var pinListAction: (LinkListsDisplayItem) -> Void
8282
private var unpinListAction: (LinkListsDisplayItem) -> Void
8383
private var deleteUnpinnedListAction: (LinkListsDisplayItem) -> Void
@@ -98,8 +98,8 @@ struct UIKitLinkListsRepresentable: UIViewControllerRepresentable {
9898
) {
9999
self.pinnedLists = pinnedLists
100100
self.unpinnedLists = unpinnedLists
101-
self.presentCreateList = presentCreateList
102-
self.presentCreateLink = presentCreateLink
101+
self._presentCreateList = presentCreateList
102+
self._presentCreateLink = presentCreateLink
103103
self.pinListAction = pinListAction
104104
self.unpinListAction = unpinListAction
105105
self.deleteUnpinnedListAction = deleteUnpinnedListAction
@@ -120,8 +120,8 @@ struct UIKitLinkListsRepresentable: UIViewControllerRepresentable {
120120
) {
121121
self.pinnedLists = pinnedLists
122122
self.unpinnedLists = unpinnedLists
123-
self.presentCreateList = presentCreateList
124-
self.presentCreateLink = presentCreateLink
123+
self._presentCreateList = presentCreateList
124+
self._presentCreateLink = presentCreateLink
125125
self.pinListAction = pinListAction
126126
self.unpinListAction = unpinListAction
127127
self.deleteUnpinnedListAction = deleteUnpinnedListAction
@@ -132,11 +132,11 @@ struct UIKitLinkListsRepresentable: UIViewControllerRepresentable {
132132
// MARK: - UIKitLinkListsDelegate
133133

134134
func presentCreateList() {
135-
presentCreateList()
135+
_presentCreateList()
136136
}
137137

138138
func presentCreateLink() {
139-
presentCreateLink()
139+
_presentCreateLink()
140140
}
141141

142142
func didSelectCard(with id: UUID) {
@@ -221,4 +221,4 @@ struct UIKitLinkListsRenderView<Destination: View>: View {
221221
)
222222
.sentryTrace("UIKIT_LINK_LISTS_VIEW")
223223
}
224-
}
224+
}

0 commit comments

Comments
 (0)