pointfreeco / swift-composable-architecture

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind.
https://www.pointfree.co/collections/composable-architecture
MIT License
12.35k stars 1.44k forks source link

.send(.presentCustomAlert, animation: .none) method does not work when present / dismiss fullScreenCover #3017

Closed JongHoooon closed 5 months ago

JongHoooon commented 5 months ago

Description

I made custom alert. It presented by fullScreenCover. I want to present / dismiss it without animation.

when present

Reduce<State, Action> { state, action in
  switch action {

...

    case .someThingHappend:
      return .send(.presentAlert, animation: .none)      //  <-- I want to present without animation

...

    case .presentAlert:
      state.destination = .customAlert(.init(
          title: "alert title",
          message: "alert message"
      ))
      return .none

when dismiss


/* custom alert view */

...

  confirmButton() {
    store.send(.delegate(.confirm), animation: .none)    //  <-- I want to dismiss without animation
  }

...

/* cusomt alert reducer */

enum Action {
    case delegate(Delegate)
    @CasePathable
    enum Delegate: Equatable {
        case confirm
   }
}

/* parent view */

case .destination(.presented(.customAlert(.delegate(.confirm)))):
  state.destination = nil
  return .none

Checklist

Expected behavior

I want to present / dismiss full screen cover without animation

Actual behavior

I want to present / dismiss full screen cover with animation

Steps to reproduce

No response

The Composable Architecture version information

1.9.3

Destination operating system

iOS 17

Xcode version information

15.3

Swift Compiler version information

1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
stephencelis commented 5 months ago

Hi @JongHoooon! The animation parameter in TCA is simply a wrapper around withAnimation, so the behavior you're seeing is how vanilla SwiftUI behaves, and not a bug with TCA. As such I'm going to convert this to a discussion, but I think you should first try to present/dismiss the full-screen cover without animation in vanilla SwiftUI and that should inform how to do so in TCA.

I believe you can use a Transaction that has disablesAnimation property set to true, but I haven't tried it so I'm not 100% sure of the vanilla solution :smile: