Skip to content

[UIAlertController] Add preferred button support#342

Open
juliensagot wants to merge 1 commit into
pointfreeco:mainfrom
juliensagot:preferred-button-support
Open

[UIAlertController] Add preferred button support#342
juliensagot wants to merge 1 commit into
pointfreeco:mainfrom
juliensagot:preferred-button-support

Conversation

@juliensagot

@juliensagot juliensagot commented May 25, 2026

Copy link
Copy Markdown
Contributor

UIKit exposes preferredAction as the way to mark the action a person is most likely to take from an alert.
Per Apple's documentation, UIKit gives that action additional emphasis and lets the Return key trigger it when a physical keyboard is connected.

  • Adds ButtonState.isPreferred and .preferred(_:).
  • Preserves preferredness through ButtonState.map, equality, hashing, and custom dump output.
  • Updates UIKit UIAlertController bridging for both AlertState and ConfirmationDialogState to set preferredAction.
  • Reports an issue when multiple buttons are marked preferred, while deterministically using the first one.
  • Adds focused value-level and UIKit tests.

Example

state.applyChangesToRoutineDialog = ConfirmationDialogState(
  titleVisibility: .visible,
  title: {
    TextState("Update Routine?", bundle: .module)
  },
  actions: {
    ButtonState(action: .onlyReplaceTrainingExercise) {
      TextState("Training Only", bundle: .module)
    }
    .preferred() // 🟢🟢🟢 This is the new API! 🟢🟢🟢

    ButtonState(action: .replaceBoth) {
      TextState("Update Both", bundle: .module)
    }
  },
  message: {
    TextState(
      "Should the linked routine also be updated with these exercise changes?",
      bundle: .module
    )
  }
)

@juliensagot juliensagot force-pushed the preferred-button-support branch from 0ce4849 to f0d4132 Compare June 20, 2026 13:22
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.

1 participant