Expanding Search Bar

Expanding Search Bar

A top bar whose round search button morphs into a full-width, focused search field while the title slides away. Recent searches and suggestions drop in below with a stagger, and Cancel morphs everything back.

Luiz Mello
  • search
  • header
  • animation

snippet.swift430 lines

7 files • Scroll to see all →
/// A suggestion row shown under the search field. Artwork is an SF Symbol on a/// tinted tile, so the snippet needs no image assets.public struct ExpandingSearchBarItem: Identifiable, Hashable {    public let id: String    let title: String    let subtitle: String    let systemImage: String    let tint: Color​    public init(title: String, subtitle: String, systemImage: String, tint: Color) {        self.id = title + subtitle        self.title = title        self.subtitle = subtitle        self.systemImage = systemImage        self.tint = tint    }​    public static let samples: [ExpandingSearchBarItem] = [        .init(title: "Dune", subtitle: "Frank Herbert · Sci-fi", systemImage: "sun.dust.fill", tint: .orange),        .init(title: "Dune Messiah", subtitle: "Frank Herbert · Sci-fi", systemImage: "moon.stars.fill", tint: .indigo),        .init(title: "Project Hail Mary", subtitle: "Andy Weir · Sci-fi", systemImage: "sparkles", tint: .teal),        .init(title: "The Overstory", subtitle: "Richard Powers · Fiction", systemImage: "tree.fill", tint: .green),        .init(title: "Piranesi", subtitle: "Susanna Clarke · Fantasy", systemImage: "building.columns.fill", tint: .blue),        .init(title: "Educated", subtitle: "Tara Westover · Memoir", systemImage: "mountain.2.fill", tint: .brown),        .init(title: "Klara and the Sun", subtitle: "Kazuo Ishiguro · Fiction", systemImage: "sun.max.fill", tint: .yellow),    ]​    public static let recentSamples: [String] = ["Ursula K. Le Guin", "Short story collections", "Hugo winners 2024"]}
Viewing: Model.swift•1 of 7