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 #3433

Closed nmalevich closed 1 month ago

nmalevich commented 1 month ago

Description

I use AlertState, @Presents and present method of UIViewController for showing alerts 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, you need to make sure to use the ifLet operator to integrate the alert's behavior into your feature:

Reduce { state, action in
  …
}
.ifLet(\.$alert, action: \.alert)

That should fix it.

Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there!