Skip to content

Commit

Permalink
Fix ephemeral dismissal (#3286)
Browse files Browse the repository at this point in the history
* Fix ephemeral dismissal

This regression was introduced to fix a UIKit warning, but it causes
state to not be `nil`'d out in SwiftUI. Luckily we caught it before a
release.

* wip
  • Loading branch information
stephencelis authored Aug 15, 2024
1 parent 27adbdc commit 2c17a93
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@
}
set {
if newValue == nil,
let childState = self.state[keyPath: state],
!isEphemeral(childState),
self.state[keyPath: state] != nil,
!self._isInvalidated()
{
self.send(action(.dismiss))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2653,6 +2653,37 @@ final class PresentationReducerTests: BaseTCATestCase {
$0.child?.child = nil
}
}

@Reducer
struct TestEphemeralBindingDismissalFeature {
@ObservableState
struct State: Equatable {
@Presents var alert: AlertState<Never>?
}
enum Action: Equatable {
case alert(PresentationAction<Never>)
}
var body: some ReducerOf<Self> {
Reduce { state, action in
return .none
}
.ifLet(\.$alert, action: /Action.alert)
}
}
@MainActor
func testEphemeralBindingDismissal() async {
@Perception.Bindable var store = Store(
initialState: TestEphemeralBindingDismissalFeature.State(
alert: AlertState { TextState("Oops!") }
)
) {
TestEphemeralBindingDismissalFeature()
}

XCTAssertNotNil(store.alert)
$store.scope(state: \.alert, action: \.alert).wrappedValue = nil
XCTAssertNil(store.alert)
}
}

@Reducer
Expand Down
33 changes: 0 additions & 33 deletions Tests/ComposableArchitectureTests/RuntimeWarningTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,38 +324,5 @@
"""
}
}

@Reducer
struct TestStoreDestination_NotIntegrated_EphemeralState {
@Reducer
struct Destination {}
@ObservableState
struct State: Equatable {
@Presents var alert: AlertState<Never>?
}
enum Action {
case alert(PresentationAction<Never>)
}
}
@MainActor
func testStoreDestination_NotIntegrated_EphemeralState() {
let store = Store(
initialState: TestStoreDestination_NotIntegrated_EphemeralState.State(
alert: .init(title: { TextState("Hi") })
)
) {
TestStoreDestination_NotIntegrated_EphemeralState()
}

store[
state: \.alert,
action: \.alert,
isInViewBody: false,
fileID: "file.swift",
filePath: "/file.swift",
line: 1,
column: 1
] = nil // NB: Not issue reported
}
}
#endif

0 comments on commit 2c17a93

Please sign in to comment.