-
Hello I'm wondering what is the way of using First attempt: var body: some View {
TabView {
ForEach(childStack.value.items) { item in
}
}
} Said that:
Second attempt: var body: some View {
TabView {
ForEach(bottomNavItems) { item in
ChildView(child: item.child)
}
}
}
private struct ChildView: View {
let child: BottomNavChild
var body: some View {
switch child {
default:
Text(child.description)
}
}
}
struct BottomNavItem: Identifiable {
var id = UUID()
var title: Text
var image: Image
var tag: Int
var child: Child<AnyObject, BottomNavChild>
} and I got:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
I faced this issue too. The thing is that |
Beta Was this translation helpful? Give feedback.
-
Following the examples and some testing I was able to use the default struct BottomNavView: View {
private let component: BottomNav
@State private var selection: BottomNavItem = .homes
private let bottomNavItems = [
TabItem(item: .homes, title: "Homes", image: "home-icon"),
TabItem(item: .access, title: "Access", image: "access-icon"),
TabItem(item: .calendar, title: "Calendar", image: "calendar-icon"),
TabItem(item: .profile, title: "Profile", image: "profile-icon"),
]
@ObservedObject
private var childStack: ObservableValue<ChildStack<AnyObject, BottomNavChild>>
private var activeChild: BottomNavChild { childStack.value.active.instance }
init(_ component: BottomNav) {
self.component = component
childStack = ObservableValue(component.childStack)
}
var body: some View {
TabView(selection: $selection) {
ForEach(bottomNavItems) { item in
ChildView(activeChild).tabItem {
Label(item.title, image: item.image)
Text(item.title)
}.tag(item.item)
}
}
.onChange(of: selection) { newValue in
component.navigateTo(item: newValue)
}
}
}
private struct ChildView: View {
let child: BottomNavChild?
init(_ child: BottomNavChild?) {
self.child = child
}
var body: some View {
switch child {
case let child as BottomNavChild.HomesTab: Text(child.description)
case let child as BottomNavChild.AccessTab: Text(child.description)
case let child as BottomNavChild.CalendarTab: Text(child.description)
case let child as BottomNavChild.ProfileTab: Text(child.description)
default:
Text("EMPTY")
}
}
}
struct TabItem: Identifiable {
var id = UUID()
var item: BottomNavItem
var title: String
var image: String
} |
Beta Was this translation helpful? Give feedback.
Following the examples and some testing I was able to use the default
TabView
: