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.62k stars 1.46k forks source link

Incorrect dismiss behavior after presenting UIAlertController UIKit #3435

Closed nmalevich closed 1 month ago

nmalevich commented 1 month ago

Description

I use AlertState, @ Presents and present method of UIViewController for showing alerts If AlertState has ButtonState with action, everything is right. But if AlertState doesn't have ButtonState or has ButtonState with only TextState(without action), after dismissing state of alert doesn't become nil So I don't have any problems with first show, but after first dismiss property in my state for alerts isn't nil, it is still previous value. So when I try to show next time, it will be nothing, because state isn't change

Checklist

Expected behavior

State of alert after dismissing is nil

Actual behavior

State of alert after dismissing isn't nil

Reproducing project

UIKitAlertDismissButtonBugExample.zip

The Composable Architecture version information

1.15.0

Destination operating system

iOS 17.6.1

Xcode version information

15.4

Swift Compiler version information

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: x86_64-apple-macosx14.0
mbrandonw commented 1 month ago

Hi @nmalevich, did you mean to file this issue again?

nmalevich commented 1 month ago

I had made a mistake in previous issues and you found it I had fixed it but I found another problem In this issues I have described another problem

mbrandonw commented 1 month ago

This is the problem:

case .view(.testIncorrect):
  state.alert = .init {
    .init("HELLO")
  }

You are showing an alert without any buttons. Our UIAlertController.init helper adds an "OK" button for you, but tapping that can't send any actions because it doesn't have that information. This can't work like it does in SwiftUI. You need to specify a button for dismissing, and you can send the .dismiss action with it.

I am going to again convert this to a discussion because this is not an issue with the library. In the future I think you can open discussions for questions like this instead of filing issues.