-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow namespaced child elements in decoded modifiers, finish backgrou…
…nd modifier
- Loading branch information
1 parent
399978a
commit 841402f
Showing
6 changed files
with
93 additions
and
29 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,34 @@ | ||
// | ||
// BackgroundModifier.swift | ||
// LiveViewNative | ||
// | ||
// Created by May Matyi on 3/17/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct BackgroundModifier<R: RootRegistry>: ViewModifier, Decodable { | ||
let alignment: Alignment | ||
let content: String | ||
let element: ElementNode | ||
@LiveContext<R> private var context | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
self.alignment = try container.decode(Alignment.self, forKey: .alignment) | ||
self.content = try container.decode(String.self, forKey: .content) | ||
self.element = decoder.userInfo[.elementNode!] as! ElementNode | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
content.background(alignment: alignment) { | ||
context.buildChildren(of: element, withTagName: self.content, namespace: "background") | ||
} | ||
} | ||
|
||
enum CodingKeys: CodingKey { | ||
case alignment | ||
case content | ||
} | ||
} |
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
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