SwiftUI Preview pauses whenever I change a file

766 Views Asked by At

I have a SwiftUI View (LandingScreenView.swift) that is using a button style implemented on another file (DefaultButtonStyle.swift). When I go to that Button Style file and change a line of code there, then return to the LandingScreenView.swift the SwiftUI preview has paused. It occurs always. This is a very fresh project with only those 2 files, I have one copy script on my build phases and I already set it to run "For install builds only". How can I make the SwiftUI works without pausing?

Xcode Version: 12.5

(I'm running it on an M1 MacBook, don't know if it makes any difference here)

import SwiftUI

struct LandingScreenView: View {
    var body: some View {
        VStack {
            Spacer().frame(width: 0, height: 44, alignment: .center)
            Text("app.title")
                .font(.appTitle)
                .frame(minWidth: 0,
                       maxWidth: .infinity,
                       alignment: .center)
            
            Spacer()
            VStack {
                Button("landing.login.button", action: {
                    
                })
                .buttonStyle(DefaultButton())

                Button("landing.about.button", action: {
                    
                })
                .buttonStyle(DefaultButton())
            }
            .frame(minWidth: 0, maxWidth: .infinity, alignment: .topLeading)
            
            Spacer()
        }.padding()
    }
}

struct LandingScreenView_Previews: PreviewProvider {
    static var previews: some View {
        LandingScreenView()
    }
}
import SwiftUI

struct DefaultButton: ButtonStyle {
    func makeBody(configuration: Configuration) -> some View {
        HStack {
            configuration.label
                .padding()
                .frame(minWidth: 0,
                       maxWidth: .infinity,
                       minHeight: 44,
                       idealHeight: 44,
                       alignment: .center)
                
                .background(Color.blue)
                .foregroundColor(.white)
                .cornerRadius(40)
        }
    }
}

Check Pods Manifest.lock

EDIT:

My problem here is not that the preview has to recompile it every time. What seems a little bit weird is that I have to press the resume button every time I go out the screen and return.

enter image description here

0

There are 0 best solutions below