Giter VIP home page Giter VIP logo

expandablesearchbar's Introduction

Expandable Search Bar

An expandable navigation bar with custom segmented control.

Description

An expandable search bar with custom segmented controls.

We created a custom navigation bar with search field and segmented controls embedded in it.

The navigation bar gets stretched if the user scrolls up the content, or if the user clicks inside the search field. If the search field is closed, or the user scrolls down the content significantly the navigation bar expands. In expanded state, you can see title, search field and segmented controls, but in stretched navigation bar state the title isn't visible.

To make the navigation bar appear consistent, I used a custom ScrollTargetBehavior to either allow the navigation bar stay in expanded state or transition to stretched state, and vice versa.

I used matched geometry effect and snappy animation for custom segmented controls, and a custom transition to display the closed search button.

Next steps

The code works, but there are still a few rough edges that I want to work on next. Here they are:

  • Modify the code and make it more readable.
  • Make a component out of the code to make it reusable.

Usage

You need to copy both ExpandableSearchBar.swift and Tab.swift to your code. You can change the case values of Tab.swift, but don't remove the case value .all.

After copying, it's fairly simple to use. Initialize the ExpandableSearchBar.swift in your view like this:

struct ContentView: View {
    private let title = "Messages"
    @State private var searchText = ""
    
    var body: some View {
        NavigationStack {
            ExpandableSearchBar(title: title, searchText: $searchText) {
                // YOUR CUSTOM SCROLLABLE CONTENT GOES HERE...
            }
            .toolbar(.hidden, for: .navigationBar)
        }
    }
}

I will make it a little more easier to use soon!

Screenshots

App testing gif

expandablesearchbar's People

Contributors

mohsinaliayub avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.