Skip to content

Re-enable animations inside modal presentation modifiers #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025

Conversation

mikhailChelbaev
Copy link
Collaborator

Problem

Placing any modal on a parent view unexpectedly turned off every SwiftUI animation in that parent hierarchy. Example:

VStack {
  SULoading()               // ← should spin
  Button("Show Modal") { isPresented.toggle() }
}
.bottomModal(isPresented: $isPresented) {
  Text("Modal Content")
}

Observed: the SULoading spinner froze as soon as the bottomModal is added—even though the modal is not presented.

Root cause

ModalPresentationModifier ended with:

.transaction { $0.disablesAnimations = true }

Because a Transaction propagates down the view tree, this flag disabled all descendant animations, including those unrelated to the modal itself.

Fix

Immediately reset the flag for the caller’s content:

content                          // original body’s `content`
  .transaction { $0.disablesAnimations = false }   // ✅ re-enable for content
  ...
  .fullScreenCover { ... }
  .transaction { $0.disablesAnimations = true }    // 🚫 disable for `fullScreenCover`
  • The inner .transaction { … = false } is higher in the hierarchy, so every animation in the caller’s view (including SULoading) now runs normally.
  • The outer .transaction { … = true } still prevents unwanted implicit animations during presentation/dismissal state changes.

@mikhailChelbaev mikhailChelbaev self-assigned this Jun 19, 2025
@mikhailChelbaev mikhailChelbaev merged commit 4088e69 into dev Jun 19, 2025
1 check passed
@mikhailChelbaev mikhailChelbaev deleted the fix-animations-with-modal branch June 19, 2025 14:11
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