embedded stacks

Afternoon All,

Im trying to make a view that contains a view within it. Ie one button will take you to a given screen and produce a desired out put "path" , while the other button will take you into a loop with a given out put "Intensity" being either H,M,L.

I want to keep the chevron back button at the top of the screen on all views but it only conforms to Path.

below is an example of the code, I understand you can have two different stacks in the same view as the "parent / root will take priority" but don't know how to correct.

import SwiftUI

struct questionFour: View { @StateObject private var appData = AppData() init(){ UINavigationBar.setAnimationsEnabled(false) }

var body: some View {
    NavigationView {
        EmptyBattery(appData: appData)
    }
}

}

struct EmptyBattery : View { @ObservedObject var appData: AppData

var body : some View {
    BatteryTButton(B1Color: .clear, B2Color: .clear, B3Color: .clear, appData: appData)
}

}

struct RedBattery : View { @ObservedObject var appData: AppData

var body : some View {
        BatteryTButton(B1Color: .clear, B2Color: .clear, B3Color: .red, appData: appData)
}

}

struct OrangeBattery : View { @ObservedObject var appData: AppData

var body : some View {
        BatteryTButton(B1Color: .clear, B2Color: .orange, B3Color: .orange, appData: appData)
}

}

struct GreenBattery : View { @ObservedObject var appData: AppData

var body: some View {

        BatteryTButton(B1Color: .green, B2Color: .green, B3Color:.green, appData: appData)
}

}

struct questionFour_Previews: PreviewProvider { static var previews: some View { questionFour() } }

struct BatteryTButton : View { var B1Color : Color var B2Color : Color var B3Color : Color @ObservedObject var appData: AppData @State private var isGreenBatteryActive = false @State private var isOrangeBatteryActive = false @State private var isRedBatteryActive = false

var body: some View {
    ZStack {
        VStack(spacing: 15) {
            Text("Intensity?")
                .font(.largeTitle)
            Spacer()
            Image("EmptyBattery")
               
            Spacer()
            NavigationLink(value: 11) {
                Image("Tick")
                    .resizable()
                    .frame(width: 120,height:100)
            }
        }
        .navigationDestination(for: Int.self) { value in
            questionFive()
        }
        VStack(spacing: 15) {
            Button(action: {
                isGreenBatteryActive = true
                appData.intensity = "H"
                print("Your app intensity is:", appData.intensity)
            }) {
                Rectangle()
                    .fill(B1Color)
                    .frame(width: 200, height: 120)
                    .cornerRadius(20)
            }
            .fullScreenCover(isPresented: $isGreenBatteryActive) {
                GreenBattery(appData: appData)
                    //.navigationBarBackButtonHidden(true)
            }

            Button(action: {
                isOrangeBatteryActive = true
                appData.intensity = "M"
                print("Your app intensity is:", appData.intensity)
            }) {
                Rectangle()
                    .fill(B2Color)
                    .frame(width: 200, height: 120)
                    .cornerRadius(20)
            }
            .fullScreenCover(isPresented: $isOrangeBatteryActive) {
                OrangeBattery(appData: appData)
                    //.navigationBarBackButtonHidden(true)
            }
            Button(action: {
                isRedBatteryActive = true
                appData.intensity = "L"
                print("Your app intensity is:", appData.intensity)
            }) {
                Rectangle()
                    .fill(B3Color)
                    .frame(width: 200, height: 120)
                    .cornerRadius(20)
            }
            .fullScreenCover(isPresented: $isRedBatteryActive) {
                RedBattery(appData: appData)
                    //.navigationBarBackButtonHidden(true)
            }
        }
        .padding(.bottom, 30)
    }
}

}

Your question is hard to answer as it is quite incomplete.

Could you provide complete code ? AppData definition is missing as well as questionFive or images.

You have not declared NavigationStack, hence the error

NavigationLink presenting a value must appear inside a NavigationStack or NavigationSplitView. Link will be disabled.

Which means the code you posted cannot run.

You should have something like:

    var body: some View {
        NavigationStack {
            ZStack {

And explain what those buttons are:

Ie one button will take you to a given screen and produce a desired out put "path" , while the other button will take you into a loop with a given out put "Intensity" being either H,M,L.

Also, explain more clearly what you get:

I want to keep the chevron back button at the top of the screen on all views but it only conforms to Path.

Also note that var names should start with lowerCase

var b1Color : Color

Please format code with code formatter tool:

struct questionFour: View {
    @StateObject private var appData = AppData()
    
    init(){
        UINavigationBar.setAnimationsEnabled(false)
    }
    
    var body: some View {
        NavigationView {
            EmptyBattery(appData: appData)
        }
    }
}

struct EmptyBattery : View { @ObservedObject
    var appData: AppData
    var body : some View {
        BatteryTButton(B1Color: .clear, B2Color: .clear, B3Color: .clear, appData: appData)
    }
}

struct RedBattery : View { @ObservedObject
    var appData: AppData
    var body : some View {
        BatteryTButton(B1Color: .clear, B2Color: .clear, B3Color: .red, appData: appData)
    }
}

struct OrangeBattery : View { @ObservedObject
    var appData: AppData
    var body : some View {
        BatteryTButton(B1Color: .clear, B2Color: .orange, B3Color: .orange, appData: appData)
    }
}

struct GreenBattery : View { @ObservedObject
    var appData: AppData
    var body: some View {
        
        BatteryTButton(B1Color: .green, B2Color: .green, B3Color:.green, appData: appData)
    }
}

struct questionFour_Previews: PreviewProvider {
    static var previews: some View {
        questionFour()
    }
}

struct BatteryTButton : View {
    var B1Color : Color
    var B2Color : Color
    var B3Color : Color
    @ObservedObject var appData: AppData
    @State private var isGreenBatteryActive = false
    @State private var isOrangeBatteryActive = false
    @State private var isRedBatteryActive = false
    
    var body: some View {
        ZStack {
            VStack(spacing: 15) {
                Text("Intensity?")
                    .font(.largeTitle)
                Spacer()
                Image("EmptyBattery")
                
                Spacer()
                NavigationLink(value: 11) {
                    Image("Tick")
                        .resizable()
                        .frame(width: 120,height:100)
                }
            }
            .navigationDestination(for: Int.self) { value in
                questionFive()
            }
            VStack(spacing: 15) {
                Button(action: {
                    isGreenBatteryActive = true
                    appData.intensity = "H"
                    print("Your app intensity is:", appData.intensity)
                }) {
                    Rectangle()
                        .fill(B1Color)
                        .frame(width: 200, height: 120)
                        .cornerRadius(20)
                }
                .fullScreenCover(isPresented: $isGreenBatteryActive) {
                    GreenBattery(appData: appData)
                    //.navigationBarBackButtonHidden(true)
                }
                
                Button(action: {
                    isOrangeBatteryActive = true
                    appData.intensity = "M"
                    print("Your app intensity is:", appData.intensity)
                }) {
                    Rectangle()
                        .fill(B2Color)
                        .frame(width: 200, height: 120)
                        .cornerRadius(20)
                }
                .fullScreenCover(isPresented: $isOrangeBatteryActive) {
                    OrangeBattery(appData: appData)
                    //.navigationBarBackButtonHidden(true)
                }
                Button(action: {
                    isRedBatteryActive = true
                    appData.intensity = "L"
                    print("Your app intensity is:", appData.intensity)
                }) {
                    Rectangle()
                        .fill(B3Color)
                        .frame(width: 200, height: 120)
                        .cornerRadius(20)
                }
                .fullScreenCover(isPresented: $isRedBatteryActive) {
                    RedBattery(appData: appData)
                    //.navigationBarBackButtonHidden(true)
                }
            }
            .padding(.bottom, 30)
        }
    }
}
embedded stacks
 
 
Q