Skip to content

ionas-dev/SnapSheet

Repository files navigation

🗄️ SnapSheet

SnapSheet Title Image

A native looking snap sheet/drawer component. Written in SwiftUI and behaves like you'd imagine any SwiftUI component to work.

In the past I've used Snap, but wanted to make one on my own.

Usage

import SwiftUI
import SnapSheet

struct ContentView: View {

  var body: some View {
    // The normal (behind the sheet) view content belongs here
    NormalContent()
      .overlay(
        SnapSheet {
          // The content shown on the sheet belongs here
        }
      )
  }
}

Additional functions

import SwiftUI
import SnapSheet

struct ContentView: View {
  @State var state: SnapSheetState = .small

  var body: some View {
    // The normal (behind the sheet) view content belongs here
    NormalContent()
      .overlay(
        SnapSheet($state, smallHeight: 100, middleHeight: 400, largeHeight: 800) {
          // The content shown on the sheet belongs here
        }
        .ignoresSafeArea()
        .background(.white)
      )
  }
}
  • Set snap heights: Set the snap small, middle and large heights the sheet snaps for
init(
  smallHeight: CGFloat = UIScreen.main.bounds.size.height * 0.1,
  middleHeight: CGFloat = UIScreen.main.bounds.size.height * 0.4,
  largeHeight: CGFloat = UIScreen.main.bounds.size.height * 0.78,
  @ViewBuilder content: () -> Content)
  • Snap state Binding: Make the state of the sheet visible and changable from outside
init(
  _ state: Binding<SnapSheetState> = .constant(.small),
  @ViewBuilder content: () -> Content)
  • Ignore safe area: Allows content of snap sheet to overlap the area of the home bar
func ignoresSafeArea() -> some View
  • Background color: Changes the background color of the snap sheet
func background(_ color: Color) -> some View

Installation

Swift Package Manager

Example Footage

SnapSheet.-.Demo.mp4

About

Native iOS bottom snap sheet

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages