Code Monkey home page Code Monkey logo

partialsheet's Introduction

PartialSheet

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

Version 3.0 has been released, there are a lot of breaking changes, make sure to read the guide before update!

Index

iPhone Preview

Dynamic Height Scrollable Content Pickers Compatible
Basic.mov
ScrollVIew.mov
Pickers.mov

iPad & Mac Preview

iPad Version Mac Version

Features

Availables

  • Slidable and dismissable with drag gesture
  • Variable height based on his content
  • Allow scrollable contents
  • Compatible with pickers
  • Customizable colors
  • Keyboard compatibility
  • Landscape compatibility
  • iOS compatibility
  • iPad compatibility
  • Mac compatibility

Nice to have

At the moment we developed all the most requested features, feel free to open an issue if you feel something is missing.

Version 3

The new version brings a lot of breaking changes and a lot of improvments:

  • A more SwiftUI way to call the PartialSheet.
  • Add support to scrollable content.
  • Add support to Material effect.
  • A new Button to avoid the rage tapping.
  • More Support for the pickers.

Installation

Requirements

  • iOS 15.0+ / macOS 12.0+
  • Xcode 13+
  • Swift 5+

Via Swift Package Manager

In Xcode 13 or grater, in you project, select: File > Add Pacakages.

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

You can read more on the wiki - full guide.

To use the Partial Sheet you need to follow just two simple steps

  1. Attach the Partial Sheet instance to your Root View in you
rootView.attachPartialSheetToRoot()
  1. Then in any view on the hierarchy you can use:
view
    .partialSheet(isPresented: $isPresented) {
        Text("Content of the Sheet")
     }

You can also use the PSButton to avoid the rage tapping:

PSButton(
    isPresenting: $isSheetPresented,
    label: {
        Text("Display the Partial Sheet")
    })

Remember to always add import PartialSheet in every file you want to use the PartialSheet.

In the Example directory you can find more runnable examples with more complex structures.

Version 2

The new version brings a lot of new features and improvements, but for now I had to drop the compatibility with iOS systems before the 15.0. If you need you can still use the version 2 pointing to the correct tag in the Package Manager.

partialsheet's People

Contributors

1337domz avatar 94haox avatar adrianhartanto004 avatar amadeu01 avatar andreadroplet avatar andreamiotto avatar anthereum avatar arturolee avatar daeda88 avatar drbeak1 avatar eliottrobson avatar florianmielke avatar hugosay avatar ildarmurzenkov avatar kitwtnb avatar parvinderjit avatar puppybits avatar russelltreacy avatar styrken avatar touyu avatar voltec avatar woko666 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

partialsheet's Issues

Doesn't work on macOS as advertised

I tried this in a Mac app and found that it is full of UIKit code. If you are intending it for Mac Catalyst apps only, then update the README to say macOS Catalyst, not macOS.

NavigationView can't be embedded inside PartialSheet

In the standard Apple sheet, one can have a NavigationView inside the sheet, the same should be possible with PartialSheet.

In the code example below, you can see the behavior difference, in particular, in PartialSheet all actions become non-responsive when the NavigationView is open.

import SwiftUI
import PartialSheet

struct ExperimentAppleSheet: View {
    
    @State var isModalSheetShown: Bool = false
    @State var isPage1Active: Bool = false
    
    var body: some View {
        VStack {
            
            Button(action: {
                self.isModalSheetShown.toggle()
            }) {
                Text("Open sheet")
            }
        }
        .sheet(isPresented: self.$isModalSheetShown) {
            NavigationView {
                VStack {
                    Text("Modal")
                    NavigationLink(destination: Text("page 1"), isActive: self.$isPage1Active, label: {
                        Button(action: {
                            self.isPage1Active.toggle()
                        }) {
                            Text("Go to next page")
                        }
                    })
                }
                .navigationBarItems(trailing: Button("Done",
                                                     action: {
                                                        self.isModalSheetShown.toggle()
                }))
            }
        }
    }
}

struct ExperimentPartialSheet: View {
    
    @State var isPage1Active: Bool = false
    @EnvironmentObject var partialSheetManager: PartialSheetManager
    
    var body: some View {
        VStack {
            
            Button(action: {
                self.partialSheetManager.showPartialSheet({
                    print("Partial sheet opened")
                }) {
                    NavigationView {
                        VStack {
                            Text("Modal")
                            NavigationLink(destination: Text("page 1"), isActive: self.$isPage1Active, label: {
                                Button(action: {
                                    self.isPage1Active.toggle()
                                }) {
                                    Text("Go to next page")
                                }
                            })
                        }
                        .navigationBarItems(trailing: Button("Done",
                                                             action: {
                                                                self.partialSheetManager.closePartialSheet()
                        }))
                    }
                }
            }) {
                Text("Open sheet")
            }
        }
        .addPartialSheet(style: PartialSheetStyle(background: .solid(Color.white),
                                                  handlerBarColor: Color(UIColor.systemGray2),
                                                  enableCover: true,
                                                  coverColor: Color.black.opacity(0.4),
                                                  blurEffectStyle: nil,
                                                  cornerRadius: 10))
    }
}


struct Experiment_Previews: PreviewProvider {
    static var previews: some View {
        ExperimentAppleSheet()
//        ExperimentPartialSheet().environmentObject(PartialSheetManager()) // uncomment and comment line above to switch
    }
}

Animation bugs with pickers

Hi there, thanks for the great library! I really love to use this in my project but I just found some strange animation when using the DatePicker or Picker inside the sheet. This is the screen rec, you can see the sheet is moving up and down while using the DatePicker

And the code is basically this

                    .onTapGesture {
                        self.partialSheetManager.showPartialSheet({
                            print("Partial sheet dismissed")
                        }) {
                            VStack() {
                                Text("Some Title").bold().font(.title)
                                DatePicker("Please select a date", selection: self.$selectedDate, in: ...Date(), displayedComponents: .date).labelsHidden()
                            }.frame(height: 300)
                        }
                    }

Is there any way to fix this? Thx a lot

can not work with ZStack

Thanks a lot to your project! but when I put my partialSheet on a button which is in a ZStack, and set the alignment .bottomTrailing, but it doesn't work .

the code as follows:

ZStack(alignment: .bottomTrailing){
            VStack{
                Picker("helo",selection: $selectedOption){
                    Text("People").tag(0)
                    Text("Tags").tag(1)
                }.pickerStyle(SegmentedPickerStyle())
                
                List{
                    ForEach(tags, id: \.self){
                        tag in
                        Text(tag.name ?? "")
                        
                    }
                }
            }.blur(radius: addMaterialMode==false ? 0: 1000)
            
            Button(action:{
                self.addMaterialMode = true
            }){
                Image(systemName: "plus.circle.fill").resizable().frame(width: 70,height: 70).padding()
            }.partialSheet(presented: $addMaterialMode) {
                Text("hello")
            }
        }

it shows like this:

截屏2020-02-27下午1 09 47

I have tried .bottomTrailing .top... but all of those don't work properly
, it can only show in the center of the screen

Sheet is still going upto the top

Hi, I added this package to make half modals as you mentioned in your stackoverflow answer. But seems like sheet is still going upto the top. The options you can specify while creating the partial sheet does not take any boolean value for it or am I doing wrong? My code is below:

import SwiftUI
import Combine
import PartialSheet

struct FriendsListView: View {
    
    @ObservedObject var friendListVM:FriendListViewModel = FriendListViewModel()
    @State var showModal:Bool = false
    
    private func addFriend(){
        self.showModal = true
    }
    
    var body: some View {
        NavigationView {
            List {
                ForEach(self.friendListVM.friends) { friendVM in
                    NavigationLink(destination: FriendsDetailView(friendVM: friendVM)) {
                        HStack {
                            Image(friendVM.profilePicture)
                                .resizable()
                                .frame(width:50,height:50)
                            VStack(alignment:.leading) {
                                Text(friendVM.name)
                                .font(.title)
                                Text("$ 10.00")
                            }
                        }
                    }
                }
            }
        .navigationBarTitle("Friends")
            .navigationBarItems(trailing: Button(action:self.addFriend){
                  Image(systemName: "plus")
            })
            
        }.partialSheet(presented: self.$showModal) {
            AddFriendView(isPresented: self.$showModal)
        }
        
        
    }
}

struct FriendsListView_Previews: PreviewProvider {
    static var previews: some View {
        FriendsListView()
    }
}

The View is looking like below in simulator for iPhone 11 Pro Max

Simulator Screen Shot - iPhone 11 Pro Max - 2020-01-27 at 00 26 41

Dismiss on Action

Hi,

Nice work.

Just a suggestion:
It would be nice to be able to dismiss the modal from code the same way as a stock modal view. With:

@Environment (\.presentationMode) var presentationMode

and then:

{
  self.presentationMode.wrappedValue.dismiss()
}

Thanks in advance if you consider it.

Compatibility issue with SwiftUIX Search-bar

Hello,

I'm using 2 Swift package for my SearchBar (SWIFTUIX), and Modal (PARTIALSHEET).

When I use the search bar, the keyboard appears and the view is above the keyboard.

Before
Screen Shot 2020-05-22 at 1 22 30 PM

When I add .addPartialSheet(style: .defaultStyle())
Screen Shot 2020-05-22 at 1 23 05 PM
This might be related to issue #35

PartialSheet crashes when trying to dismiss TextField

The line self.dismissKeyboard() in the code below crashes when dismissing the PartialSheet via a drag gesture if a TextField in the PartialSheet has a keyboard presenting. I haven't looked too deeply into this, but I believe this may be because UIApplication.shared.sendAction(resign, to: nil, from: nil, for: nil) is calling into something UIKit-related that SwiftUI isn't.

private func dragGesture() -> _EndedGesture<GestureStateGesture<DragGesture, DragState>> {
    DragGesture()
        .updating($dragState) { drag, state, _ in
            self.dismissKeyboard()
            let yOffset = drag.translation.height
            let threshold = CGFloat(-50)
            let stiffness = CGFloat(0.3)
            if yOffset > threshold {
                state = .dragging(translation: drag.translation)
            } else if
                // if above threshold and belove ScreenHeight make it elastic
                -yOffset + self.sheetContentRect.height <
                    UIScreen.main.bounds.height + self.handlerSectionHeight
            {
                let distance = yOffset - threshold
                let translationHeight = threshold + (distance * stiffness)
                state = .dragging(translation: CGSize(width: drag.translation.width, height: translationHeight))
            }
    }
    .onEnded(onDragEnded)
}

This should be reproducible in a pretty simple use case, but if not let me know and I can try to isolate a sample case.

Thanks a lot!

onDismiss Closure

This is great work. Thanks for your effort!

I would like execute some code when the user dismisses the sheet. Have you considered adding an onDismiss: closure?

Thank you.

How to dismiss view?

I can't dismiss view with
self.presentationMode.wrappedValue.dismiss()
because I use Partial sheet, not system .sheet
How can I dismiss view which was presented by PartialSheet programmatically?

Buttons wrapped in ScrollView do not work.

When this modal window appears, the buttons are not active, in order for the buttons to start working, you need to interact with scrollview, after that a modal view will jump (it will decrease by a few pixels) and the buttons will become active, I hope I explained it clearly) I also attach an example code from your project.

.partialSheet(presented: $showPartialSheet, backgroundColor: Color(UIColor.secondarySystemBackground)) {
     ChangeIcons()
}

struct ChangeIcons: View {
    var body: some View {
        ScrollView(.horizontal, showsIndicators: false) {
            HStack {
                VStack(alignment: .center) {
                    Button(action: foofunc) {
                        Image("infoApp")
                            .resizable()
                            .renderingMode(.original)
                            .cornerRadius(15)
                            .frame(width: 80, height: 80)
                            .overlay(
                                RoundedRectangle(cornerRadius: 15)
                                    .stroke(Color.red, lineWidth: 3)
                                    .frame(width: 90, height: 90)
                        )
                    }.frame(width: 95, height: 95)
                    Text("Стандартная")
                        .font(.system(size: 11, design: .rounded))
                        .bold()
                }
                VStack(alignment: .center) {
                    Button(action: fooFunc) {
                        Image("altIconApp")
                            .resizable()
                            .renderingMode(.original)
                            .cornerRadius(15)
                            .frame(width: 80, height: 80)
                            .overlay(
                                RoundedRectangle(cornerRadius: 15)
                                    .stroke(Color.red, lineWidth: 3)
                                    .frame(width: 90, height: 90)
                        )
                    }.frame(width: 95, height: 95)
                    Text("Автор иконки")
                        .font(.system(size: 11, design: .rounded))
                        .bold()
                }
            }.padding(.horizontal)
        }.onAppear(perform: fooFunc)
    }
}

Picker in partial sheet causes issues

So I've noticed placing a picker in a partial sheet causes some weird issues.

  1. Dragging on the picker triggers the drag gesture of the sheet. So when you try to drag on the picker the sheet moves a bit before the picker does its thing.
  2. Related to 1, if you have a TextField AND a picker in the partial sheet things get really bumpy. If the keyboard is open and you drag the picker, the drag gesture of the sheet gets triggered (as mentioned above) which tells the keyboard to dismiss. SwiftUI can't seem to handle this all at once and crashes.

Crash message

AttributeGraph precondition failure: setting value during update: 75004.
2020-06-29 09:14:19.822339-0500 Fox Relay[13433:3310197] [error] precondition failure: setting value during update: 75004

The crash originates here and is triggered here

I like this library and would like to continue using it for my app so some guidance on this would be appreciated.

Multiple sheets stack option

Ability to stack a sheet onto another sheet.
Ability to dismiss existing sheet and quickly call a replacement sheet in function form.

Awesome feature idea: have the sheet set partial distance based on sections of forms

This would make it easy to define an automatic layout behavior, wherein the sheet would expand in increments to show more sections if they fit, and respond to scroll, naturally. Some tension between each section would give it a more natural transition, such as the spring interrupted animation wherein you implement drag interception of animation, but only start the animation after a certain magnitude of the current section is no longer visible. This would make a very nice automatic part to an automatic scrolling UI behavior on each field, wherein the user advances the form automatically and naturally as they complete each section.

TextField inside partial sheet won't update @State var

I try to add a TextField into partial sheet, but it does not update its @State var.
Example:

self.partialSheetManager.showPartialSheet {
  TextField("Enter your name", text: self.$newBoardName)
  Text("Hello, \(self.newBoardName)!") // won't update
}

Sheet opening problem

If you use a partial sheet to open one view.. close it.. then open the sheet with another view, the sheet open animation starts from the height of the previous sheet on the first open call of the new view.
[ISSUE FIXED IN 2.1.3]

onDismiss not being called from closePartialSheet

It is documented to run the onDismiss, but does not.

/// Close the Partial Sheet and run the onDismiss function if it has been previously specified

    public func closePartialSheet() {
        self.isPresented = false
    }

The onDismiss function is run when dragging to close as expected.

I added something like this and bound it to an action and now I get the onDismiss to fire.

public func dismissPartialSheet() {
        self.isPresented = false
        self.onDismiss?()
}

I am not sure if there was intent to have the closePartialSheet merely close the sheet (e.g. maybe a cancel-type scenario) without running the onDismiss function.

Background

It there any way we can change the entire background color of the sheet, looks like it is always in white color. Would like to use it in dark mode.
Thank you so much!

No way to initialise PartialSheet using binding starting 2.0

I have looked at the library before, but have never used it. Now I've decided to use it and, as I understand, starting from 2.0, it's not possible to initialise PartialSheet using a binding, and is possible only using a user action (pressing a button and calling the sheet action there). If this is indeed so, I think it's a bit of a downgrade and is not in line with the SwiftUI approach.

I use global state for my navigation, so before, I could configure the state (in case of deep linking, for instance) and this way navigate to any of the views, including an opened sheet. Now it looks like I can't do that.

Crash When PartialSheet Appears Again?

PartialSheet is awesome and your work on 2.0 has been terrific! Thank you for what you are doing!

I have a bug in my prototype app. I do not know if it is caused by PartialSheet. I'm not as familiar with Xcode as I would like to be, and so you may want to ask me for more information.

Here is the setup:

  • I have a SwiftUI view called ViewA() that has a form. In that form is a view called MapVIew() that contains an MKMapView via UIViewRepresentable. MapView() has several params, one of which is a Bool for editing. MapView() within the form on ViewA() is not editable.
  • When the user taps on the MapView() in the form on ViewA(), a NavigationLInk pushes a new view, ViewB(), that contains a new instance of MapView() with the MKMapView, but this time it is editable.
  • In ViewB(), the user can center the user location, bring up a settings PartialSheet, and drop a pin by long-pressing on the MKMapView contained within MapView().
  • Within the settings PartialSheet, the user can change the map type (Standard, Satellite, Hybrid) and drop a pin exactly on the user's current location.
  • If the user taps on a dropped pin, detail about that pin is shown on another PartialSheet, including the reverse geocoded street address, the latitude, and the longitude. This PartialSheet also contains a button to remove the pin.
  • Only 1 dropped pin is shown at a time on the map. If the user drops another pin at the user location or long-presses on another location in the MKMapView, any pin that already exists is removed.
  • Both PartialSheets are closed by calling .closePartialSheet() on the PartialSheetManager environment object.
  • The MapView() instance on ViewA() and the MapView() instance on ViewB() show the same MKMapView data, including user location and a dropped pin, if it exists. The only differences which MapView() is editable and the sizes of the MapView() instances are different in ViewA() vs. ViewB().

A description of the problem:

  • As long as I stay on ViewB(), I can bring up the settings PartialSheet and drop pins on the user location as much as I would like. I can also drop as many pins as needed (one at a time) at other locations on the MKMapView and bring up the pin detail PartialSheet for each one without any problems.
  • However, if I back out ViewB() to the parent ViewA() with the form, tap on the MapView() in the form to go back to ViewB(), and then either 1) bring up the settings PartialSheet, or 2) show pin detail by tapping on the pin, the app crashes with Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1da55a12c).
  • Clarification: The crash occurs only after a PartialSheet is opened and closed on ViewB(), returning to ViewA(), going back to ViewB() and opening a PartialSheet.
  • In both crashes, the PartialSheet does not show before the crash.
  • This crash did not occur when I was using v1.0.3 of PartialSheet. It only appeared after I started using v2.1. (That doesn't mean I did not create a problem in my code when converting it to accommodate PartialSheet changes from 1.0.3 to 2.1.)
  • The code to bring up the settings PartialSheet and the pin detail PartialSheet are in two different files. The settings PartialSheet code is in ViewB() and the pin detail PartialSheet is in MapView().
  • When I print stack traces for both crashes, it appears to be caused by the same code location in SwiftUI. (SwiftUI 0x00000001da5600f0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5628144) The stack traces are pasted below.

Would it be possible that PartialSheet has a common bug that causes both crashes? What other information do you need from me?

Thank you very much for your help.

Jim


Crash with bringing up Map Settings PartialSheet

▿ 33 elements

0 : "0 ??? 0x000000011622466c 0x0 + 4666312300"
1 : "1 Cardigan 0x0000000104d69390 main + 0"
2 : "2 SwiftUI 0x00000001da5600f0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5628144"
3 : "3 SwiftUI 0x00000001da4152a0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 4272800"
4 : "4 SwiftUI 0x00000001da5600f0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5628144"
5 : "5 SwiftUI 0x00000001da4152a0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 4272800"
6 : "6 SwiftUI 0x00000001da55ff6c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5627756"
7 : "7 SwiftUI 0x00000001da52baf8 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5413624"
8 : "8 SwiftUI 0x00000001da52aca0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5409952"
9 : "9 SwiftUI 0x00000001da0bdea4 3652361F-29A7-3130-AB4A-72A5F7BB506B + 769700"
10 : "10 SwiftUI 0x00000001da0be9f4 3652361F-29A7-3130-AB4A-72A5F7BB506B + 772596"
11 : "11 AttributeGraph 0x00000001ce264ef4 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 114420"
12 : "12 AttributeGraph 0x00000001ce24c88c 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 14476"
13 : "13 AttributeGraph 0x00000001ce24cd48 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 15688"
14 : "14 AttributeGraph 0x00000001ce251cb0 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 36016"
15 : "15 SwiftUI 0x00000001da1cad3c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1871164"
16 : "16 SwiftUI 0x00000001da1caaf0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1870576"
17 : "17 SwiftUI 0x00000001da1ca768 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1869672"
18 : "18 SwiftUI 0x00000001da1ca8e0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1870048"
19 : "19 SwiftUI 0x00000001da4814b4 3652361F-29A7-3130-AB4A-72A5F7BB506B + 4715700"
20 : "20 SwiftUI 0x00000001da1ca8a8 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1869992"
21 : "21 SwiftUI 0x00000001da1e6678 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1984120"
22 : "22 SwiftUI 0x00000001da05ccdc 3652361F-29A7-3130-AB4A-72A5F7BB506B + 371932"
23 : "23 SwiftUI 0x00000001da05cc4c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 371788"
24 : "24 SwiftUI 0x00000001da05cd7c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 372092"
25 : "25 CoreFoundation 0x00000001a1fbec54 9624AAFD-5437-3772-A507-0F357875808D + 707668"
26 : "26 CoreFoundation 0x00000001a1fb98e4 9624AAFD-5437-3772-A507-0F357875808D + 686308"
27 : "27 CoreFoundation 0x00000001a1fb9d84 9624AAFD-5437-3772-A507-0F357875808D + 687492"
28 : "28 CoreFoundation 0x00000001a1fb9660 CFRunLoopRunSpecific + 480"
29 : "29 GraphicsServices 0x00000001ac3ca604 GSEventRunModal + 164"
30 : "30 UIKitCore 0x00000001a618e15c UIApplicationMain + 1944"
31 : "31 Cardigan 0x0000000104d693e0 main + 80"
32 : "32 libdyld.dylib 0x00000001a1e351ec 95B366E7-F5BD-3308-9416-24B35999029B + 4588"

Crash with bringing up Pin Detail Settings PartialSheet

▿ 31 elements
0 : "0 ??? 0x000000011509866c 0x0 + 4647913068"
1 : "1 Cardigan 0x000000010245d390 main + 0"
2 : "2 SwiftUI 0x00000001da5600f0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5628144"
3 : "3 SwiftUI 0x00000001da4152a0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 4272800"
4 : "4 SwiftUI 0x00000001da55ff6c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5627756"
5 : "5 SwiftUI 0x00000001da52baf8 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5413624"
6 : "6 SwiftUI 0x00000001da52aca0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 5409952"
7 : "7 SwiftUI 0x00000001da0bdea4 3652361F-29A7-3130-AB4A-72A5F7BB506B + 769700"
8 : "8 SwiftUI 0x00000001da0be9f4 3652361F-29A7-3130-AB4A-72A5F7BB506B + 772596"
9 : "9 AttributeGraph 0x00000001ce264ef4 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 114420"
10 : "10 AttributeGraph 0x00000001ce24c88c 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 14476"
11 : "11 AttributeGraph 0x00000001ce24cd48 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 15688"
12 : "12 AttributeGraph 0x00000001ce251cb0 5CAF326B-142F-3CAC-AE1C-7B4271D0A801 + 36016"
13 : "13 SwiftUI 0x00000001da1cad3c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1871164"
14 : "14 SwiftUI 0x00000001da1caaf0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1870576"
15 : "15 SwiftUI 0x00000001da1ca768 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1869672"
16 : "16 SwiftUI 0x00000001da1ca8e0 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1870048"
17 : "17 SwiftUI 0x00000001da4814b4 3652361F-29A7-3130-AB4A-72A5F7BB506B + 4715700"
18 : "18 SwiftUI 0x00000001da1ca8a8 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1869992"
19 : "19 SwiftUI 0x00000001da1e6678 3652361F-29A7-3130-AB4A-72A5F7BB506B + 1984120"
20 : "20 SwiftUI 0x00000001da05ccdc 3652361F-29A7-3130-AB4A-72A5F7BB506B + 371932"
21 : "21 SwiftUI 0x00000001da05cc4c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 371788"
22 : "22 SwiftUI 0x00000001da05cd7c 3652361F-29A7-3130-AB4A-72A5F7BB506B + 372092"
23 : "23 CoreFoundation 0x00000001a1fbec54 9624AAFD-5437-3772-A507-0F357875808D + 707668"
24 : "24 CoreFoundation 0x00000001a1fb98e4 9624AAFD-5437-3772-A507-0F357875808D + 686308"
25 : "25 CoreFoundation 0x00000001a1fb9d84 9624AAFD-5437-3772-A507-0F357875808D + 687492"
26 : "26 CoreFoundation 0x00000001a1fb9660 CFRunLoopRunSpecific + 480"
27 : "27 GraphicsServices 0x00000001ac3ca604 GSEventRunModal + 164"
28 : "28 UIKitCore 0x00000001a618e15c UIApplicationMain + 1944"
29 : "29 Cardigan 0x000000010245d3e0 main + 80"
30 : "30 libdyld.dylib 0x00000001a1e351ec 95B366E7-F5BD-3308-9416-24B35999029B + 4588"

Xcode 12 canvas

Xcode 12 canvas crashes as soon as PartialSheet is imported to view. Any idea how to fix this?

Doesn't work

I have tried this in my app by replacing different working instances of .sheet with .partialSheet and none of them has worked. The results have either been a blank sheet or corruption of the presenting view. Nice idea but I suspect it needs broader testing.

Provide a license

Hey, it would be totally awesome if you provide a license, otherwise it is illegal for others to use your code.

The license you choose is for sure up to you, but I would suggest to make it as easy as possible for people to use your code, use the Unlicense.
Otherwise, MIT is a popular choice.

Great swiftui element you developed there!

How to use it if you still have good old AppDelegate?

I'm struggling to get sheet running on a mixed setup and your documentation shows only the usage if app is configured with swiftUI form beginning.

can you show us how to use it if we don't have such a setup.

Thank you in advance!

Keyboard observer moves all content up above keyboard

It appears that the new addition of keyboard observers causes elements like a tab bar to shift above the keyboard in instances where the partial sheet is added to the TabView and a keyboard is presented at any time, sheet presented or not. I think I have a solution that works.

Instead of .padding(.bottom, self.offset) in the PartialSheetViewModifier on line 79, the negative offset should be added to iPhoneSheet() as such .offset(x: 0, y: -self.offset) on like 113.

if deviceType == .iphone {
    iPhoneSheet()
        .offset(x: 0, y: -self.offset)
        .edgesIgnoringSafeArea(.vertical)
}

From my testing this solution will prevent the whole content from receiving a padding when the keyboard presents.

Not working fine with NavigationView & NavigationLink

I have the use case below :

  • NavigationView with a NavigationLink (send the user to second view[page])
  • the second view use .partialSheet
  • the partialSheet view has a Textfield
    when the keyboard is opened , there is an issue as the image below :

84661094_887988474971084_2607907784263467008_n


85054519_210616900083226_3467720100453285888_n

Drag to take full screen

Thanks for the amazing Swift package. It saved a lot of hours of work.

I would like to ask if it's possible to implement a functionality where, the partial sheet should have the max height equal to half the screen size (or height passed in configuration) on initial load and when swipe up, the height should change to full screen. I understand this should only be possible for contents which are of size more than half of screen.

Something like this gif. Where the partial screen takes full height when searching using a keyboard.

ezgif com-video-to-gif

How do use Navigation Link in Partial Sheet

I wrote the following code.
However, NavigationLink doesn't work.
How do I use NavigationLink in PertialSheet?

import PartialSheet
import SwiftUI

struct ContentView: View {
    @EnvironmentObject private var partialSheetManager: PartialSheetManager
    var body: some View {
        NavigationView {
            Button(action: {
                self.partialSheetManager.showPartialSheet {
                    NavigationLink(destination: Text("destination view")) {
                        Text("navigation link")
                    }
                }
            }) {
                Text("show partial sheet")
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .addPartialSheet()
    }
}

Animation is applied on sheet view and is propagated down to the content

There is this set on the sheet view:
.animation(self.dragState.isDragging ? nil : .interpolatingSpring(stiffness: 300.0, damping: 30.0, initialVelocity: 10.0)) which applies animation to the content of the sheet. In my case, I have views which are hidden and shown depending on the state in the sheet content and now they are automatically animated.

Per Apple's documentation on animation(_:): Use this modifier on leaf views rather than container views. The animation applies to all child views within this view; calling animation(_:) on a container view can lead to unbounded scope.

Basically, setting this on the the container (sheet view) is an anti-pattern. I think, explicit property animation should be used instead, this way no matter what the content is provided to the PartialSheet, it will not be affected.

Rest all ObservedObjects inside navigatoinview childs in tabbar

if we place a TabVIew and add a partial sheet to it, then add some NavigationViews for tabs and go to inside of NavigationView child views if view uses ObservedObject for ViewModel when we open partial sheet all variables in ObservedObject of ViewModel was reset

Button is not working inside ScrollView

I have content for SheetView inside a ScrollView. And under ScrollView there are few UI elements and one button. So when the view loaded the first time the button is not working. But after doing the scroll event the button starts working. Here is my code,

//Main ContentView
`var body: some View {

    HStack {
        Spacer()
        Button(action: {
            self.partialSheetManager.showPartialSheet({
                 print("normal sheet dismissed")
            }) {
                 SheetView()
            }
        }, label: {
            Text("Display the Partial Sheet")
        })
    }
}`

//SheetView

`struct SheetView: View {
var body: some View {
VStack {

        ScrollView {
            Text("Hello")
            
            Button(action: {
                print("Button is tapping")
            }) {
                Text("Tap Here")
            }
        }
    }
}

}`

Static Heights

Hello mate, firstly thanks for this repo :)

I want to use it with custom static heights.
For example y:200 and y:600 cases. Is there any way to do it ?

I made this custom modal but it's not working so well. This screenshots will help you to understand what I'm trying to do.

Thanks in advance :)

Simulator Screen Shot - iPhone 11 Pro Max - 2020-05-05 at 01 50 05

Simulator Screen Shot - iPhone 11 Pro Max - 2020-05-05 at 01 50 09

Blur effect on sheet

It would be nice to have a blur effect on the sheet as well, similar to the sheet on Apple Maps.
9B3C2220-F95A-4B7E-9567-74A1295CF314

08EAB340-ADE7-473C-9795-E8465808928F

Remove PartialSheet from its view hierarchy when not presented

Any possible to using AnyTransiton to insert it into View Hierarchy when presented and remove it when not presented.
Now partialSheet view is just being hidden off of the screen instead of being removed.
Possible improvements may be like below:

if presented {
    PartialSheetContent.offset(offsetWhenPresented)
        .transition(anyTransitionMethod).animation(anyAnimation)
} 
else {
    EmptyView()
}

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.