Fix linter and layout issues

This commit is contained in:
Carson Katri 2020-08-04 14:25:07 -04:00
parent c0a580653a
commit fff9909a5a
6 changed files with 34 additions and 18 deletions

View File

@ -93,6 +93,8 @@ public struct _NavigationLinkProxy<Label, Destination> where Label: View, Destin
} }
public func activate() { public func activate() {
subject.navigationContext.destination = subject.destination if !isSelected {
subject.navigationContext.destination = subject.destination
}
} }
} }

View File

@ -39,13 +39,14 @@ public struct _NavigationViewProxy<Content: View>: View {
public init(_ subject: NavigationView<Content>) { self.subject = subject } public init(_ subject: NavigationView<Content>) { self.subject = subject }
public var content: Content { subject.content } public var content: some View {
subject.content
.environmentObject(subject.context)
}
public var body: some View { public var body: some View {
HStack { subject.context.destination.view
content .environmentObject(subject.context)
subject.context.destination.view
}
.environmentObject(subject.context)
} }
} }

View File

@ -35,7 +35,7 @@ struct NavItem: Identifiable {
init<V>(_ id: String, destination: V) where V: View { init<V>(_ id: String, destination: V) where V: View {
self.id = id self.id = id
self.destination = title(destination.frame(minWidth: 300), title: id) self.destination = title(destination, title: id)
} }
init(unavailable id: String) { init(unavailable id: String) {
@ -141,11 +141,7 @@ struct TokamakDemoView: View {
let list = title( let list = title(
List(links) { link in List(links) { link in
if let dest = link.destination { if let dest = link.destination {
NavigationLink(link.id, destination: HStack { NavigationLink(link.id, destination: dest)
Spacer()
dest
Spacer()
})
} else { } else {
#if os(WASI) #if os(WASI)
Text(link.id) Text(link.id)

View File

@ -37,9 +37,13 @@ extension _ShapeView: ViewDeferredToRenderer {
if let shapeAttributes = shape as? ShapeAttributes { if let shapeAttributes = shape as? ShapeAttributes {
return AnyView(HTML("div", shapeAttributes.attributes(style)) { path }) return AnyView(HTML("div", shapeAttributes.attributes(style)) { path })
} else if let color = style as? Color { } else if let color = style as? Color {
return AnyView(HTML("div", ["style": "fill: \(color.cssValue(environment));"]) { path }) return AnyView(HTML("div", [
"style": "fill: \(color.cssValue(environment));",
]) { path })
} else if let foregroundColor = foregroundColor { } else if let foregroundColor = foregroundColor {
return AnyView(HTML("div", ["style": "fill: \(foregroundColor.cssValue(environment));"]) { path }) return AnyView(HTML("div", [
"style": "fill: \(foregroundColor.cssValue(environment));",
]) { path })
} else { } else {
return path return path
} }

View File

@ -22,7 +22,17 @@ extension NavigationView: ViewDeferredToRenderer {
width: 100%; height: 100%; width: 100%; height: 100%;
""", """,
]) { ]) {
_NavigationViewProxy(self) _NavigationViewProxy(self).content
HTML("div", [
"style": """
display: flex; flex-direction: column;
align-items: center; justify-content: center;
flex-grow: 1;
height: 100%;
""",
]) {
_NavigationViewProxy(self)
}
}) })
} }
} }

View File

@ -157,11 +157,15 @@ extension Text {
underline = (active, color) underline = (active, color)
} }
} }
let hasStrikethrough = strikethrough?.0 ?? false let hasStrikethrough = strikethrough?.0 ?? false
let hasUnderline = underline?.0 ?? false let hasUnderline = underline?.0 ?? false
let textDecoration = !hasStrikethrough && !hasUnderline ? let textDecoration = !hasStrikethrough && !hasUnderline ?
"none" : "none" :
"\(hasStrikethrough ? "line-through" : "") \(hasUnderline ? "underline" : "")" "\(hasStrikethrough ? "line-through" : "") \(hasUnderline ? "underline" : "")"
let decorationColor = strikethrough?.1?.cssValue(environment)
?? underline?.1?.cssValue(environment)
?? "inherit"
return [ return [
"style": """ "style": """
@ -179,8 +183,7 @@ extension Text {
letter-spacing: \(kerning); letter-spacing: \(kerning);
vertical-align: \(baseline == nil ? "baseline" : "\(baseline!)em"); vertical-align: \(baseline == nil ? "baseline" : "\(baseline!)em");
text-decoration: \(textDecoration); text-decoration: \(textDecoration);
text-decoration-color: \(strikethrough?.1?.cssValue(environment) ?? underline?.1?.cssValue(environment) text-decoration-color: \(decorationColor)
?? "inherit")
""", """,
"class": isRedacted ? "_tokamak-text-redacted" : "", "class": isRedacted ? "_tokamak-text-redacted" : "",
] ]