I currently have a view HostView
that provides HostSummaryView
and EditHostSummaryView
, where the former responds to editMode.wrappedValue? == .inactive
. HostView
looks like this:
struct HostView: View {
@Environment(\.editMode) var editMode
var body: some View {
HStack {
EditButton()
}
if editMode?.wrappedValue == .inactive {
HostSummary()
} else {
EditHostSummary()
}
}
}
I have a RootView
that contains a TabView
, which looks like this:
struct RootView: View {
@State private var selectedTab = 0
var body: some View {
TabView(selection: $selectedTab) {
View1()
.onTapGesture { self.selectedTab = 0 }
.tag(0)
View2()
.tag(1)
HostView()
.tag(2)
}
}
}
I tried passing the @Environment(\.editMode) var editMode
to HostView
, but that did not fix the problem. The EditButton
does not toggle editMode
in the HostView
. However, HostView
works when I access it through a non-TabView
view.
How can I get this to work?
I couldn't find a previous question about this but it is known that some things don't work from within a TabView
you have to push it down a View
.
I think it is considered a bug.
struct EditableHost: View {
@State private var selectedTab = 0
var body: some View {
TabView(selection: $selectedTab) {
Text("View 1")
.onTapGesture { self.selectedTab = 0 }
.tag(0)
Text("View 2")
.tag(1)
ParentHostView()
.tabItem { Text("host") }
.tag(2)
}
}
}
struct ParentHostView: View {
@State var active: Bool = true
var body: some View {
NavigationView{
NavigationLink(
destination: HostView(),
isActive: $active,
label: {
Text("HOST")
})
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct HostView: View {
@Environment(\.editMode) var editMode
var body: some View {
VStack{
HStack {
EditButton()
}
if editMode?.wrappedValue == .inactive {
Text("HostSummary")
} else {
Text("EditHostSummary")
}
}.navigationBarBackButtonHidden(true)
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments