SlideOverCard icon indicating copy to clipboard operation
SlideOverCard copied to clipboard

Sheet onDismiss is called immediately when View appeared

Open chichkanov opened this issue 1 year ago • 3 comments

Steps to repro

Case 1

  1. Attach .slideOverCard(item: ...) modifier to a View
  2. Implement onDismiss closure
  3. Closure is executed 5 times when sheet is not opened

Case 2

  1. Attach .slideOverCard(isPresented: ...) modifier to a View
  2. Implement onDismiss closure
  3. Closure is executed 2 times when sheet is not opened

Env Simulator iPhone 15 pro max, iOS 17.4

Code Sample 1

struct Sheet3: Identifiable {
    var id: String { title }
    let title: String
}

struct ContentView: View {
    
    @State private var showSheet3: Sheet3? = nil
    
    var body: some View {
        VStack {
            Button("Show sheet #3") { showSheet3 = .init(title: "Sheet #3")  }
        }
        .slideOverCard(item: $showSheet3, onDismiss: { print("Sheet #3 dismiss") }) { sheet3 in
            Text(sheet3.title)
        }
    }
}

Console Output 1

Sheet #3 dismiss
Sheet #3 dismiss
Sheet #3 dismiss
Sheet #3 dismiss
Sheet #3 dismiss

Code Sample 2

struct ContentView: View {
    
    @State private var showSheet1 = false
    
    var body: some View {
        VStack {
            Button("Show sheet #1") { showSheet1 = true }
        }
        .slideOverCard(isPresented: $showSheet1, onDismiss: { print("Sheet #1 dismiss") }) {
            Text("Sheet #1")
        }
    }
}

Console Output 2

Sheet #1 dismiss
Sheet #1 dismiss

chichkanov avatar Apr 11 '24 11:04 chichkanov

I encountered the same problem, have you found any solutions to it?

cerfking avatar May 22 '24 00:05 cerfking

I encountered the same problem, have you found any solutions to it?

Hey, I haven't. Just continue sticking to a SwiftUI .sheet with presentation detents

chichkanov avatar May 22 '24 05:05 chichkanov

Oh thought I have done something wrong, but seems like this is a common issue in version 3.0.1. Have you found any solutions or workarounds for this problem? Do we really have to go back to the previous version of this package? 🤔

Bartozo avatar Nov 10 '24 18:11 Bartozo