Skip to content

Conversation

@stephencelis
Copy link
Member

Assuming the new APIs are locked-in, this updates our existing APIs to consume the new ones and not the deprecated old ones. In the process I introduced the ability to do 3+ buttons on alerts.

Some food for thought:

  • Should ActionSheetState be renamed to ConfirmationDialogState? Pretty wordy...
  • Or should it all be AlertState and we could introduce something like:
    enum AlertStateMode {
      case alert
      case confirmationDialog(titleVisibility: Visibility)
    }

case cancel(label: TextState?)
case `default`(label: TextState)
case destructive(label: TextState)
public enum ButtonRole {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking...but the rename seemed worth it to unify with Apple's APIs...

Comment on lines 9 to 11
withTransaction(self.transaction) {
self.wrappedValue = nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withTransaction might not be needed here because self.transaction should already be applied to self.wrappedValue. It might even override other withTransaction/withAnimation calls higher up.
In the event you wanted to add support for .transaction()/.animation() to this binding, I've found the best way to maintain the animation precedence would be

extension Binding {
  func isPresent<Wrapped>() -> Binding<Bool> where Value == Wrapped? {
    .init(
      get: { self.wrappedValue != nil },
      set: { isPresent, transaction in
        guard !isPresent else { return }
        self.transaction(transaction).wrappedValue = nil
      }
    )
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! Good to know, thanks @iampatbrown!

@stephencelis stephencelis merged commit 0cd0c3e into main Sep 20, 2021
@stephencelis stephencelis deleted the alert-apis branch September 20, 2021 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants