aheze / SplitSheet

A lightweight, fully interactive split-screen sheet.
MIT License
188 stars 7 forks source link

SwiftUI Support #1

Open pedrommcarrasco opened 2 years ago

pedrommcarrasco commented 2 years ago

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

aheze commented 2 years ago

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!

pedrommcarrasco commented 2 years ago

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

aheze commented 2 years ago

That's true, thanks!

ghost commented 2 years ago

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

aheze commented 2 years ago

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

ghost commented 2 years ago

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.

LeoSM-07 commented 2 years ago

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

ghost commented 2 years ago

@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.