Skip to content

Instantly share code, notes, and snippets.

@rushairer
Created August 7, 2021 16:26
Show Gist options
  • Select an option

  • Save rushairer/e18095f9d642800adb5f1ccf4628e0fa to your computer and use it in GitHub Desktop.

Select an option

Save rushairer/e18095f9d642800adb5f1ccf4628e0fa to your computer and use it in GitHub Desktop.
NavigationLinkBugDemoApp
//
// ContentView.swift
// Shared
//
// Created by Abenx on 2021/8/8.
//
import SwiftUI
/// Demo of NavigationLink causing page problems
///
/// Problem description: When the following structure is used, after entering level3. If the app loses focus, such as drawing out of the control center or multi-page manager, it will cause the page to refresh and render, and eventually jump to level 2.
/// iPhone 12 Pro Max / iOS 15 beta 4 has this problem
/// iPhone 12 Pro Max / iOS 14.6 has no such problem
/// Xcode Version: 12.5.1 (12E507) & 13.0 beta 4 (13A5201i)
struct ContentView: View {
/// If you comment out this line of code, there will be no problem.
@Environment(\.openURL) var openURL
@State private var isOK: Bool = false
var body: some View {
NavigationView {
NavigationLink("Goto Level 2", destination: Level2View().onAppear {
/// If you comment out this line of code, there will be no problem.
isOK = false
})
}
}
}
struct Level2View: View {
var body: some View {
/// If you don't use GeometryReader, there is no problem.
GeometryReader {proxy in
NavigationLink("Goto Level 3", destination: Text("I am in Level 3"))
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment