0

I'm encountering an error when using the fullScreenCover modifier in SwiftUI. The error message states: "A new orientation transaction token is being requested while a valid one already exists." The error occurs during a fullscreen transition when dismissing the current view and presenting a new view (fromVC and toVC references are provided in the error message). The window and scene orientations are both set to portrait, and there is an existing active orientation transaction token with the original orientation also set to portrait.

I have tried various solutions, including setting the windowOrientation and sceneOrientation explicitly, wrapping the fullScreenCover in a NavigationStack, and dismissing the current view using presentationMode.wrappedValue.dismiss() when the new view is presented. However, the error persists.

This is my code Base


import SwiftUI
import Firebase
import FirebaseCore
import FirebaseAuth


@available(iOS 16.0, *)
struct SignUp: View {
    @StateObject private var viewModal = SignViewData()
    @Environment(\.presentationMode) var presentationMode
    @State private var mainView = false
    @State private var SignInView = false
    
    var body: some View {
        ZStack {
            VStack(alignment: .leading){
                Text("Sign Up")
                    .font(.largeTitle)
                    .fontWeight(.bold)
                    .foregroundStyle(.linearGradient(colors: [.pink.opacity(0.6), .primary.opacity(0.5)], startPoint: .topLeading, endPoint: .bottomTrailing))
                    .padding(.leading,10)
                    .padding(.bottom,20)
                Section{
                    TextField("", text: $viewModal.text)
                        .textContentType(.emailAddress)
                        .keyboardType(.emailAddress)
                        .autocapitalization(.none)
                        .disableAutocorrection(true)
                        .placeholder(when: viewModal.text.isEmpty) {
                            Text("Email address")
                                .foregroundColor(.primary)
                                .blendMode(.overlay)
                        }
                        .customField(icon: "envelope.open.fill")
                    SecureField("", text: $viewModal.password)
                        .textContentType(.password)
                        .placeholder(when: viewModal.password.isEmpty) {
                            Text("Password")
                                .foregroundColor(.primary)
                                .blendMode(.overlay)
                        }
                        .customField(icon: "key.fill")
                    
                }
                .padding(.leading,10)
                .padding(.trailing,10)
                .padding(.bottom,10)
                
                Button {
                    Task{
                        do{
                            try await viewModal.signUp()
                            if viewModal.value == true{
                                DispatchQueue.main.async { // Add DispatchQueue.main.async block
                                    mainView.toggle()
                                }
                            }
                            return
                        }
                        catch {
                            print(error)
                        }
                    }
                } label: {
                    ButtonView(title: "Create Account")
                }
                .padding(.leading,10)
                .padding(.trailing,10)
                .fullScreenCover(isPresented: $mainView) {
// Any time i segue into this view i keep getting the error down below
                    NavigationStack{
                        RootView()
                    }
                }
                Divider()
                    .padding(5)
                    .padding(.leading,10)
                    .padding(.trailing,10)
                HStack{
                    Text("Already have an account?")
                        .font(.subheadline)
                        .foregroundStyle(.linearGradient(colors: [.pink.opacity(0.7), .primary.opacity(0.5)], startPoint: .topLeading, endPoint: .bottomTrailing))
                    Button {
                        SignInView.toggle()
                    } label: {
                        Text("Sign In")
                            .font(.subheadline)
                            .fontWeight(.semibold)
                            .foregroundColor(.black)
                    }
                }
                .fullScreenCover(isPresented:$SignInView){
                    NavigationStack{
                        SignIn()
                    }
                }
                .padding(.leading,20)
            }.padding(15)
                .frame(width: 400,height: 370)
                .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 30, style: .continuous))
                .shadow(color: Color("Shadow").opacity(0.3), radius: 10, x: 0, y: 10)
                .strokeStyle(cornerRadius: 30)
                .padding(20)
        }.background(
            Image("Background 4")
        )
    }
}

@available(iOS 16.0, *)
struct SignUp_Previews: PreviewProvider {
    static var previews: some View {
        SignUp()
    }
}

extension View {
    func placeholder<Content: View>(
        when shouldShow: Bool,
        alignment: Alignment = .leading,
        @ViewBuilder placeholder: () -> Content) -> some View {
            ZStack(alignment: alignment) {
                placeholder().opacity(shouldShow ? 1 : 0)
                self
            }
        }
}

2023-06-10 21:37:10.137760+0300 SignEase[50521:19426350] [Assert] A new orientation transaction token is being requested while a valid one already exists. reason=Fullscreen transition (dismissing): fromVC=<_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x13b80f200>; toVC=<_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x13a8d7c00>;; windowOrientation=portrait; sceneOrientation=portrait; existingTransaction=<_UIForcedOrientationTransactionToken: 0x280b814a0; state: active; originalOrientation: portrait (1)>

0 Answers0