SlideOverCard icon indicating copy to clipboard operation
SlideOverCard copied to clipboard

SOCManager doesn't work inside sheet

Open 0xifarouk opened this issue 3 years ago • 2 comments

If I tried to present a card using the SOCManager from a Sheet, it doesn't work.

Sample Code:

struct ContentView: View {
    
    @State private var isShowingCard: Bool = false
    @State private var isShowingSheet: Bool = false
    
    var body: some View {
        
        NavigationView {
            VStack {
                Button("Show Sheet") {
                    isShowingSheet.toggle()
                }
            }
            .navigationTitle("Card Test")
            .sheet(isPresented: $isShowingSheet, content: {
                Button("Show Card") {
                    SOCManager.present(isPresented: $isShowingCard) {
                        ZStack {
                            Text("Card")
                        }
                    }
                }
            })
        }
    }
}

Error message in terminal:

2021-06-02 14:54:58.677044+0300 CardTest[53318:3531446] [Presentation] Attempt to present <TtGC7SwiftUI19UIHostingControllerGV13SlideOverCard13SlideOverCardGVS_6ZStackVS_4Text__: 0x7faab5d29920> on <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x7faab5f05810> (from <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier_: 0x7faab5f05810>) which is already presenting <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x7faab5d12080>.

0xifarouk avatar Jun 02 '21 11:06 0xifarouk

same for modal presentation

RolandasRazma avatar Jan 31 '22 10:01 RolandasRazma

https://github.com/joogps/SlideOverCard/blob/791197c26a0fea83fcf31b1e9fb9a324db7a4b0b/Sources/SlideOverCard/Manager.swift#L22 this is not correct, when you have modal sheet presented already you will pick wrong VC to present against. You need to iterate over all children to find top most view controller. Something like https://stackoverflow.com/questions/6131205/how-to-find-topmost-view-controller-on-ios

https://github.com/joogps/SlideOverCard/blob/791197c26a0fea83fcf31b1e9fb9a324db7a4b0b/Sources/SlideOverCard/Manager.swift#L36 this is not correct even if you apply same fix as above because developer might call function without SlideOverCard presented and you will dismiss wrong VC

RolandasRazma avatar Jan 31 '22 10:01 RolandasRazma