You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have features that use alerts and confirmationDialogs for changes to items in a SwiftUI List. In the past this worked fine because I would attach the dialog modifier to the root of the feature and it would display as a sheet so it didn't matter where in the hierarchy I put it.
List{ForEach(store.items){ item inItemView(item).onTap{send(.itemButtonTapped)} // Populates destination with dialog state
}}.confirmationDialog(
$store.scope(state: \.destination?.dialog, action: \.destination.dialog))
In iOS 26, though, you need to attach the alert modifier to the row view itself so the popover arrow will point at the view that generated it. This presents a problem because the row elements are inside a ForEach so when you populate the Destination enum it applies to all the rows. The popover attachment point is now indeterminate.
I first solved this with a small piece of state that identifies which row the dialog should apply to:
This works and is a fine fallback, but I then have to repeat this pattern over several features. I'd prefer to just have the dialog state itself keep track of which row it applies to. So I wrote a wrapper that adds an identifier to the dialog state:
The conformance compiles, but I still get the error when adding it to my Destination enum.
The new design is going to make this pattern more common so I'd like to have a generic approach to solving it. Is there a way to squeeze my little wrapper into a Destination enum and have it work like the standard dialog state?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have features that use
alert
s andconfirmationDialog
s for changes to items in a SwiftUIList
. In the past this worked fine because I would attach the dialog modifier to the root of the feature and it would display as a sheet so it didn't matter where in the hierarchy I put it.In iOS 26, though, you need to attach the alert modifier to the row view itself so the popover arrow will point at the view that generated it. This presents a problem because the row elements are inside a
ForEach
so when you populate theDestination
enum it applies to all the rows. The popover attachment point is now indeterminate.I first solved this with a small piece of state that identifies which row the dialog should apply to:
Then I write a little wrapper to differentiate which row gets the dialog:
Now I can use it in my list of items:
This works and is a fine fallback, but I then have to repeat this pattern over several features. I'd prefer to just have the dialog state itself keep track of which row it applies to. So I wrote a wrapper that adds an identifier to the dialog state:
Now I add a wrapper around the dialog modifier from swift-navigation:
This compiles, but when I try to use it in my feature we have issues:
In the expansion of the
@Reducer
macro I get:Looking at the macro code it looks like the dialog state values are special cased using the
_EphemeralState
protocol so I added conformance:The conformance compiles, but I still get the error when adding it to my
Destination
enum.The new design is going to make this pattern more common so I'd like to have a generic approach to solving it. Is there a way to squeeze my little wrapper into a
Destination
enum and have it work like the standard dialog state?Beta Was this translation helpful? Give feedback.
All reactions