Giter Site home page Giter Site logo

zorro0799 / ionavigation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kaevinio/ionavigation

1.0 0.0 0.0 1.35 MB

Beautiful Sidebar and Tabbar for iOS, iPadOS and macOS written in 100% SwiftUI ๐Ÿ“ฑ

License: MIT License

Swift 100.00%

ionavigation's Introduction

IOComponents

A simple and beautiful Sidebar, a Tabbar and a Navigationbar for iOS, iPadOS and macOS, written in 100% SwiftUI.


๐Ÿ’ฐ Support

I fell in love with coding in 2016 and there has been no looking back since! If you, or your company, use any of my projects or like what I'm doing, kindly consider supporting me.

I really appreciate you buying me a coffee โ˜•๏ธ

Sponsors

Special thanks to SPACE SQUAD for backing this project! They make great software with โ™ฅ๏ธ in Berlin.


๐Ÿ‘‹ Let's Connect


๐Ÿ“– Content

๐Ÿช„ Features

  • Availability on iOS, iPadOS and macOS
  • Show a header and a button (optional) in the Sidebar
  • Add unlimited groups and views to the Sidebar
  • Collapse groups (or set them as not collapsable)
  • Hover over elements (iPadOS & macOS)
  • Adapts to regular and compact mode (iPadOS)
  • Add the integrated Navigationbar to your views
  • Add a back button to the Navigationbar
  • Add one or multiple items to the Navigationbar
  • Set your custom color

๐Ÿ“ฑ Screenshots

macOS

iPadOS

iOS

๐ŸŽฅ Preview

mac.mov

๐Ÿ›  Installation

Requirements
  • iOS 15.0+ / macOS 12.0
  • Xcode 13+
  • Swift 5+
Swift Package Manager

In Xcode, go to File > Add Packages and add https://github.com/kaevinio/IONavigation.git. Add the package to all your targets.

๐Ÿ“ How to Use

Sidebar & Tabbar

The Sidebar consists of several groups, which contain individual views and is displayed on macOS and iPadOS. The Tabbar contains individual views and is available on iOS as well as in compact windows on iPadOS.

  • To use the package, you need to import IONavigation on top of the files you want to use it in

  • Create a new SwiftUI file and name it NavigationView (or whatever name you'd like for your navigation)

  • Add the respective environment value for checking the window size to determine whether the Sidebar or the Tabbar will be used (this is only available on iOS)

#if os(iOS)
@Environment(\.horizontalSizeClass) var horizontalSizeClass
#endif
  • In your view's body, setup the Sidebar and the Tabbar according to the horizontalSizeClass
#if os(iOS)
if horizontalSizeClass == .compact {
      Tabbar(items: tabbarItems, color: .purple)
} else {
      Sidebar(header: "IONavigation", color: .purple, itemGroups: sidebarItemGroups, actionIcon: Image(systemName: "plus.circle.fill"), action: add)
}
#else
Sidebar(header: "IONavigation", color: .purple, itemGroups: sidebarItemGroups, actionIcon: Image(systemName: "plus.circle.fill"), action: add)
#endif

Note: Header, actionIcon and action are optional. If you don't use a header, the actionIcon will not be displayed either.

You pass an array of Item for the Tabbar but an array of ItemGroup to the Sidebar. This is because the Sidebar supports different groups, which can be collapsed.

You can also select views from your sidebar programmatically. In your view, add the following property:

@StateObject private var sidebarSelection = SidebarSelection.shared

You can then set sidebarSelection with the ID of the view you want to select, e.g. in a function:

private func selectSearchTab() {
    sidebarSelection.selectedViewID = HomeTab.search.rawValue
}

You can find the respective code in the example project.

Navigationbar

Using the built-in Navigationbar is optional, as it does not belong to the Sidebar or the Tabbar. To use it, navigate to the view you'd like to use it in. First, import IONavigation at the top.

  • Create a VStack with zero spacing and add the NavigationBar at the top:
var body: some View {
      VStack(spacing: 0) {
          Navigationbar(title: "Header")

          // Here will be your views
          ScrollView {
              Text("Hello, world!")
                  .padding()
          }
      }
      .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
      .background(Color("primaryBackground"))
}

This will display a blank Navigationbar with a header. You can also add either a BackButton, which is displayed on the leading side of the header (for deeper navigation) or you can add one or multiple NavigationItems, which will be added to trailing side of the Navigationbar. You can choose between an icon and text to be shown.

  • To show NavigationItems, use the built-in ViewModifier .navigationItem:
var body: some View {
      VStack(spacing: 0) {
          Navigationbar(title: "Header")
              .navigationItem(image: Image(systemName: "heart.fill"), color: .purple, action: {})
              .navigationItem(image: Image(systemName: "bookmark.fill"), color: .purple, action: {})

          // Here will be your views
          ScrollView {
              Text("Hello, world!")
                  .padding()
          }
      }
      .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
      .background(Color("primaryBackground"))
}

In the Example directory you can find demo code to show how to setup all components.

ionavigation's People

Contributors

kaevinio avatar

Stargazers

 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.