Skip to content

Commit

Permalink
feat: [JIRA: HCPSDKFIORIUIKIT-2497] [New Color System] Search Bar (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexXiong-dev committed Mar 12, 2024
1 parent 90e8de7 commit 27a1aef
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Apps/Examples/Examples.xcodeproj/project.pbxproj
Expand Up @@ -129,6 +129,7 @@
C18868D32B32580800F865F7 /* ColorEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = C18868D22B32580800F865F7 /* ColorEntity.swift */; };
C1A0FDB32AD893FA0001738E /* SortFilterView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A0FDB22AD893FA0001738E /* SortFilterView+Extensions.swift */; };
C1C764882A818BEC00BCB0F7 /* SortFilterExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1C764872A818BEC00BCB0F7 /* SortFilterExample.swift */; };
E99A025F2B9EC055008A4B77 /* SearchIconAndPlaceholder.swift in Sources */ = {isa = PBXBuildFile; fileRef = E99A025E2B9EC055008A4B77 /* SearchIconAndPlaceholder.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -298,6 +299,7 @@
C18868D22B32580800F865F7 /* ColorEntity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorEntity.swift; sourceTree = "<group>"; };
C1A0FDB22AD893FA0001738E /* SortFilterView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SortFilterView+Extensions.swift"; sourceTree = "<group>"; };
C1C764872A818BEC00BCB0F7 /* SortFilterExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortFilterExample.swift; sourceTree = "<group>"; };
E99A025E2B9EC055008A4B77 /* SearchIconAndPlaceholder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchIconAndPlaceholder.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -721,6 +723,7 @@
C106AD492B33970500FE8B35 /* SearchPromptFontAndColor.swift */,
C18868D22B32580800F865F7 /* ColorEntity.swift */,
C167183B2B477A81005E2629 /* SearchDemos.swift */,
E99A025E2B9EC055008A4B77 /* SearchIconAndPlaceholder.swift */,
);
path = SearchBar;
sourceTree = "<group>";
Expand Down Expand Up @@ -913,6 +916,7 @@
8A5579D124C1293C0098003A /* Settings.swift in Sources */,
8AD9DFB025D49967007448EC /* ContactItemActionItemsExample.swift in Sources */,
8A6D64B125AE658300D2D76C /* ExpHeaderView.swift in Sources */,
E99A025F2B9EC055008A4B77 /* SearchIconAndPlaceholder.swift in Sources */,
B1BA1F922B19AAEE00E6C052 /* TabViewDetailView.swift in Sources */,
B1DD864F2B07441C00D7EDFD /* UIFont+Fiori.swift in Sources */,
B8D4376F25F980340024EE7D /* ObjectCell_Spec_Jan2018.swift in Sources */,
Expand Down
Expand Up @@ -9,6 +9,12 @@ struct SearchDemos: View {
Text("Search text and font")
}

NavigationLink {
SearchIconAndPlaceholder()
} label: {
Text("Search icon and placeholder")
}

NavigationLink {
SearchWithSuggestion()
} label: {
Expand Down
@@ -0,0 +1,48 @@
import FioriThemeManager
import SwiftUI

struct SearchIconAndPlaceholder: View {
@State private var queryString = ""

// following code demonstrate a workaround for styling search bar
// search icon and placeholder
// reference issue: https://developer.apple.com/forums/thread/709773
var body: some View {
NavigationStack {
List(ColorEntity.filterColors(queryString)) { color in
Text(color.name)
.foregroundColor(color.fioriColor)
}
.navigationTitle("Colors")
}
.searchable(text: $queryString, prompt: "Color name")
.navigationBarTitleDisplayMode(.inline)
.onAppear {
UISearchTextField.appearance().backgroundColor = UIColor(Color.preferredColor(.quaternaryFill))
UISearchTextField.appearance().attributedPlaceholder = NSAttributedString(string: "Color name", attributes: [NSAttributedString.Key.foregroundColor: UIColor(Color.preferredColor(.tertiaryLabel))])

let searchImage = UIImage(systemName: "magnifyingglass")?
.withTintColor(UIColor(Color.preferredColor(.tertiaryLabel)), renderingMode: .alwaysOriginal)
.applyingSymbolConfiguration(UIImage.SymbolConfiguration(weight: .semibold))
UISearchBar.appearance().setImage(searchImage, for: .search, state: .normal)

// SwiftUI doesn't support bookmark actions.
// Only show bookmark icon
UISearchBar.appearance().showsBookmarkButton = true
let bookmarkImage = UIImage(systemName: "book")?
.withTintColor(UIColor(Color.preferredColor(.tintColor2)), renderingMode: .alwaysOriginal)
UISearchBar.appearance().setImage(bookmarkImage, for: .bookmark, state: .normal)
}
.onDisappear {
UISearchTextField.appearance().backgroundColor = nil
UISearchTextField.appearance().attributedPlaceholder = nil
UISearchBar.appearance().setImage(nil, for: .search, state: .normal)
UISearchBar.appearance().showsBookmarkButton = false // bookmark hidden
UISearchBar.appearance().setImage(nil, for: .bookmark, state: .normal)
}
}
}

#Preview {
SearchIconAndPlaceholder()
}

0 comments on commit 27a1aef

Please sign in to comment.