Swiftpack.co - stleamist/NavigationSearchBarModifier as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by stleamist.
stleamist/NavigationSearchBarModifier v0.3.0
A clean way to attach a search bar with a scope bar in SwiftUI.
⭐️ 24
🕓 3 years ago
iOS
.package(url: "https://github.com/stleamist/NavigationSearchBarModifier.git", from: "v0.3.0")

NavigationSearchBarModifier

Build for the latest iOS Build for iOS 14 beta

A clean way to attach a search bar with a scope bar in SwiftUI.

Usage

import SwiftUI
import NavigationSearchBarModifier

struct GroceryList: View {
    
    let groceries: [Grocery]
    @State private var searchControllerIsPresented = false
    @State private var searchTerm: String?
    private var scopes: [String]? = ["Fruit", "Vegetable"]
    @State private var selectedScope: Int = 0
    
    private var predicate: (Grocery) -> Bool {
        if let searchTerm = searchTerm {
            return { grocery in
                grocery.name.localizedCaseInsensitiveContains(searchTerm)
            }
        } else {
            return { _ in true }
        }
    }
    
    var body: some View {
        NavigationView {
            List(groceries.filter(predicate)) { grocery in
                Text(grocery.name)
            }
            .navigationBarTitle("Groceries")
            .navigationSearchBar(
                searchControllerIsPresented: $searchControllerIsPresented,
                searchTerm: $searchTerm,
                searchScopes: scopes,
                selectedSearchScope: $selectedScope,
                hidesWhenScrolling: true
            )
        }
    }
}

GitHub

link
Stars: 24
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics