1

Notice in the gif that once I navigate and dismiss the new view, I am unable to navigate back! Is this a SwiftUI bug or a misuse of NavigationLinks?


struct ContentView: View {
    var body: some View {
        return NavigationView {
            NavigationLink(destination: FakeView1()) {
                Text("Navigate")
            }
        }
    }
}

struct FakeView1: View {
    var body: some View {
        Text("Hey")
    }
}

Video

natecraft1
  • 2,737
  • 9
  • 36
  • 56
  • https://stackoverflow.com/questions/56829974/swiftui-how-to-push-to-next-screen-when-tapping-on-button/58776772#58776772 – Rohit Makwana Dec 26 '19 at 05:01
  • Looks like it's a bug. Please see [this](https://stackoverflow.com/q/57433049/3687801) – nayem Dec 26 '19 at 05:03
  • 1
    [An extensive discussion](https://forums.developer.apple.com/thread/124757) from apple developer forum regarding this issue. It seems there is no workaround until now. – nayem Dec 26 '19 at 05:15
  • I could suppose you updated Xcode to 11.3... I recommend to downgrade to 11.1. – Asperi Dec 26 '19 at 05:22
  • Wow, okay thanks. I'm in no rush so I'll just wait until it's behaving as expected. I assume Apple is aware of this then... – natecraft1 Dec 26 '19 at 05:25
  • Check out my solution [here](https://stackoverflow.com/a/59933501/4067700) – Victor Kushnerov Jan 27 '20 at 15:58

2 Answers2

1

This seems swiftUI bug. I also faced the same issue so, I have used this workaround for it.

struct ContentView: View {

@State var isFakeActive: Bool = false

var body: some View {
    NavigationView {
        NavigationLink(destination: FakeView1(isFakeActive: self.$isFakeActive), isActive: self.$isFakeActive) {
            Text("Navigate")
        }
    }
  }
}

And for your FakeView1 class.

struct FakeView1: View {

@Binding var isFakeActive: Bool

var body: some View {
    Text("Hey")
        .navigationBarItems(leading: Button(action: {
            self.isFakeActive = false
        }, label: {
            HStack {
                Image(systemName: "arrow.left")
                Text("Back")
            }
        }))
    }
}

I have tested and it is working fine.

kchopda
  • 312
  • 4
  • 16
1

it's simulators bug.Try with your device

ZhanKail
  • 31
  • 5