Skip to content

Commit

Permalink
naive search
Browse files Browse the repository at this point in the history
  • Loading branch information
thoamsy committed Nov 25, 2020
1 parent 9107a4f commit a8c7f93
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 32 deletions.
12 changes: 6 additions & 6 deletions SFIconsPicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
591B6E99256BFB9000CBC59A /* SFIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 591B6E97256BFB9000CBC59A /* SFIcons.swift */; };
597BFE922568BEB000635149 /* SFIconsPickerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597BFE7F2568BEAE00635149 /* SFIconsPickerApp.swift */; };
597BFE932568BEB000635149 /* SFIconsPickerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597BFE7F2568BEAE00635149 /* SFIconsPickerApp.swift */; };
597BFE942568BEB000635149 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597BFE802568BEAE00635149 /* ContentView.swift */; };
597BFE952568BEB000635149 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597BFE802568BEAE00635149 /* ContentView.swift */; };
597BFE942568BEB000635149 /* SFCategoryIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597BFE802568BEAE00635149 /* SFCategoryIcons.swift */; };
597BFE952568BEB000635149 /* SFCategoryIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 597BFE802568BEAE00635149 /* SFCategoryIcons.swift */; };
597BFE962568BEB000635149 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 597BFE812568BEB000635149 /* Assets.xcassets */; };
597BFE972568BEB000635149 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 597BFE812568BEB000635149 /* Assets.xcassets */; };
59A8238A256D069D00360C98 /* Searchbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59A82389256D069D00360C98 /* Searchbar.swift */; };
Expand All @@ -25,7 +25,7 @@
591B6E91256BFB7400CBC59A /* CategoriesList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoriesList.swift; sourceTree = "<group>"; };
591B6E97256BFB9000CBC59A /* SFIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SFIcons.swift; sourceTree = "<group>"; };
597BFE7F2568BEAE00635149 /* SFIconsPickerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SFIconsPickerApp.swift; sourceTree = "<group>"; };
597BFE802568BEAE00635149 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
597BFE802568BEAE00635149 /* SFCategoryIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SFCategoryIcons.swift; sourceTree = "<group>"; };
597BFE812568BEB000635149 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
597BFE862568BEB000635149 /* SFIconsPicker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SFIconsPicker.app; sourceTree = BUILT_PRODUCTS_DIR; };
597BFE892568BEB000635149 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -76,7 +76,7 @@
children = (
591B6E96256BFB7B00CBC59A /* Model */,
597BFE7F2568BEAE00635149 /* SFIconsPickerApp.swift */,
597BFE802568BEAE00635149 /* ContentView.swift */,
597BFE802568BEAE00635149 /* SFCategoryIcons.swift */,
59A82389256D069D00360C98 /* Searchbar.swift */,
597BFE812568BEB000635149 /* Assets.xcassets */,
591B6E91256BFB7400CBC59A /* CategoriesList.swift */,
Expand Down Expand Up @@ -210,7 +210,7 @@
591B6E92256BFB7400CBC59A /* CategoriesList.swift in Sources */,
591B6E98256BFB9000CBC59A /* SFIcons.swift in Sources */,
59A8238A256D069D00360C98 /* Searchbar.swift in Sources */,
597BFE942568BEB000635149 /* ContentView.swift in Sources */,
597BFE942568BEB000635149 /* SFCategoryIcons.swift in Sources */,
597BFE922568BEB000635149 /* SFIconsPickerApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -222,7 +222,7 @@
591B6E93256BFB7400CBC59A /* CategoriesList.swift in Sources */,
591B6E99256BFB9000CBC59A /* SFIcons.swift in Sources */,
59A8238B256D069D00360C98 /* Searchbar.swift in Sources */,
597BFE952568BEB000635149 /* ContentView.swift in Sources */,
597BFE952568BEB000635149 /* SFCategoryIcons.swift in Sources */,
597BFE932568BEB000635149 /* SFIconsPickerApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Binary file not shown.
39 changes: 28 additions & 11 deletions Shared/CategoriesList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,43 @@
import SwiftUI

struct CategoriesList: View {
@ObservedObject var sfIcons = SFIconsList()
@ObservedObject var sfIcons = SFIconsModel()
@State private var search = ""
@State private var searchedIcons: [String] = []

var allIcons: [String] {
sfIcons.icons.categories[0].icons
}

var body: some View {
return NavigationView {
if sfIcons.fetching {
ProgressView()
} else {
List {
Section(header: Text("Categories")) {
ForEach(sfIcons.icons.categories, id: \.0) { (category, categoryIcon, icons) in
NavigationLink(
destination: ContentView(icons: icons)
.navigationBarTitle(category, displayMode: .inline)
) {
Label(category, systemImage: categoryIcon)
}.frame(height: 44)
VStack {
Searchbar(text: $search, onCommit: { keyword in
searchedIcons = allIcons.filter { $0.contains(keyword) }
}, onCancel: {
searchedIcons = []
})
if !searchedIcons.isEmpty {
SFCategoryIcons(icons: searchedIcons)
} else {
List {
Section(header: Text("Categories")) {
ForEach(sfIcons.icons.categories, id: \.0) { (category, categoryIcon, icons) in
NavigationLink(
destination: SFCategoryIcons(icons: icons)
.navigationBarTitle(category, displayMode: .inline)
) {
Label(category, systemImage: categoryIcon)
}.frame(height: 44)
}
}
}
.listStyle(InsetGroupedListStyle())
}
}
.listStyle(InsetGroupedListStyle())
.navigationTitle("Symbols")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Shared/Model/SFIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ enum Associate: String {
}


class SFIconsList: ObservableObject {
class SFIconsModel: ObservableObject {
let requestURL = URL(string: "https://raw.githubusercontent.com/thoamsy/sf-icon-names/master/sf-name.json")!

@Published var icons: SFIcons = SFIcons() {
Expand Down
14 changes: 6 additions & 8 deletions Shared/ContentView.swift → Shared/SFCategoryIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SwiftUI
import Combine


struct ContentView: View {
struct SFCategoryIcons: View {
let icons: [String]
@State private var tintColor: Color = .primary
@State var selectedIndex = -1
Expand All @@ -20,27 +20,25 @@ struct ContentView: View {
Image(systemName: name)
.renderingMode(.template)
.foregroundColor(tintColor)
.onTapGesture {
selectedIndex = index
}
// .onTapGesture {
// selectedIndex = index
// }
.frame(width: 80, height: 80)
.border(Color(UIColor.separator))
.cornerRadius(4)
.padding([.bottom], 4)
.contextMenu {
Text("Copy Symbol Name")
Button("YES", action: {})
// Button(action: {
// UIPasteboard.general.string = name
// }, label: {
// Text("Copy Symbol Name")
// Label("Copy Symbol Name", systemImage: "doc.on.doc")
// })
}

Text(name).foregroundColor(.primary).font(.footnote).lineLimit(2)
}
.frame(height: 120)

// .background(index == selectedIndex ? Color(UIColor.link) : Color(UIColor.secondarySystemGroupedBackground))
}
.font(.title2)
.padding()
Expand Down
1 change: 0 additions & 1 deletion Shared/SFIconsPickerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct SFIconsPickerApp: App {
var body: some Scene {
WindowGroup {
CategoriesList()
// ContentView()
}
}
}
18 changes: 13 additions & 5 deletions Shared/Searchbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ import SwiftUI

struct Searchbar: View {
@Binding var text: String
// @Environment(\.colorScheme) var scheme: ColorScheme
var onCommit: (_ commit: String) -> Void
var onCancel: () -> Void

@State private var isEditing = false

var body: some View {
HStack {
HStack {
Image(systemName: "magnifyingglass")
TextField("Search ...", text: $text, onEditingChanged: { _ in
isEditing = true
})
TextField(
"Search ...",
text: $text,
onEditingChanged: { _ in isEditing = true }) {
onCommit(text.lowercased())
}
.textCase(.lowercase)
Button(action: {
text = ""
}) {
Expand All @@ -38,6 +43,7 @@ struct Searchbar: View {
UIApplication.shared.endEditing(true)
isEditing = false
text = ""
onCancel()
}) {
Text("Cancel")
}
Expand All @@ -50,7 +56,9 @@ struct Searchbar: View {

struct Searchbar_Previews: PreviewProvider {
static var previews: some View {
Searchbar(text: .constant("foobar"))
Searchbar(text: .constant("foobar"), onCommit: {
print($0)
}, onCancel: {})
}
}

Expand Down

0 comments on commit a8c7f93

Please sign in to comment.