swift icon indicating copy to clipboard operation
swift copied to clipboard

In Preview, the toolbar causes a crash.

Open gnksbm opened this issue 2 years ago • 1 comments

Description I recently found a bug related to toolbar.

Steps to reproduce This is the code that is causing the bug.

struct ContentView: View {
    @State var isPresented: Bool = false

    var body: some View {
        NavigationStack {
            VStack {
                
            }
            .toolbar {
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button {
                        isPresented = true
                    } label: {
                        Text("Click")
                    }
                }
            }
        }
        
        .sheet(isPresented: $isPresented) {

        }
    }
}

PreviewCrashed 001

If you enter the sheet once with the Button in the toolbar, then use the gesture or button(if sheet has Button to change isPresented) to return and press the Button in the toolbar again, the Preview will cause a Crash.

If you put the Button in VStack without putting it in the toolbar, there was no problem and this looks like there is a bug in the toolbar.

I shared this issue with people around me and tried it with another mac device, another Project, and I had a Preview Crash when I had the same symptoms or first pressed the Button.

I thought it was simply an error in Preview, but it also happened on the actual device.

  • On iPhone mini 13 (Device Build), at the same point as Crash in Preview, the Button no longer works and the app does not quit.

The case I checked without a bug.

  • Works fine on iPhone 14 (Simulator Build).

  • On iPad 9th (Device Build), Destination iPhone and Destination iPad both work fine.

  • Works fine on mac mini m2 (Device Build - Design for iPad).

Expected behavior Should not crash.

Environment

  • swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
  • Xcode Version 14.3.1 (14E300c)
  • iOS 16.4

gnksbm avatar Jul 18 '23 14:07 gnksbm

This seems like a SwiftUI issue, not an issue with the Swift language or tooling itself. Please repost on the Apple Developer Forums and I am sure you will receive the answer you were looking for.

itjustcrashed avatar Jul 29 '24 19:07 itjustcrashed