Support long swiping in carousels

This commit is contained in:
david-swift 2024-01-04 11:26:42 +01:00
parent 9cbf88727c
commit 503cf3a191
5 changed files with 38 additions and 0 deletions

View File

@ -13,6 +13,10 @@ The elements.
The content.
### `allowLongSwipes`
Whether long swipes are allowed.
### `view`
The view.
@ -24,3 +28,9 @@ Initialize `Carousel`.
- Parameters:
- elements: The elements.
- content: The view for an element.
### `longSwipes(_:)`
Set whether long swipes are allowed or not.
- Parameter longSwipes: Whether long swipes are allowed.
- Returns: The carousel.

View File

@ -9,6 +9,10 @@ A text widget.
The content.
### `lineWrapping`
Whether line wrapping is allowed.
## Methods
### `init(_:)`
@ -26,3 +30,9 @@ Update the view storage of the text widget.
Get the container of the text widget.
- Returns: The view storage.
### `wrap(_:)`
Line wrapping allows the text view to span multiple lines if the width is narrow.
- Parameter wrap: Whether to allow line wrapping.
- Returns: The text.

View File

@ -14,12 +14,15 @@ public struct Carousel<Element>: View where Element: Identifiable {
var elements: [Element]
/// The content.
var content: (Element) -> Body
/// Whether long swipes are allowed.
var allowLongSwipes = false
/// The view.
public var view: Body {
Container(elements, content: content) {
Libadwaita.Carousel()
}
.inspect { _ = ($0 as? Libadwaita.Carousel)?.longSwipes(allowLongSwipes) }
}
/// Initialize `Carousel`.
@ -34,4 +37,13 @@ public struct Carousel<Element>: View where Element: Identifiable {
self.elements = elements
}
/// Set whether long swipes are allowed or not.
/// - Parameter longSwipes: Whether long swipes are allowed.
/// - Returns: The carousel.
public func longSwipes(_ longSwipes: Bool = true) -> Self {
var newSelf = self
newSelf.allowLongSwipes = longSwipes
return newSelf
}
}

View File

@ -38,6 +38,7 @@ struct CarouselDemo: View {
.frame(minWidth: 300, minHeight: 200)
.frame(maxSize: 500)
}
.longSwipes()
}
}

View File

@ -91,6 +91,11 @@ This is an overview of the available widgets and other components in _Adwaita_.
| ---------------------------- | --------------------------------------------------------------------------------------- |
| `trailingSidebar(_:)` | Whether the sidebar is trailing to the content view. |
### `Carousel` Modifiers
| Syntax | Description |
| ---------------------------- | --------------------------------------------------------------------------------------- |
| `longSwipes(_:)` | Whether long swiping is enabled. |
### `ViewSwitcher` Modifiers
| Syntax | Description |
| ---------------------------- | --------------------------------------------------------------------------------------- |