Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sheet onDismiss is called immediately when View appeared #31

Open
chichkanov opened this issue Apr 11, 2024 · 2 comments
Open

Sheet onDismiss is called immediately when View appeared #31

chichkanov opened this issue Apr 11, 2024 · 2 comments

Comments

@chichkanov
Copy link

chichkanov commented Apr 11, 2024

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
@cerfking
Copy link

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

@chichkanov
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants