SplitSheet icon indicating copy to clipboard operation
SplitSheet copied to clipboard

SwiftUI Support

Open pedrommcarrasco opened this issue 2 years ago • 8 comments

First of all, great work on the framework 👍 Are you planning to extend it with a SwiftUI version that uses a Representable? 🤔

pedrommcarrasco avatar Jun 09 '22 17:06 pedrommcarrasco

Thanks! Should be pretty simple, when I get the time I'll add support. However at WWDC22 SwiftUI now automatically gets support for half-sheet overlays with presentationDetents - Apple's implementation is probably much more polished than anything I can come up with!

aheze avatar Jun 09 '22 18:06 aheze

Apple's implementation is probably much more polished than anything I can come up with!

Don't be so pessimistic! The only difference between you and an Apple Engineer is the title - everything is highly subjective and I believe that, under the same conditions, you could perform as good, if not better, than one!

However at WWDC22 SwiftUI now automatically gets support for half-sheet overlays with presentationDetent

I think you might be under-selling your little framework here. SwiftUI's sheets act as modals, as in, they'll be placed on top of an existing view instead of sharing (splitting) the space with other view. I've yet to check the new sheets Apple presented at WWDC22, but assuming I'm right, your framework does a complete different job (both technically and visually) than Apple Sheets - and that's great, because that's exactly what I'm looking for :D

pedrommcarrasco avatar Jun 09 '22 19:06 pedrommcarrasco

That's true, thanks!

aheze avatar Jun 09 '22 20:06 aheze

Hey, I'm gonna have a go at porting this to SwiftUI

ghost avatar Jun 29 '22 21:06 ghost

Nice, thanks @FunkyMonkey729! Comment any problems you run into here

aheze avatar Jun 29 '22 21:06 aheze

I've got it kind of working, it's all good apart from animations a kinda broken, for example in this view,


struct ContentView: View {
    
    @State var toggleColour = false
    
    var body: some View {
        SplitSheetView(isPresented: $isPresented) {
            ZStack {
                if toggleColour {
                    Color.orange
                } else {
                    Color.green
                }
                Button("Toggle colour") {
                    withAnimation {
                        toggleColour.toggle()
                    }
                }
            }
        } sheet: {
            Color.red
        }
    }
}

it wouldn't animate between green and orange, only cut between them. Also observing the showing property to update isPresented breaks the presenting and dismiss animations. It seems that UIHostingController breaks all animations where the state is outside its root view. I'll try and think of a solution tomorrow, but I'm not sure it's possible without rewriting the whole thing in SwiftUI.

ghost avatar Jun 29 '22 23:06 ghost

@FunkyMonkey729 any updates on this? Would love to use something like this in my SwiftUI project.

LeoSM-07 avatar Jul 05 '22 00:07 LeoSM-07

@LeoSM-07 I can't find a way of getting the main view to observe if the sheet is showing or not without breaking the presenting and hiding animations. Pretty sure it's impossible as it involves redrawing the SwiftUI views as the presenting animation happens, which breaks the animation. Might try and rewrite it all in SwiftUI if I have time this week.

ghost avatar Jul 05 '22 23:07 ghost