SecureFields.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. extension BackendFeatures {
  2. /// Backend methods for secure text fields.
  3. ///
  4. /// These are used by ``SecureField``.
  5. @MainActor
  6. public protocol SecureFields: Core {
  7. /// Creates an editable secure text field with a placeholder label and
  8. /// change handler.
  9. ///
  10. /// Predominantly used by ``SecureField``.
  11. ///
  12. /// - Returns: A secure text field.
  13. func createSecureField() -> Widget
  14. /// Sets the placeholder label and change handler of an editable secure
  15. /// text field.
  16. ///
  17. /// - Parameters:
  18. /// - secureField: The secure text field to update.
  19. /// - placeholder: The secure text field's placeholder label.
  20. /// - environment: The current environment.
  21. /// - onChange: The action to perform when the secure text field's content
  22. /// changes. This replaces any existing change handlers, and is called
  23. /// whenever the displayed value changes.
  24. /// - onSubmit: The action to perform when the user hits Enter/Return,
  25. /// or whatever the backend decides counts as submission of the field.
  26. func updateSecureField(
  27. _ secureField: Widget,
  28. placeholder: String,
  29. environment: EnvironmentValues,
  30. onChange: @escaping (String) -> Void,
  31. onSubmit: @escaping () -> Void
  32. )
  33. /// Sets the value of an editable secure text field.
  34. ///
  35. /// - Parameters:
  36. /// - secureField: The secure text field to set the content of.
  37. /// - content: The new content.
  38. func setContent(ofSecureField secureField: Widget, to content: String)
  39. /// Gets the value of an editable secure text field.
  40. ///
  41. /// - Parameter secureField: The secure text field to get the content of.
  42. /// - Returns: `secureField`'s content.
  43. func getContent(ofSecureField secureField: Widget) -> String
  44. }
  45. }