This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e94885f
commit 4f876fa
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
**STRUCT** | ||
|
||
# `Overlay` | ||
|
||
A wrapper around a view for adding other views on top. | ||
|
||
## Properties | ||
### `child` | ||
|
||
The child view. | ||
|
||
### `overlay` | ||
|
||
The overlay view. | ||
|
||
### `overlayID` | ||
|
||
The identifier for the overlay content. | ||
|
||
## Methods | ||
### `container(modifiers:)` | ||
|
||
Get the overlay's view storage. | ||
- Parameter modifiers: The view modifiers. | ||
- Returns: The view storage. | ||
|
||
### `update(_:modifiers:)` | ||
|
||
Update the overlay's view storage. | ||
- Parameters: | ||
- storage: The view storage. | ||
- modifiers: The view modifiers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Overlay.swift | ||
// Adwaita | ||
// | ||
// Created by david-swift on 03.01.24. | ||
// | ||
|
||
import Libadwaita | ||
|
||
/// A wrapper around a view for adding other views on top. | ||
struct Overlay: Widget { | ||
|
||
/// The child view. | ||
var child: View | ||
/// The overlay view. | ||
var overlay: Body | ||
|
||
/// The identifier for the overlay content. | ||
let overlayID = "overlay" | ||
|
||
/// Get the overlay's view storage. | ||
/// - Parameter modifiers: The view modifiers. | ||
/// - Returns: The view storage. | ||
func container(modifiers: [(View) -> View]) -> ViewStorage { | ||
let contentStorage = child.storage(modifiers: modifiers) | ||
let overlayStorage = overlay.widget(modifiers: modifiers).storage(modifiers: modifiers) | ||
let overlay = Libadwaita.Overlay().child(contentStorage.view).addOverlay(overlayStorage.view) | ||
return .init(overlay, content: [.mainContent: [contentStorage], overlayID: [overlayStorage]]) | ||
} | ||
|
||
/// Update the overlay's view storage. | ||
/// - Parameters: | ||
/// - storage: The view storage. | ||
/// - modifiers: The view modifiers. | ||
func update(_ storage: ViewStorage, modifiers: [(View) -> View]) { | ||
if let storage = storage.content[.mainContent]?.first { | ||
child.updateStorage(storage, modifiers: modifiers) | ||
} | ||
if let storage = storage.content[overlayID]?.first { | ||
overlay.widget(modifiers: modifiers).update(storage, modifiers: modifiers) | ||
} | ||
} | ||
|
||
} | ||
|
||
extension View { | ||
|
||
/// Add an overlay view. | ||
/// - Parameters: | ||
/// - overlay: The overlay view. | ||
/// - Returns: A view. | ||
public func overlay(@ViewBuilder _ overlay: @escaping () -> Body) -> View { | ||
Overlay(child: self, overlay: overlay()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters