Skip to content

Commit

Permalink
Merge pull request #174 from kiwicom/169-refactor-custom-content-eval…
Browse files Browse the repository at this point in the history
…uation

Refactor custom content evaluation
  • Loading branch information
PavelHolec authored Jun 14, 2022
2 parents df3242e + 8294203 commit 18bdc18
Show file tree
Hide file tree
Showing 21 changed files with 159 additions and 155 deletions.
12 changes: 6 additions & 6 deletions Sources/Orbit/Components/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct Alert<Content: View>: View {
let status: Status
let isSuppressed: Bool
let descriptionLinkAction: TextLink.Action
let content: () -> Content
@ViewBuilder let content: Content

public var body: some View {
HStack(alignment: .firstTextBaseline, spacing: .xSmall) {
Expand All @@ -61,7 +61,7 @@ public struct Alert<Content: View>: View {
}
}

content()
content

switch buttons {
case .primary, .secondary, .primaryAndSecondary:
Expand Down Expand Up @@ -171,7 +171,7 @@ public extension Alert {
status: Status = .info,
isSuppressed: Bool = false,
descriptionLinkAction: @escaping TextLink.Action = { _, _ in },
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) {
self.title = title
self.description = description
Expand All @@ -180,7 +180,7 @@ public extension Alert {
self.status = status
self.isSuppressed = isSuppressed
self.descriptionLinkAction = descriptionLinkAction
self.content = content
self.content = content()
}

/// Creates Orbit Alert component.
Expand Down Expand Up @@ -323,7 +323,7 @@ struct AlertPreviews: PreviewProvider {
}

static var storybook: some View {
LazyVStackIfAvailable(alignment: .leading, spacing: .large) {
LazyVStack(alignment: .leading, spacing: .large) {
basic
basicNoIcon
suppressed
Expand All @@ -332,7 +332,7 @@ struct AlertPreviews: PreviewProvider {
}

static var storybookMix: some View {
LazyVStackIfAvailable(alignment: .leading, spacing: .large) {
LazyVStack(alignment: .leading, spacing: .large) {
primaryButtonOnly
noButtons
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Orbit/Components/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public struct Card<Content: View>: View {
let status: Status?
let width: ContainerWidth
let backgroundColor: Color?
let content: () -> Content
@ViewBuilder let content: Content

public var body: some View {
VStack(alignment: .leading, spacing: headerSpacing) {
header

if isContentEmpty == false {
VStack(alignment: contentAlignment, spacing: contentSpacing) {
content()
content
}
.padding(.top, isHeaderEmpty ? contentPadding : 0)
.padding([.horizontal, .bottom], contentPadding)
Expand Down Expand Up @@ -140,7 +140,7 @@ public struct Card<Content: View>: View {
}

var isContentEmpty: Bool {
content() is EmptyView
content is EmptyView
}

var shadow: TileBorderModifier.Shadow {
Expand Down Expand Up @@ -181,7 +181,7 @@ public extension Card {
backgroundColor: Color? = .whiteNormal,
contentLayout: CardContentLayout = .default(),
contentAlignment: HorizontalAlignment = .leading,
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) {
self.title = title
self.description = description
Expand All @@ -195,7 +195,7 @@ public extension Card {
self.backgroundColor = backgroundColor
self.contentLayout = contentLayout
self.contentAlignment = contentAlignment
self.content = { content() }
self.content = content()
}

/// Creates Orbit Card wrapper component with empty content.
Expand Down
8 changes: 4 additions & 4 deletions Sources/Orbit/Components/ChoiceTile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct ChoiceTile<Content: View>: View {
let message: MessageType
let alignment: ChoiceTileAlignment
let action: () -> Void
let content: () -> Content
@ViewBuilder let content: Content

public var body: some View {
SwiftUI.Button(
Expand All @@ -58,7 +58,7 @@ public struct ChoiceTile<Content: View>: View {

VStack(alignment: .leading, spacing: padding) {
header
content()
content
messageView
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public extension ChoiceTile {
message: MessageType = .none,
alignment: ChoiceTileAlignment = .default,
action: @escaping () -> Void = {},
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) {
self.title = title
self.description = description
Expand All @@ -230,7 +230,7 @@ public extension ChoiceTile {
self.message = message
self.alignment = alignment
self.action = action
self.content = content
self.content = content()
}

/// Creates Orbit ChoiceTile component.
Expand Down
10 changes: 5 additions & 5 deletions Sources/Orbit/Components/HorizontalScroll.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public struct HorizontalScroll<Content: View>: View {
let minHeight: CGFloat?
let horizontalPadding: CGFloat
let verticalPadding: CGFloat
let content: () -> Content
@ViewBuilder let content: Content

public var body: some View {
SingleAxisGeometryReader(axis: .horizontal, alignment: .top) { width in
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: spacing) {
content()
content
.frame(width: itemWidth(forContentWidth: width), alignment: .leading)
.frame(maxWidth: maxItemWidth, alignment: .leading)
.frame(height: resolvedItemHeight, alignment: .top)
Expand Down Expand Up @@ -78,7 +78,7 @@ public struct HorizontalScroll<Content: View>: View {
minHeight: CGFloat? = nil,
horizontalPadding: CGFloat = .xSmall,
verticalPadding: CGFloat = .xSmall,
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) {
self.spacing = spacing
self.itemWidth = itemWidth
Expand All @@ -87,7 +87,7 @@ public struct HorizontalScroll<Content: View>: View {
self.minHeight = minHeight
self.horizontalPadding = horizontalPadding
self.verticalPadding = verticalPadding
self.content = content
self.content = content()
}

func itemWidth(forContentWidth contentWidth: CGFloat) -> CGFloat? {
Expand Down Expand Up @@ -320,7 +320,7 @@ struct HorizontalScrollPreviews: PreviewProvider {
}
}

static func intrinsicContent<Content>(@ViewBuilder content: @escaping () -> Content) -> some View where Content: View {
static func intrinsicContent<Content>(@ViewBuilder content: () -> Content) -> some View where Content: View {
VStack(alignment: .leading) {
Text("Intrinsic")
content()
Expand Down
2 changes: 2 additions & 0 deletions Sources/Orbit/Components/InputField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public struct InputField<Value>: View where Value: LosslessStringConvertible {
.accentColor(.blueNormal)
.background(textFieldPlaceholder, alignment: .leading)
.disabled(state == .disabled)
.accessibility(.inputValue)

button
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Orbit/Components/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import SwiftUI
public struct List<Content: View>: View {

let spacing: CGFloat
let content: () -> Content
@ViewBuilder let content: Content

public var body: some View {
VStack(alignment: .listTextLeading, spacing: spacing) {
content()
content
}
}

/// Creates Orbit List component, wrapping ListItem content.
public init(spacing: CGFloat = .xSmall, @ViewBuilder content: @escaping () -> Content) {
public init(spacing: CGFloat = .xSmall, @ViewBuilder content: () -> Content) {
self.spacing = spacing
self.content = content
self.content = content()
}
}

Expand Down
30 changes: 15 additions & 15 deletions Sources/Orbit/Components/ListChoice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public struct ListChoice<HeaderContent: View, Content: View>: View {
let value: String
let disclosure: ListChoiceDisclosure
let showSeparator: Bool
let content: Content
let action: () -> Void
let content: () -> Content
let headerContent: () -> HeaderContent
@ViewBuilder let headerContent: HeaderContent

public var body: some View {
if isEmpty == false {
Expand All @@ -65,7 +65,7 @@ public struct ListChoice<HeaderContent: View, Content: View>: View {
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: 0) {
header
content()
content
}

disclosureView
Expand All @@ -89,7 +89,7 @@ public struct ListChoice<HeaderContent: View, Content: View>: View {
TextStrut(.large)
.padding(.vertical, verticalPadding)

headerContent()
headerContent
.padding(.leading, isHeaderEmpty ? .medium : 0)
.padding(.trailing, disclosure == .none ? .medium : 0)
.accessibility(.listChoiceValue)
Expand Down Expand Up @@ -173,11 +173,11 @@ public struct ListChoice<HeaderContent: View, Content: View>: View {
}

var isCustomHeaderEmpty: Bool {
headerContent() is EmptyView
headerContent is EmptyView
}

var isCustomContentEmpty: Bool {
content() is EmptyView
content is EmptyView
}

var isHeaderTextEmpty: Bool {
Expand All @@ -201,8 +201,8 @@ public struct ListChoice<HeaderContent: View, Content: View>: View {
disclosure: ListChoiceDisclosure = .disclosure(),
showSeparator: Bool = true,
action: @escaping () -> Void = {},
@ViewBuilder content: @escaping () -> Content,
@ViewBuilder headerContent: @escaping () -> HeaderContent
@ViewBuilder content: () -> Content,
@ViewBuilder headerContent: () -> HeaderContent
) {
self.title = title
self.description = description
Expand All @@ -211,8 +211,8 @@ public struct ListChoice<HeaderContent: View, Content: View>: View {
self.disclosure = disclosure
self.showSeparator = showSeparator
self.action = action
self.content = content
self.headerContent = headerContent
self.content = content()
self.headerContent = headerContent()
}
}

Expand All @@ -227,8 +227,8 @@ public extension ListChoice {
disclosure: ListChoiceDisclosure = .disclosure(),
showSeparator: Bool = true,
action: @escaping () -> Void = {},
@ViewBuilder content: @escaping () -> Content,
@ViewBuilder headerContent: @escaping () -> HeaderContent
@ViewBuilder content: () -> Content,
@ViewBuilder headerContent: () -> HeaderContent
) {
self.init(
title,
Expand All @@ -251,7 +251,7 @@ public extension ListChoice {
disclosure: ListChoiceDisclosure = .disclosure(),
showSeparator: Bool = true,
action: @escaping () -> Void = {},
@ViewBuilder headerContent: @escaping () -> HeaderContent
@ViewBuilder headerContent: () -> HeaderContent
) where Content == EmptyView {
self.init(
title,
Expand All @@ -273,7 +273,7 @@ public extension ListChoice {
disclosure: ListChoiceDisclosure = .disclosure(),
showSeparator: Bool = true,
action: @escaping () -> Void = {},
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) where HeaderContent == EmptyView {
self.init(
title,
Expand Down Expand Up @@ -320,7 +320,7 @@ public extension ListChoice where HeaderContent == Text {
disclosure: ListChoiceDisclosure = .disclosure(),
showSeparator: Bool = true,
action: @escaping () -> Void = {},
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) {
self.init(
title,
Expand Down
1 change: 1 addition & 0 deletions Sources/Orbit/Components/Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public struct Select: View {
label: {
Text(value ?? placeholder, color: .none)
.foregroundColor(textColor)
.accessibility(.inputValue)
}
)
.buttonStyle(
Expand Down
10 changes: 5 additions & 5 deletions Sources/Orbit/Components/Tabs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public struct Tabs<Content: View>: View {
let underlineHeight: CGFloat = .xxxSmall
let lineLimit: Int?
let distribution: TabsDistribution
let content: () -> Content
@ViewBuilder let content: Content

public var body: some View {
HStack(alignment: .center, spacing: 0) {
content()
HStack(spacing: 0) {
content
.lineLimit(lineLimit)
.frame(maxWidth: maxTabWidth, minHeight: Layout.preferredSmallButtonHeight, maxHeight: .infinity)
}
Expand Down Expand Up @@ -154,12 +154,12 @@ extension Tabs {
selectedIndex: Binding<Int>,
distribution: TabsDistribution = .equal,
lineLimit: Int? = nil,
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) {
self._selectedIndex = selectedIndex
self.distribution = distribution
self.lineLimit = lineLimit
self.content = content
self.content = content()
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Orbit/Components/Tile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public struct Tile<Content: View>: View {
let titleStyle: Heading.Style
let descriptionColor: Text.Color
let action: () -> Void
let content: () -> Content
@ViewBuilder let content: Content

public var body: some View {
SwiftUI.Button(
Expand All @@ -107,7 +107,7 @@ public struct Tile<Content: View>: View {
HStack(spacing: 0) {
VStack(spacing: 0) {
header
content()
content
}
.frame(maxWidth: .infinity, alignment: .leading)

Expand Down Expand Up @@ -207,7 +207,7 @@ public extension Tile {
titleStyle: Heading.Style = .title4,
descriptionColor: Text.Color = .inkLight,
action: @escaping () -> Void = {},
@ViewBuilder content: @escaping () -> Content
@ViewBuilder content: () -> Content
) {
self.title = title
self.description = description
Expand All @@ -219,7 +219,7 @@ public extension Tile {
self.titleStyle = titleStyle
self.descriptionColor = descriptionColor
self.action = action
self.content = content
self.content = content()
}

/// Creates Orbit Tile component.
Expand Down
Loading

0 comments on commit 18bdc18

Please sign in to comment.