Skip to content

Commit eb0f64a

Browse files
committed
Add searchable if variant
1 parent 15656e5 commit eb0f64a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ As a positive side-effect of this change, `LinkText` can now be used on all plat
1515
### ✨ Features
1616

1717
* `LinkText` can now be used on all platforms.
18+
* `View+Conditionals` has a new `searchable(if:...)` variant.
1819

1920
### 💡 Behavior changes
2021

Sources/SwiftUIKit/Extensions/View+Conditionals.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public extension View {
1919
self
2020
}
2121
}
22-
22+
2323
/// Make the view searchable if the condition is `true`.
2424
@ViewBuilder
2525
func searchable(
@@ -38,6 +38,30 @@ public extension View {
3838
}
3939
}
4040

41+
#if !os(watchOS) && !os(tvOS)
42+
/// Make the view searchable if the condition is `true`.
43+
@available(iOS 17.0, macOS 14.0, tvOS 17.0, *)
44+
@ViewBuilder
45+
func searchable(
46+
if condition: Bool,
47+
text: Binding<String>,
48+
isPresented: Binding<Bool>,
49+
placement: SearchFieldPlacement = .automatic,
50+
prompt: Text? = nil
51+
) -> some View {
52+
if condition {
53+
self.searchable(
54+
text: text,
55+
isPresented: isPresented,
56+
placement: placement,
57+
prompt: prompt
58+
)
59+
} else {
60+
self
61+
}
62+
}
63+
#endif
64+
4165
/// Show the view if the provided condition is `true`.
4266
func visible(if condition: Bool) -> some View {
4367
hidden(if: !condition)

0 commit comments

Comments
 (0)