Giter Site home page Giter Site logo

partialsheet's Introduction

PartialSheet

A custom SwiftUI modifier to present a Partial Modal Sheet based on his content size.

Features

Availables

  • Slidable and dismissable with drag gesture
  • Variable height based on his content
  • Customizable colors
  • iOS compatibility
  • Landscape compatibility

Upcoming

  • iPad compatibility
  • Mac compatibility

Nice to have

  • ScrcrollView and List compatibility: as soon as Apple adds some API to handle better ScrollViews

Installation

Requirements

  • iOS 13.0+ / macOS 10.15+
  • Xcode 11.2+
  • Swift 5+

Via Swift Package Manager

In Xcode 11 or grater, in you project, select: File > Swift Packages > Add Pacakage Dependency.

In the search bar type PartialSheet and when you find the package, with the next button you can proceed with the installation.

If you can't find anything in the panel of the Swift Packages you probably haven't added yet your github account. You can do that under the Preferences panel of your Xcode, in the Accounts section.

How to Use

To use the Partial Sheet just attach the new modifier:

YourView
.partialSheet(
    presented: Binding<Bool>, 
    backgroundColor: Color = Color.white, 
    handlerBarColor: Color = Color.gray, 
    enableCover: Bool = true, 
    coverColor: Color = Color.black.opacity(0.4), 
    view: @escaping () -> SheetContent) -> some View where SheetContent : View

If you want a starting point copy in your ContentView file the following code:

import SwiftUI
import PartialSheet

struct ContentView: View {

    @State private var modalPresented: Bool = false
    @State private var longer: Bool = false

    var body: some View {
        NavigationView {

            VStack {
                Text("""
				Hi, this is the Partial Sheet modifier.
				It allows you to dispaly a totally custom sheet with a relative height based on his content.
				In this way the sheet will cover the screen only for the space it will need
				""")
                Spacer()
                Button(action: {
                    self.modalPresented = true
                }, label: {
                    Text("Display the Partial Shehet")
                })
                    .padding()
                Spacer()
            }
            .padding()
            .navigationBarTitle("Partial Sheet")
        }
        .partialSheet(presented: $modalPresented) {
            VStack {
                Group {
                    Text("Settings Panel")
                        .font(.subheadline)
                    Toggle(isOn: self.$longer) {
                        Text("Advanced")
                    }
                    .padding()
                }
                .frame(height: 50)
                if self.longer {
                    VStack {
                        Text("More settings here...")
                    }
                    .frame(height: 200)
                }
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

partialsheet's People

Contributors

andreamiotto avatar florianmielke avatar puppybits 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.