ScrollContainers.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. extension BackendFeatures {
  2. /// Backend methods for scroll containers.
  3. ///
  4. /// These are used by ``ScrollView`` and other views that require scrolling.
  5. @MainActor
  6. public protocol ScrollContainers: Core {
  7. /// Gets the layout width of a backend's scroll bars.
  8. ///
  9. /// Assumes that the width is the same for both vertical and horizontal
  10. /// scroll bars (where the width of a horizontal scroll bar is what pedants
  11. /// may call its height). If the backend uses overlay scroll bars then this
  12. /// width should be 0.
  13. ///
  14. /// This value may make sense to have as a computed property for some backends
  15. /// such as `AppKitBackend` where plugging in a mouse can cause the default
  16. /// scroll bar style to change. If something does cause this value to change,
  17. /// ensure that the configured root environment change handler gets called so
  18. /// that SwiftCrossUI can update the app's layout accordingly.
  19. var scrollBarWidth: Int { get }
  20. /// Creates a scrollable single-child container wrapping the given widget.
  21. ///
  22. /// - Parameter child: The widget to wrap in a scroll container.
  23. /// - Returns: A scroll container wrapping `child`.
  24. func createScrollContainer(for child: Widget) -> Widget
  25. /// Updates a scroll container with environment-specific values.
  26. ///
  27. /// This method is primarily used on iOS to apply environment changes
  28. /// that affect the scroll view’s behavior, such as keyboard dismissal mode.
  29. ///
  30. /// - Parameters:
  31. /// - scrollView: The scroll container widget previously created by
  32. /// ``createScrollContainer(for:)``.
  33. /// - environment: The current ``EnvironmentValues`` to apply.
  34. /// - bounceHorizontally: Whether the scroll view should 'bounce' horizontally.
  35. /// Some backends ignore this, as it's not a universal concept.
  36. /// - bounceVertically: Whether the scroll view should 'bounce' vertically.
  37. /// Some backends ignore this, as it's not a universal concept.
  38. /// - hasHorizontalScrollBar: Whether the scroll view has a horizontal
  39. /// scroll bar.
  40. /// - hasVerticalScrollBar: Whether the scroll view has a vertical scroll
  41. /// bar.
  42. func updateScrollContainer(
  43. _ scrollView: Widget,
  44. environment: EnvironmentValues,
  45. bounceHorizontally: Bool,
  46. bounceVertically: Bool,
  47. hasHorizontalScrollBar: Bool,
  48. hasVerticalScrollBar: Bool
  49. )
  50. }
  51. }