Last active
April 1, 2021 20:36
-
-
Save jordibruin/a36be3d34652d689125247f893dd1a27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// constraint test | |
// | |
// Created by Jordi Bruin on 01/04/2021. | |
// | |
import SwiftUI | |
// 1. Click the "Open Detail View" button | |
// 2. Go back | |
// 3. Click the "Open Detail View" button again | |
// 4. Click the "Present Modal" | |
// 5. It will crash | |
struct ContentView: View { | |
var body: some View { | |
NavigationView { | |
NavigationLink( | |
destination: DetailView(), | |
label: { | |
Text("Open Detail View") | |
}) | |
// If you comment this out, it does not crash | |
.toolbar { | |
ToolbarItem(placement: .navigationBarTrailing) { | |
Menu { | |
ForEach(1...5, id: \.self) { index in | |
Button { | |
print("tap menu item") | |
} label: { | |
HStack { | |
Text("Menu Item \(index)") | |
} | |
} | |
} | |
} label: { | |
Text("Filter") | |
} | |
} | |
} | |
} | |
} | |
} | |
struct DetailView: View { | |
@State var modalType: ModalType? | |
var body: some View { | |
Button(action: { | |
modalType = .modalWithTabView | |
}, label: { | |
Text("Present Modal") | |
}) | |
.sheet(item: $modalType, content: { $0 }) | |
} | |
} | |
enum ModalType: Identifiable, View { | |
case modalWithTabView | |
var id: String { | |
return "modalWithTabView" | |
} | |
var body: some View { | |
switch self { | |
case .modalWithTabView: | |
ModalWithTabView() | |
} | |
} | |
} | |
struct ModalWithTabView: View { | |
@State var currentStep = 0 | |
var body: some View { | |
TabView(selection: $currentStep) { | |
ForEach (0 ..< 10) { index in | |
Text("Page \(index)") | |
.tag(index) | |
} | |
} | |
// If you comment this out, it does not crash | |
.tabViewStyle(PageTabViewStyle()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment