From 420544254ca157fd8ce147021abb5070b985f9d4 Mon Sep 17 00:00:00 2001 From: Matt Smollinger Date: Fri, 15 Jul 2022 09:23:59 -0400 Subject: [PATCH 1/2] Expose text field background color to enable dark mode support --- .../InstantSearchSwiftUI/View/SearchBar.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Sources/InstantSearchSwiftUI/View/SearchBar.swift b/Sources/InstantSearchSwiftUI/View/SearchBar.swift index c6f7958d..b5c9d418 100644 --- a/Sources/InstantSearchSwiftUI/View/SearchBar.swift +++ b/Sources/InstantSearchSwiftUI/View/SearchBar.swift @@ -21,6 +21,10 @@ public struct SearchBar: View { /// Whether the search bar is in the editing state @Binding public var isEditing: Bool + + /// Customizable background color for the main text field + @State public var searchBarBackgroundColor = + Color(.sRGB, red: 239/255, green: 239/255, blue: 240/255, opacity: 1) private let placeholder: String private var onSubmit: () -> Void @@ -66,15 +70,15 @@ public struct SearchBar: View { .onTapGesture { isEditing = true } - .background(Color(.sRGB, red: 239/255, green: 239/255, blue: 240/255, opacity: 1)) + .background(searchBarBackgroundColor) .cornerRadius(10) if isEditing { - Button(action: { - isEditing = false - }, - label: { - Text("Cancel") - }) + + Button { + isEditing = false + } label: { + Text("Cancel") + } .padding(.trailing, 10) .transition(.move(edge: .trailing)) .animation(.default) From 2dc9a64658c15dfe60f17f63aa173bfc0c81c912 Mon Sep 17 00:00:00 2001 From: Joe Cotellese Date: Fri, 15 Jul 2022 13:40:35 -0400 Subject: [PATCH 2/2] update to include foreground color --- Sources/InstantSearchSwiftUI/View/SearchBar.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/InstantSearchSwiftUI/View/SearchBar.swift b/Sources/InstantSearchSwiftUI/View/SearchBar.swift index b5c9d418..cb1cf7b6 100644 --- a/Sources/InstantSearchSwiftUI/View/SearchBar.swift +++ b/Sources/InstantSearchSwiftUI/View/SearchBar.swift @@ -26,6 +26,8 @@ public struct SearchBar: View { @State public var searchBarBackgroundColor = Color(.sRGB, red: 239/255, green: 239/255, blue: 240/255, opacity: 1) + @State public var searchBarForegroundColor = Color(.gray) + private let placeholder: String private var onSubmit: () -> Void @@ -51,7 +53,7 @@ public struct SearchBar: View { .overlay( HStack { Image(systemName: "magnifyingglass") - .foregroundColor(.gray) + .foregroundColor(searchBarForegroundColor) .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading) .padding(.leading, 8) .disabled(true) @@ -61,7 +63,7 @@ public struct SearchBar: View { }, label: { Image(systemName: "multiply.circle.fill") - .foregroundColor(.gray) + .foregroundColor(searchBarForegroundColor) .padding(.trailing, 8) }) }