1
0

PresentationModifiers.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. extension View {
  2. /// Sets the detents (heights) for the enclosing sheet presentation to snap
  3. /// to when the user resizes it interactively.
  4. ///
  5. /// Detents are only respected on platforms that support sheet resizing,
  6. /// and sheet resizing is generally only supported on mobile.
  7. ///
  8. /// If no detents are specified, then a single default detent is used. The
  9. /// default is platform-specific. On iOS the default is
  10. /// ``PresentationDetent/large``.
  11. ///
  12. /// - Supported platforms: iOS & Mac Catalyst 15+ (ignored on unsupported
  13. /// platforms)
  14. /// - ``PresentationDetent/fraction(_:)`` and
  15. /// ``PresentationDetent/height(_:)`` fall back to
  16. /// ``PresentationDetent/medium`` on iOS 15 and earlier
  17. ///
  18. /// - Parameter detents: A set of detents that the sheet can be resized to.
  19. /// - Returns: A view with the ``PreferenceValues/presentationDetents``
  20. /// preference set.
  21. public func presentationDetents(_ detents: Set<PresentationDetent>) -> some View {
  22. preference(key: \.presentationDetents, value: Array(detents))
  23. }
  24. /// Sets the corner radius for the enclosing sheet presentation.
  25. ///
  26. /// - Supported platforms: iOS & Mac Catalyst 15+, Gtk4 (ignored on
  27. /// unsupported platforms)
  28. ///
  29. /// - Parameter radius: The corner radius in points.
  30. /// - Returns: A view with the ``PreferenceValues/presentationCornerRadius``
  31. /// preference set.
  32. public func presentationCornerRadius(_ radius: Double) -> some View {
  33. preference(key: \.presentationCornerRadius, value: radius)
  34. }
  35. /// Sets the visibility of the enclosing sheet presentation's drag
  36. /// indicator.
  37. ///
  38. /// Drag indicators are only supported on platforms that support sheet
  39. /// resizing, and sheet resizing is generally only supported on mobile.
  40. ///
  41. /// - Supported platforms: iOS & Mac Catalyst 15+ (ignored on unsupported
  42. /// platforms)
  43. ///
  44. /// - Parameter visibility: The visibility to use for the drag indicator of
  45. /// the enclosing sheet.
  46. /// - Returns: A view with the
  47. /// ``PreferenceValues/presentationDragIndicatorVisibility`` preference
  48. /// set.
  49. public func presentationDragIndicatorVisibility(
  50. _ visibility: Visibility
  51. ) -> some View {
  52. preference(key: \.presentationDragIndicatorVisibility, value: visibility)
  53. }
  54. /// Sets the background of the enclosing sheet presentation.
  55. ///
  56. /// - Parameter color: The background color to use for the enclosing sheet
  57. /// presentation.
  58. /// - Returns: A view with the ``PreferenceValues/presentationBackground``
  59. /// preference set.
  60. public func presentationBackground(_ color: Color) -> some View {
  61. preference(key: \.presentationBackground, value: color)
  62. }
  63. /// Prevents the user from dismissing the enclosing sheet presentation.
  64. ///
  65. /// When interactive dismissal is disabled, users can only dismiss sheets by
  66. /// performing actions that your code handles and turns into programmatic
  67. /// dismissals.
  68. ///
  69. /// - Parameter isDisabled: Whether interactive dismissal is disabled.
  70. /// - Returns: A view with the
  71. /// ``PreferenceValues/interactiveDismissDisabled`` preference set.
  72. public func interactiveDismissDisabled(_ isDisabled: Bool = true) -> some View {
  73. preference(key: \.interactiveDismissDisabled, value: isDisabled)
  74. }
  75. /// Sets the preferred color scheme for the nearest enclosing presentation,
  76. /// such as a sheet or window.
  77. ///
  78. /// > Note: Not supported by GtkBackend or Gtk3Backend. When targeting those
  79. /// > platforms this modifier has no effect.
  80. ///
  81. /// - Parameter colorScheme: The preferred color scheme for the nearest
  82. /// enclosing presentation.
  83. /// - Returns: A view with the ``PreferenceValues/preferredColorScheme``
  84. /// preference set.
  85. public func preferredColorScheme(_ colorScheme: ColorScheme?) -> some View {
  86. preference(key: \.preferredColorScheme, value: colorScheme)
  87. }
  88. }