Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [JIRA: HCPSDKFIORIUIKIT-2497] [New Color System] Search Bar (#657)
- Loading branch information
1 parent
90e8de7
commit 27a1aef
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Apps/Examples/Examples/FioriSwiftUICore/SearchBar/SearchIconAndPlaceholder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |