Bottom sheet

A cursor at the bottom of the screen with 3 states, built with SwiftUI.

There have been many attempts to recreate the BottomSheet from Apple’s maps, shortcuts and music, because unfortunately Apple doesn’t offer them in its SDK.

However, all previous attempts have a common problem: The height does not change in the different states. This way, the bottom plate is always the same size (e.g. 800px) and thus remains 800px, even if you only see 400px, for example – the rest is unreachable unless you move the bottom plate up.

There are also many apps that only have two states – not three, like Apple Maps.

Unfortunately, my implementation currently supports only one state (the height cannot be changed) and three states (e.g. Apple – Top, Middle, Bottom (, Hidden)). But I’m working on a two-state solution.

Here are some alternatives:

Here you can see the above reports:

  • IOS 13
  • Swift 5.3
  • Xcode 12

The preferred method of installing BottomSheet is the Swift package manager.

Xcode 11 is integrated with libSwiftPM to support iOS, watchOS and tvOS platforms.

  1. In Xcode open your project and go to File → Quick Packages → Add Package Dependencies….
  2. Enter the URL of the repository (https://github.com/LucasMucGH/BottomSheet) and click Next.
  3. Select a branch for the rules (with the branch set to Main).
  4. Click on Finish.

Basic usage

A WARNING:
Here is an example of code to illustrate where and how it is used, without a functional initializer. Examples of work codes can be found under Examples

Just like you use a sheet of paper in SwiftUI.

ContentView Structure : See { “order”.}

@State var bottomSheetPosition : Football position = .middle //1

var body : what view {

Map() //2
.bottomSheet() //3
}
}

//1 The current status of the bottom page is stored here
The following states are valid: .hidden, .bottom, .middle and .top.
If you don’t want to change the state, you can use for example .constant(.hidden) (must be used with resizing: false).

//2 This is the view that BottomSheet should include

//3 How to add a BottomSheet – simple, isn’t it?

A WARNING:
This is an example of code for viewing parameters and their default values and value types, without a functional initializer. Examples of work codes can be found under Examples

.bottomSheet(
bottomSheetPosition : bound,
resizable : bool = true,
showCancelButton : Bool = false, header
: String ? = null,
@ContentToDisplay : () -> mContent,
closeAction : @escaping () -> () = {}
)

  • Position of the bottom plate
    The current status of the bottom plate is stored here.
    The following states are allowed: .hidden, .bottom, .middle and .top.
    If you don’t want to change the state, you can use for example .constant(.hidden) (must be used with resizing: false).
  • Resizable
    This setting controls whether it can be dragged.
    In the case of a false trip, the tow indicator disappears.
  • ShowCancelButton
    Activates the visibility of the close button (X).
  • Name
    Title Cover page.
    Maybe zero.
  • Contents
    Here it is declared that the view must be located in the BottomSheet.
  • CloseAction
    Here you specify the action to be performed when you click the Close (X) button.
    IF THEY WANT SOMETHING TO HAPPEN, THEY HAVE TO EXPLAIN IT.

For example

{
self.bottomSheetPosition = .hidden
}

A WARNING:
This is an example of code for viewing parameters and their default values and value types, without a functional initializer. Examples of work codes can be found under Examples

.bottomSheet(
bottomSheetPosition : bound,
resizable : bool = true,
showCancelButton : Bool = false,
@ViewBuilder headerContent : () -> hContent ?,
@ViewBuilder mainContent : () -> mContent,
closeAction : @escaping () -> () = {}
)

  • Position of the bottom plate
    The current status of the bottom plate is stored here.
    The following states are allowed: .hidden, .bottom, .middle and .top.
    If you don’t want to change the state, you can use for example .constant(.hidden) (must be used with resizing: false).
  • Resizable
    This setting controls whether it can be dragged.
    In the case of a false trip, the tow indicator disappears.
  • ShowCancelButton
    Activates the visibility of the close button (X).
  • headerContent
    Here is the content of your custom header.
    All views are possible, which can cause problems if the view is too wide. A label, small image or text is recommended.
    Maybe zero.
  • mainContent
    Here you declare the view that should be in the bottom sheet.
  • CloseAction
    Here you specify the action to be performed when you click the Close (X) button.
    IF THEY WANT SOMETHING TO HAPPEN, THEY HAVE TO EXPLAIN IT.

For example

{
self.bottomSheetPosition = .hidden
}

The simplest version of thefooter sheet

import SwiftUI
import BottomSheet

Sheet background test1 : See { “order”.}

@Private change of the position of the bottom plate : Bottom plate position = .mid

var body : single view {
ZStack {
//A plain black background
Color.black
.edgesIgnoringSafeArea(.all)

.bottomSheet(bottomSheetPosition: self.$bottomSheetPosition, content: {/numbers 0 to 99 as main content inScrollView {ForEach(0)…<100) { index inText(string(index))}.frame(maxWidth: .infinity)}.padding(.top)})}}}}

Bottom sheet not to drag but to discard to show additional information

import SwiftUI
import BottomSheet

Structure of the BottomSheetTest2 : See { “order”.}

@Private change of the position of the bottom plate : Bottom plate position = .mid

var body : single view {
ZStack {
//A plain black background
Color.black
.edgesIgnoringSafeArea(.all)

.bottomSheetSheetPosition: self.$bottomSheetPosition, resizable: false, showCancelButton: true, title : Hello, world, content: {
//A caption, with some sample text and read more and tab button
VS attack (alignment: .leading, distance: zero) {

Text (Bottom Sheet)
.foregroundColor(.white)
.bold()
.padding(8)
.background(color.red)
.cornerRadius(10)
.padding(.horizontal)

divider().padding(10)

Text (Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incidunt ut labore et dolore magna aliqua. If you want to keep your work to a minimum, you can use it as a training module).
.fixedSize (horizontal: false, vertical: true)
.padding(.horizontal)

divider().padding(10)

HStack {
Button(action: {}, label: {
Text(Read more)
.foregroundColor(.white)
})
.padding(.vertical)
.padding(.horizontal, 50)
.background(Color.black)
.cornerRadius(20)

Button(Action): {}, label :
Image (systemName : bookmark)
.foregroundColor(.white)
})
.padding()
.background(Circle()
Spacer()
}
.padding([.horizontal, .bottom]])

Spacer()
}
.padding(.top)
}, closeAction :
//Approximation (X) moves the sheet from the bottom to the bottom
withAnimation(.linear) {
self.bottomSheetPosition = .hidden
})
}
}
}
}

import SwiftUI
import BottomSheet

Structure of the BottomSheetTest3 : See { “order”.}

@Private change of the position of the bottom plate : BottomSheetPosition = .middle
@State private var searchText : Chain =

var body: some view {
//A plain black background
Color.black
.edgesIgnoringSafeArea(.all)

.bottomSheetPosition: self.$bottomSheetPosition, resizable: true, showCancelButton: true, headerContent: {//A Search string as header contentHStack {Image(systemName: magnifyingglass)TextField(Search, text: self.$searchText)}.foregroundColor(.secondaryLabel).padding(.vertical, 8).padding(.horizontal, 5).background(RoundedRectangle(cornerRadius: 10).fill(Color.quaternaryLabel))}, mainContent: {// Numbers from 0 to 99 as main content in a scroll viewScrollView {ForEach(0…<100) { index inText(String(index)))}..frame(maxWidth : .infinity)}.padding(.top)}, closeAction: {//The Close (X) moves the bottom sheet down withAnimate(.linear) {self.bottomSheetPosition = .bottom}})}}

GitHub

swiftui sheet half screenswift slide up viewswiftui bottom sheetswiftui partial sheetswift sheet viewuikit bottom sheetbottom sheet swiftui githubswift fitted sheets

You May Also Like

How To Fix Thumbnails Not Showing In Windows 10

The Windows thumbnail function makes it easy to recognize photos and movies…

A Complete Guide On Resolving The Issue of Phone Overheating

The phone can sometimes even get hot, whether it’s during a game…

How To Fix Windows 10 File Explorer Dark Theme Not Working

When it comes to customisation options, Windows 10 offers users a considerable…

Apex Legends Crashing PC Fix 2020

Various problems can occur during gambling. If you’re playing the new royal…