[SWIFT] How to disable user operations during asynchronous processing

problem

There is an asynchronous process called account creation, but I want to disable user operations during creation. However, there seems to be no way to disable user operations even after checking. Therefore, we examined whether it could be solved by using ZStack and overlaying View on top of it.

Solutions

As shown in the code below, when I tried overlaying Color.white only when isBusy was true, I was able to confirm that the View below could not be operated, so this seems to be good. If there is a better way, I would appreciate it if you could comment ...

ZStack{
	VStack{
		TextField("username", text: $vm.userName)
			.autocapitalization(.none)
			.textFieldStyle(RoundedBorderTextFieldStyle())
		TextField("mail address", text: $vm.emailAddress)
			.autocapitalization(.none)
			.textFieldStyle(RoundedBorderTextFieldStyle())
		SecureField("password", text: $vm.password)
			.autocapitalization(.none)
			.textFieldStyle(RoundedBorderTextFieldStyle())
		SecureField("Password confirmation", text: $vm.passwordConfirm)
			.autocapitalization(.none)
			.textFieldStyle(RoundedBorderTextFieldStyle())
		if vm.validationText != "" {
			Text(vm.validationText)
				.foregroundColor(.red)
				.font(.footnote)
		}
		Button(
			action: {
				vm.createAccount()
			}
		){
			Text("Account creation")
				.padding(4)
				.frame(maxWidth: .infinity)
				.foregroundColor(Color.white)
				.background(Color.gray)
				.cornerRadius(8)			
		}
	}
	.padding(.horizontal)
		
	if vm.isBusy {
		Color.white
			.opacity(0.7)
			.edgesIgnoringSafeArea(.all)
			.overlay(
				ProgressView("Creating an account...")
					.foregroundColor(.black)
			)
	}
}

ezgif.com-gif-maker (2).gif

Recommended Posts

How to disable user operations during asynchronous processing
How to implement asynchronous processing in Outsystems
[RuboCop] How to disable warnings
[Rails] How to disable turbolinks
[Processing × Java] How to use variables
[Processing × Java] How to use arrays
How to prevent duplicate processing by addEventListener
[Processing × Java] How to use the loop
[Processing × Java] How to use the class
[Processing × Java] How to use the function
How to make asynchronous pagenations using Kaminari
How to test interrupts during Thread.sleep with JUnit
[Swift UI] How to disable ScrollsToTop of ScrollView
How to use scope and pass processing (Jakarta)
How to execute processing before and after docker-entrypoint.sh
How to redirect after user login with Spring-security
How to deploy
How to make an image partially transparent in Processing
How to make batch processing with Rails + Heroku configuration
How to implement login request processing (Rails / for beginners)
[Rails, JS] How to implement asynchronous display of comments
How to update devise user information without a password
[swift5] How to execute processing when tabBar is tapped
How to standardize operations on sets -First class collection-
[Kotlin] How to get IP address and user agent