1
0

BackendFeatures.swift 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /// Namespace for backend protocols.
  2. ///
  3. /// Conform to ``BaseAppBackend`` to create a backend that can be used to run
  4. /// an app. Backends are usually built on top of an existing UI framework.
  5. ///
  6. /// Default placeholder implementations are available for all backend methods,
  7. /// via the ``BackendFeatures/BaseStubs`` protocol. **These implementations will
  8. /// `fatalError` when called and are simply intended to allow incremental
  9. /// implementation of backends, not as a production-ready fallback for views
  10. /// that cannot be represented by a given backend.** See that type's
  11. /// documentation for more details.
  12. ///
  13. /// ## Backend Protocols
  14. ///
  15. /// Since a fully-functional SwiftCrossUI backend is such a complicated beast,
  16. /// we've split it up into a bunch of smaller protocols, each of which deals
  17. /// with implementing a single feature or logical set of features.
  18. ///
  19. /// At a high level, there are three protocols (technically typealiases of
  20. /// protocol compositions) you need to worry about.
  21. ///
  22. /// - term ``Core``: This protocol describes the absolute bare minimum amount
  23. /// of code required for an app to launch, show something on the screen, and
  24. /// perform basic widget manipulation.
  25. /// - term ``BaseAppBackend``: This protocol describes all the code required for
  26. /// a minimally functional backend, including everything in `Core` as well as
  27. /// many UI controls and containers, text and images. Conforming to this
  28. /// protocol is required for your backend type to be usable in SwiftCrossUI
  29. /// APIs.
  30. ///
  31. /// You will probably want to implement some other backend protocols in
  32. /// addition to `BaseAppBackend`, since this is pretty bare-bones on its own.
  33. /// - term ``FullAppBackend``: This protocol describes all the code needed for a
  34. /// fully functional backend that supports everything SwiftCrossUI has to
  35. /// offer, including URL and file handling, alerts, and sheets. It includes
  36. /// everything in `BaseAppBackend`.
  37. ///
  38. /// See the documentation for each protocol for more details on what they
  39. /// require.
  40. ///
  41. /// ## Design Notes
  42. ///
  43. /// If you need to modify the children of a widget after creation but there
  44. /// aren't update methods available, this is an intentional limitation to
  45. /// reduce the complexity of maintaining a multitude of backends -- nest
  46. /// another container, such as a VStack, inside the container to allow you
  47. /// to change its children on demand.
  48. ///
  49. /// For interactive controls with values, the method for setting the
  50. /// control's value is always separate from the method for updating the
  51. /// control's properties (e.g. its minimum value, or placeholder label etc).
  52. /// This is because it's very common for view implementations to either
  53. /// update a control's properties without updating its value (in the case
  54. /// of an unbound control), or update a control's value only if it doesn't
  55. /// match its current value (to prevent infinite loops).
  56. ///
  57. /// Many views have both a `create` and an `update` method. The `create`
  58. /// method should only have parameters for properties which don't have
  59. /// sensible defaults (e.g. under some backends, image widgets can't be
  60. /// created without an underlying image being selected up-front, so the
  61. /// `create` method requires a `filePath` and will overlap with the `update`
  62. /// method). This design choice was made to reduce the amount of repeated
  63. /// code between the `create` and `update` methods of the various widgets
  64. /// (since the `update` method is always called between calling `create`
  65. /// and actually displaying the widget anyway).
  66. ///
  67. /// ## Topics
  68. ///
  69. /// ### Top-Level
  70. /// - ``BackendFeatures/Core``
  71. /// - ``BaseAppBackend``
  72. /// - ``FullAppBackend``
  73. ///
  74. /// ### Implementation Helpers
  75. /// - ``BackendFeatures/BaseStubs``
  76. public enum BackendFeatures {}