Replies: 2 comments
-
Hi @natemann, it's annoying, but I think the only solution right now is to nest SwitchStore(…) {
CaseLet(…) { … }
…
Default {
SwitchStore(…) {
CaseLet(…) { … }
}
}
} We have experimented with lifting the restriction using |
Beta Was this translation helpful? Give feedback.
-
Hi @natemann, I did face a similar issue with 17 cases this is how I fix it it might not be the best solution but it works well for a larger number of The basic Idea is to have a something to group them, here the public struct Modal: ReducerProtocol {
public enum State: Equatable {
case addArtifacts(AddFavoriteArtifact.State)
case addProject(AddProject.State)
case buildScreen(BuildDetailed.State)
case editArtifact(EditFavoriteArtifact.State)
case editWorkflow(EditWorkflow.State)
case magicLink(UserWelcome.State)
case mail(MailReducer.State)
case onboarding(Onboarding.State)
case restoreFromCloud(RestoreFromCloud.State)
case settings(SettingsRR.State)
case shareAccess(ShareAccess.State)
case subscriptionEnding(SubscriptionEnding.State)
case subscriptionFlow(SubscriptionFlow.State)
case updateToken(UpdateToken.State)
case weatherAndTrend(WeatherAndTrend.State)
case safari(SafariLink.State)
case share(SheetState.State)
public var group: Int {
switch self {
case .addArtifacts: return 1
case .addProject: return 1
case .buildScreen: return 1
case .editArtifact: return 1
case .editWorkflow: return 1
case .magicLink: return 1
case .mail: return 2
case .subscriptionFlow: return 2
case .subscriptionEnding: return 2
case .restoreFromCloud: return 2
case .safari: return 2
case .share: return 2
case .settings: return 3
case .shareAccess: return 3
case .updateToken: return 3
case .weatherAndTrend: return 3
case .onboarding: return 3
}
}
}
} func group1(_ presentedModalStore: StoreOf<Modal>) -> some View {
SwitchStore(presentedModalStore) {
CaseLet(state: /Modal.State.addArtifacts, action: Modal.Action.addArtifacts, then: AddFavoriteArtifactsView.init(store:))
CaseLet(state: /Modal.State.addProject, action: Modal.Action.addProject, then: AddProjectView.init(store:))
CaseLet(state: /Modal.State.buildScreen, action: Modal.Action.buildScreen, then: BuildDetailedView.init(store:))
CaseLet(state: /Modal.State.editWorkflow, action: Modal.Action.editWorkflow, then: { EditWorkflowView(store: $0) })
CaseLet(state: /Modal.State.editArtifact, action: Modal.Action.editArtifact, then: EditFavoriteArtifactView.init(store:))
CaseLet(state: /Modal.State.magicLink, action: Modal.Action.magicLink, then: UserWelcomeView.init(store:))
}
}
func group2(_ presentedModalStore: StoreOf<Modal>) -> some View {
SwitchStore(presentedModalStore) {
CaseLet(state: /Modal.State.subscriptionEnding, action: Modal.Action.subscriptionEnding, then: SubscriptionEndingView.init(store:))
CaseLet(state: /Modal.State.subscriptionFlow, action: Modal.Action.subscriptionFlow, then: SubscriptionFlowView.init(store:))
CaseLet(state: /Modal.State.mail, action: Modal.Action.mail) { store in
if MFMailComposeViewController.canSendMail() == false {
Text("Unable to send email")
} else {
MailView(store: store)
}
}
// CaseLet(state: /Modal.State.safari, action: Modal.Action.safari, then: SafariView.init(store:))
// CaseLet(state: /Modal.State.share, action: Modal.Action.share, then: ShareSheet.init(store:))
CaseLet(state: /Modal.State.restoreFromCloud, action: Modal.Action.restoreFromCloud, then: RestoreFromCloudView.init(store:))
}
}
func group3(_ presentedModalStore: StoreOf<Modal>) -> some View {
SwitchStore(presentedModalStore) {
CaseLet(state: /Modal.State.settings, action: Modal.Action.settings, then: SettingsView.init(store:))
CaseLet(state: /Modal.State.shareAccess, action: Modal.Action.shareAccess, then: ShareAccessView.init(store:))
CaseLet(state: /Modal.State.updateToken, action: Modal.Action.updateToken, then: UpdateTokenView.init(store:))
CaseLet(state: /Modal.State.weatherAndTrend, action: Modal.Action.weatherAndTrend, then: WeatherAndTrendView.init(store:))
CaseLet(state: /Modal.State.onboarding, action: Modal.Action.onboarding, then: OnboardingView.init(store:))
}
}
func genericModalBuilderForIndex(_ index: UUID) -> some View {
return IfLetStore(
self.store.scope(state: { $0.modals[id: index] }, action: { AppFeature.Action.modals(id: index, action: $0) }),
then: { presentedModalStore in
NavigationView {
switch ViewStore(presentedModalStore).block {
case 1: group1(presentedModalStore)
case 2: group2(presentedModalStore)
case 3: group3(presentedModalStore)
default: Text("This state is not implemented(\(#file):\(#line))").foregroundColor(.red).font(.largeTitle).background(Color.black)
}
}
}
)
} I hope it helps |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a switchStore with ten cases. It looks like the limit in the library is 9. Is there a way to add a 10th case, or will the library need to be updated?
Beta Was this translation helpful? Give feedback.
All reactions