Hello there!
I'm trying to implement ForEachStore within a TabView + PageStyle
Here is my childView's state (reduced state):
public struct State: Equatable, Identifiable {
// MARK: Internal
public let id: String
public let index: Int
public init( index: Int) {
self.index = index
self.id = index.description
}
}
In my parent's view I'm doing this to implement a PagedStyle TabView
.
@ViewBuilder
func contentView(
singleBooking: CarEntrySteps.Infos.SingleBooking,
store: CarEntrySteps.Store,
viewStore: CarEntrySteps.ViewStore
) -> some View {
TabView(selection: viewStore.presentedStepIndexBinding) {
IfLetStore(
store.carEntryInitialStep,
then: CarEntryInitialStep.View.init(store:)
)
.tag(0)
ForEachStore(store.carAccessSteps) { store in
CarEntryStep.View(store: store)
.tag(ViewStore(store).index)
}
}
.tabViewStyle(
PageTabViewStyle(indexDisplayMode: .never)
)
.overlay(
PageIndicator(
count: viewStore.entryStepsCount,
selectedIndex: viewStore.presentedStepIndexBinding
),
alignment: .bottom
)
}
Everything is working as expected but my question is here:
CarEntryStep.View(store: store)
.tag(ViewStore(store).index)
Is it okay, to init a temporary ViewStore just to get access to my index
property on that child state ?
Thanks.