Launch Full Immersive Space from NavigationLink button

I am trying to launch openImmersiveSpace, but seem like there is an issue with the openImmersiveSpace Task.

Error: Static method 'buildExpression' requires that 'Task<OpenImmersiveSpaceAction.Result, Never>' conform to 'View'

Here is the code and the error shows up on the "Task" line.

import SwiftUI
import RealityKit
import RealityKitContent

struct TestView: View {
    
    @Environment(\.openImmersiveSpace) var openImmersiveSpace
    @Environment(\.dismissImmersiveSpace) var dismissImmersiveSpace

    var body: some View {
        
        VStack{
            Text("Open Full Immersive & switch to NextViewArea")
                
            NavigationLink {
                Task {
                    await openImmersiveSpace(id: "ImmersiveSpace")
                }
                NextViewArea()
            } label:{
                Label(" Enter Full Immersive Space")
            }
        }
    }
}

How can I move onto the next view area in the floating window while also launching full immersive space. Any help would be much appreciated.

Answered by DTS Engineer in 787651022

Hello,

The error message is saying that the compiler expected a type that conforms to View, but Task does not conform to View.

Most likely what you wanted to do here is add the task on to the destination view:

NextViewArea()
    .task {
        // open the immersive space here if it makes sense to do so.
    }
Accepted Answer

Hello,

The error message is saying that the compiler expected a type that conforms to View, but Task does not conform to View.

Most likely what you wanted to do here is add the task on to the destination view:

NextViewArea()
    .task {
        // open the immersive space here if it makes sense to do so.
    }
Launch Full Immersive Space from NavigationLink button
 
 
Q