Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Support long swiping in carousels
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 4, 2024
1 parent 9cbf887 commit 503cf3a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Documentation/Reference/structs/Carousel.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ The elements.

The content.

### `allowLongSwipes`

Whether long swipes are allowed.

### `view`

The view.
Expand All @@ -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.
10 changes: 10 additions & 0 deletions Documentation/Reference/structs/Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ A text widget.

The content.

### `lineWrapping`

Whether line wrapping is allowed.

## Methods
### `init(_:)`

Expand All @@ -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.
12 changes: 12 additions & 0 deletions Sources/Adwaita/View/Carousel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
}

}
1 change: 1 addition & 0 deletions Tests/CarouselDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct CarouselDemo: View {
.frame(minWidth: 300, minHeight: 200)
.frame(maxSize: 500)
}
.longSwipes()
}

}
Expand Down
5 changes: 5 additions & 0 deletions user-manual/Information/Widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| ---------------------------- | --------------------------------------------------------------------------------------- |
Expand Down

0 comments on commit 503cf3a

Please sign in to comment.