-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add public
_ModifierStack
type (#998)
* Make BuiltinRegistry and ModifierContainer public * Revert "Make BuiltinRegistry and ModifierContainer public" This reverts commit 4b68667. * Add public `_ModifierStack` type * Convert to ViewModifier
- Loading branch information
1 parent
962a487
commit 307d322
Showing
2 changed files
with
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// ModifierStack.swift | ||
// | ||
// | ||
// Created by Carson Katri on 6/29/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// A container that decodes a modifier stack. | ||
/// | ||
/// Use this as a modifier: | ||
/// | ||
/// ```swift | ||
/// content | ||
/// .modifier(modifierStack) | ||
/// ``` | ||
public struct _ModifierStack<R: RootRegistry>: Decodable, ViewModifier { | ||
private let stack: [ModifierContainer<R>] | ||
|
||
@ObservedElement private var element | ||
@LiveContext<R> private var context | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
self.stack = try container.decode([ModifierContainer<R>].self) | ||
} | ||
|
||
public func body(content: Content) -> some View { | ||
content | ||
.applyModifiers(stack[...], element: element, context: context.storage) | ||
} | ||
} |
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,7 @@ | ||
defmodule LiveViewNativeSwiftUi.Types.ModifierStack do | ||
use LiveViewNativePlatform.Modifier.Type | ||
def type, do: :map | ||
|
||
def cast(%LiveViewNativeSwiftUi.Modifiers{} = value), do: {:ok, Jason.decode!(Jason.encode!(value))} | ||
def cast(_), do: :error | ||
end |