-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow modified views to fill their parent if a child requires it #165
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,6 +19,12 @@ public typealias ModifiedContent = TokamakCore.ModifiedContent | |||||
|
||||||
public protocol DOMViewModifier { | ||||||
var attributes: [String: String] { get } | ||||||
/// Can the modifier be flattened? | ||||||
var orderDependent: Bool { get } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
extension DOMViewModifier { | ||||||
public var orderDependent: Bool { false } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
extension ModifiedContent: DOMViewModifier | ||||||
|
@@ -42,6 +48,7 @@ extension _ZIndexModifier: DOMViewModifier { | |||||
} | ||||||
|
||||||
extension _BackgroundModifier: DOMViewModifier where Background == Color { | ||||||
public var orderDependent: Bool { true } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
public var attributes: [String: String] { | ||||||
["style": "background-color: \(background.description)"] | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,16 +15,43 @@ | |||||
import Runtime | ||||||
import TokamakCore | ||||||
|
||||||
private protocol AnyModifiedContent { | ||||||
var anyContent: AnyView { get } | ||||||
var anyModifier: DOMViewModifier { get } | ||||||
} | ||||||
|
||||||
extension ModifiedContent: AnyModifiedContent where Modifier: DOMViewModifier, Content: View { | ||||||
var anyContent: AnyView { | ||||||
AnyView(content) | ||||||
} | ||||||
|
||||||
var anyModifier: DOMViewModifier { | ||||||
modifier | ||||||
} | ||||||
} | ||||||
|
||||||
extension ModifiedContent: ViewDeferredToRenderer where Content: View { | ||||||
public var deferredBody: AnyView { | ||||||
if let domModifier = modifier as? DOMViewModifier { | ||||||
return AnyView(HTML("div", domModifier.attributes) { | ||||||
content | ||||||
}) | ||||||
if let adjacentModifier = content as? AnyModifiedContent, | ||||||
!(adjacentModifier.anyModifier.orderDependent || domModifier.orderDependent) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// Flatten non-order-dependent modifiers | ||||||
var attr = domModifier.attributes | ||||||
for (key, val) in adjacentModifier.anyModifier.attributes { | ||||||
if let prev = attr[key] { | ||||||
attr[key] = prev + val | ||||||
} | ||||||
} | ||||||
return AnyView(HTML("div", attr) { | ||||||
adjacentModifier.anyContent | ||||||
}) | ||||||
} else { | ||||||
return AnyView(HTML("div", domModifier.attributes) { | ||||||
content | ||||||
}) | ||||||
} | ||||||
} else { | ||||||
return AnyView(HTML("div") { | ||||||
content | ||||||
}) | ||||||
return AnyView(content) | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,6 +32,7 @@ extension _OverlayModifier: DOMViewModifier where Overlay == _ShapeView<_Stroked | |||||
|
||||||
// TODO: Implement arbitrary clip paths with CSS `clip-path` | ||||||
extension _ClipEffect: DOMViewModifier { | ||||||
public var orderDependent: Bool { true } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
public var attributes: [String: String] { | ||||||
if let roundedRect = shape as? RoundedRectangle { | ||||||
return ["style": "border-radius: \(roundedRect.cornerSize.width)px; overflow: hidden;"] | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit