Skip to content

Comments

Refactor Toast Message Manager#1065

Merged
aaronbrethorst merged 1 commit intoOneBusAway:surveysfrom
mosliem:feature/surveys/refactor-toast-messages
Feb 25, 2026
Merged

Refactor Toast Message Manager#1065
aaronbrethorst merged 1 commit intoOneBusAway:surveysfrom
mosliem:feature/surveys/refactor-toast-messages

Conversation

@mosliem
Copy link
Contributor

@mosliem mosliem commented Feb 24, 2026

This PR refactors the ToastManager to remove its global singleton (ToastManager.shared) and migrate the app towards an explicit Dependency Injection (DI) pattern.

By tying the ToastManager lifecycle to the Application class and explicitly passing it down the hierarchy

What's Changed

  • Removed Global State: Dropped the shared property on ToastManager. It is now instantiated locally and attached to the core Application instance.
  • SwiftUI Integration: Updated UIKit extensions (showSuccessToast, showErrorToast) to expect a ToastManager argument. This argument is then passed to the hosting view's environment (.environmentObject(manager)).
  • SwiftUI Observation Updates: Updated ToastModifier and ToastContainerView to accept the ToastManager via @EnvironmentObject instead of directly referencing @ObservedObject var manager = ToastManager.shared.
  • Surveys Integration: Updated SurveyViewHostingProtocol to use the injected application.toastManager when posting survey-related feedback toasts.

@mosliem mosliem changed the base branch from main to surveys February 24, 2026 23:01
Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Mohamed, thanks for taking the time to clean up the ToastManager singleton. Migrating from ToastManager.shared to explicit dependency injection through the Application class is exactly the right direction — it makes the toast system testable, eliminates hidden global state, and aligns with the DI patterns used throughout the rest of the codebase. The change is well-scoped: the @EnvironmentObject wiring is correct, the new var application: Application { get } protocol requirement is cleanly satisfied by both existing conformers (MapViewController and StopViewController), and the hideToastMessage removal is justified since the ToastModifier binding already handles the reset automatically.

There's nothing left to change — this PR is ready to merge. Nice, focused refactoring.

@aaronbrethorst aaronbrethorst merged commit 34bf1f4 into OneBusAway:surveys Feb 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants