Skip to content

Commit 5e47ed5

Browse files
committed
Refactor RuntimeObjectsList from AllRuntimeObjectsView
1 parent 132d2f4 commit 5e47ed5

3 files changed

Lines changed: 64 additions & 38 deletions

File tree

HeaderViewer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
FA53C69F2B8BF82000FC1A15 /* GatherScreenshots.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA53C69E2B8BF82000FC1A15 /* GatherScreenshots.swift */; };
11+
FA6BEDCB2BD5941500D20C6F /* RuntimeObjectsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6BEDCA2BD5941500D20C6F /* RuntimeObjectsView.swift */; };
1112
FA9687E92B8338E100123476 /* NamedNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9687E82B8338E100123476 /* NamedNode.swift */; };
1213
FA9687EB2B833C1700123476 /* RuntimeObjectType.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9687EA2B833C1700123476 /* RuntimeObjectType.swift */; };
1314
FA9687ED2B833C3200123476 /* RuntimeObjectDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA9687EC2B833C3200123476 /* RuntimeObjectDetail.swift */; };
@@ -73,6 +74,7 @@
7374
FA53C6932B8BF70200FC1A15 /* HeaderViewerUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HeaderViewerUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
7475
FA53C69E2B8BF82000FC1A15 /* GatherScreenshots.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GatherScreenshots.swift; sourceTree = "<group>"; };
7576
FA53C6A02B8BFC0E00FC1A15 /* HeaderViewerUITests.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HeaderViewerUITests.entitlements; sourceTree = "<group>"; };
77+
FA6BEDCA2BD5941500D20C6F /* RuntimeObjectsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuntimeObjectsView.swift; sourceTree = "<group>"; };
7678
FA9687E72B82E37E00123476 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
7779
FA9687E82B8338E100123476 /* NamedNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NamedNode.swift; sourceTree = "<group>"; };
7880
FA9687EA2B833C1700123476 /* RuntimeObjectType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuntimeObjectType.swift; sourceTree = "<group>"; };
@@ -144,6 +146,7 @@
144146
children = (
145147
FAD661F72B81D1210000D2A6 /* HeaderViewerApp.swift */,
146148
FAD661F92B81D1210000D2A6 /* ContentView.swift */,
149+
FA6BEDCA2BD5941500D20C6F /* RuntimeObjectsView.swift */,
147150
FAAA8C162B8B072100BD85B4 /* ListView.swift */,
148151
FAAA8C122B857A1300BD85B4 /* RuntimeListings.swift */,
149152
FAAA8C0E2B85788700BD85B4 /* ImageClassPicker.swift */,
@@ -308,6 +311,7 @@
308311
isa = PBXSourcesBuildPhase;
309312
buildActionMask = 2147483647;
310313
files = (
314+
FA6BEDCB2BD5941500D20C6F /* RuntimeObjectsView.swift in Sources */,
311315
FAAA8C0F2B85788700BD85B4 /* ImageClassPicker.swift in Sources */,
312316
FA9687E92B8338E100123476 /* NamedNode.swift in Sources */,
313317
FA9687F32B8433B900123476 /* SemanticStringView.swift in Sources */,

HeaderViewer/ContentView.swift

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,6 @@ struct ContentRootView: View {
5959
}
6060
}
6161

62-
private enum RuntimeTypeSearchScope: Hashable {
63-
case all
64-
case classes
65-
case protocols
66-
}
67-
68-
private extension RuntimeTypeSearchScope {
69-
var includesClasses: Bool {
70-
switch self {
71-
case .all: true
72-
case .classes: true
73-
case .protocols: false
74-
}
75-
}
76-
var includesProtocols: Bool {
77-
switch self {
78-
case .all: true
79-
case .classes: false
80-
case .protocols: true
81-
}
82-
}
83-
}
84-
8562
private class AllRuntimeObjectsViewModel: ObservableObject {
8663
let runtimeListings: RuntimeListings = .shared
8764

@@ -137,20 +114,9 @@ private struct AllRuntimeObjectsView: View {
137114
}
138115

139116
var body: some View {
140-
let runtimeObjects = viewModel.runtimeObjects
141-
ListView(runtimeObjects, selection: $selectedObject) { runtimeObject in
142-
RuntimeObjectRow(type: runtimeObject)
143-
}
144-
.id(runtimeObjects) // don't try to diff the List
145-
.searchable(text: $viewModel.searchString)
146-
.autocorrectionDisabled() // turn of auto-correct for the search field
147-
.searchScopes($viewModel.searchScope) {
148-
Text("All")
149-
.tag(RuntimeTypeSearchScope.all)
150-
Text("Classes")
151-
.tag(RuntimeTypeSearchScope.classes)
152-
Text("Protocols")
153-
.tag(RuntimeTypeSearchScope.protocols)
154-
}
117+
RuntimeObjectsList(
118+
runtimeObjects: viewModel.runtimeObjects, selectedObject: $selectedObject,
119+
searchString: $viewModel.searchString, searchScope: $viewModel.searchScope
120+
)
155121
}
156122
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// RuntimeObjectsView.swift
3+
// HeaderViewer
4+
//
5+
// Created by Leptos on 4/21/24.
6+
//
7+
8+
import SwiftUI
9+
10+
enum RuntimeTypeSearchScope: Hashable {
11+
case all
12+
case classes
13+
case protocols
14+
}
15+
16+
extension RuntimeTypeSearchScope {
17+
var includesClasses: Bool {
18+
switch self {
19+
case .all: true
20+
case .classes: true
21+
case .protocols: false
22+
}
23+
}
24+
var includesProtocols: Bool {
25+
switch self {
26+
case .all: true
27+
case .classes: false
28+
case .protocols: true
29+
}
30+
}
31+
}
32+
33+
struct RuntimeObjectsList: View {
34+
let runtimeObjects: [RuntimeObjectType] // caller's responsibility to filter this
35+
36+
@Binding var selectedObject: RuntimeObjectType?
37+
@Binding var searchString: String
38+
@Binding var searchScope: RuntimeTypeSearchScope
39+
40+
var body: some View {
41+
ListView(runtimeObjects, selection: $selectedObject) { runtimeObject in
42+
RuntimeObjectRow(type: runtimeObject)
43+
}
44+
.id(runtimeObjects) // don't try to diff the List
45+
.searchable(text: $searchString)
46+
.autocorrectionDisabled() // turn of auto-correct for the search field
47+
.searchScopes($searchScope) {
48+
Text("All")
49+
.tag(RuntimeTypeSearchScope.all)
50+
Text("Classes")
51+
.tag(RuntimeTypeSearchScope.classes)
52+
Text("Protocols")
53+
.tag(RuntimeTypeSearchScope.protocols)
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)