Skip to content

Commit

Permalink
Add searchable if variant
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed Dec 18, 2024
1 parent 15656e5 commit eb0f64a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ As a positive side-effect of this change, `LinkText` can now be used on all plat
### ✨ Features

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

### 💡 Behavior changes

Expand Down
26 changes: 25 additions & 1 deletion Sources/SwiftUIKit/Extensions/View+Conditionals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public extension View {
self
}
}

/// Make the view searchable if the condition is `true`.
@ViewBuilder
func searchable(
Expand All @@ -38,6 +38,30 @@ public extension View {
}
}

#if !os(watchOS) && !os(tvOS)
/// Make the view searchable if the condition is `true`.
@available(iOS 17.0, macOS 14.0, tvOS 17.0, *)
@ViewBuilder
func searchable(
if condition: Bool,
text: Binding<String>,
isPresented: Binding<Bool>,
placement: SearchFieldPlacement = .automatic,
prompt: Text? = nil
) -> some View {
if condition {
self.searchable(
text: text,
isPresented: isPresented,
placement: placement,
prompt: prompt
)
} else {
self
}
}
#endif

/// Show the view if the provided condition is `true`.
func visible(if condition: Bool) -> some View {
hidden(if: !condition)
Expand Down

0 comments on commit eb0f64a

Please sign in to comment.