Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit 8653cf3

Browse files
committed
Add column
1 parent c9d2b81 commit 8653cf3

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

samples/discovery/ios/ios/ComponentBoxUI/Sources/ComponentBoxUI/ComponentBoxUI.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ enum ComponentBoxUI {
1818
action: String?
1919
)
2020

21+
case Column(
22+
id: String,
23+
components: [componentbox.Component]?,
24+
modifier: componentbox.Modifier?,
25+
verticalArrangement: componentbox.Arrangement?,
26+
horizontalAlignment: componentbox.Alignment?,
27+
action: String?,
28+
isLazy: Bool?
29+
)
30+
2131
case Button(id: String, components: [componentbox.Component]?, modifier: componentbox.Modifier?, isEnabled: Bool?, action: String?, variant: String?)
32+
2233
case Row(
2334
id: String,
2435
components: [componentbox.Component]?,
@@ -28,6 +39,7 @@ enum ComponentBoxUI {
2839
action: String?,
2940
isLazy: Bool?
3041
)
42+
3143
case Text(id: String, modifier: componentbox.Modifier?, text: String?, color: componentbox.Color?, textStyle: String?)
3244

3345
@available(iOS 14.0, *)
@@ -40,6 +52,9 @@ enum ComponentBoxUI {
4052
case let .Button(id, components, modifier, isEnabled, action, variant):
4153
return AnyView(ComponentBoxUIButton(id: id, components: components, modifier: modifier, isEnabled: isEnabled, action: action, variant: variant))
4254

55+
case let .Column(id, components, modifier, verticalArrangement, horizontalAlignment, action, isLazy):
56+
return AnyView(ComponentBoxUIColumn(id: id, components: components, modifier: modifier, verticalArrangement: verticalArrangement, horizontalAlignment: horizontalAlignment, action: action, isLazy: isLazy))
57+
4358
case let .Row(id, components, modifier, horizontalArrangement, verticalAlignment, action, isLazy):
4459
return AnyView(ComponentBoxUIRow(id: id, components: components, modifier: modifier, horizontalArrangement: horizontalArrangement, verticalAlignment: verticalAlignment, action: action, isLazy: isLazy))
4560

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Created by Matt Ramotar on 3/27/22.
3+
// Copyright (c) 2022 Dropbox, Inc. All rights reserved.
4+
//
5+
6+
import Foundation
7+
import SwiftUI
8+
import componentbox
9+
10+
@available(iOS 14.0, *)
11+
struct ComponentBoxUIColumn: View, Identifiable {
12+
let id: String
13+
let components: Array<componentbox.Component>?
14+
let modifier: componentbox.Modifier?
15+
let verticalArrangement: componentbox.Arrangement?
16+
let horizontalAlignment: componentbox.Alignment?
17+
let action: String?
18+
let isLazy: Bool?
19+
20+
21+
var body: some View {
22+
23+
let backgroundColor = modifier?.background != nil ? modifier!.background!.title.ui() : "Background".ui()
24+
25+
let padding = modifier?.padding != nil ? modifier!.padding!.build() : EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
26+
27+
if (self.components != nil) {
28+
if (self.isLazy == true) {
29+
ScrollView {
30+
ForEach(self.components!, id: \.self) { component in
31+
component.inflate()
32+
}
33+
}.frame(maxWidth: .infinity).padding(padding).background(backgroundColor)
34+
} else {
35+
VStack {
36+
ForEach(self.components!, id: \.self) { component in
37+
component.inflate()
38+
}
39+
}.frame(maxWidth: .infinity, alignment: .center).padding(padding).background(backgroundColor)
40+
}
41+
}
42+
}
43+
}

samples/discovery/ios/ios/ComponentBoxUI/Sources/ComponentBoxUI/extensions/inflate.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import componentbox
1010

1111
@available(iOS 14.0, *)
1212
public extension Component {
13-
@ViewBuilder func inflate() -> some View {
13+
func inflate() -> some View {
1414
switch self {
1515

1616
case let box as Component.Box:
@@ -29,6 +29,19 @@ public extension Component {
2929
let ui = ComponentBoxUI.Button(id: button.id, components: button.components as? [componentbox.Component], modifier: button.modifier, isEnabled: button.isEnabled as? Bool, action: button.action, variant: button.variant)
3030
return AnyView(ui.inflate())
3131

32+
case let column as Component.Column:
33+
let ui = ComponentBoxUI.Column(
34+
id: column.id,
35+
components: column.components as? [componentbox.Component],
36+
modifier: column.modifier,
37+
verticalArrangement: column.verticalArrangement,
38+
horizontalAlignment: column.horizontalAlignment,
39+
action: column.action,
40+
isLazy: column.isLazy as? Bool
41+
)
42+
43+
return AnyView(ui.inflate())
44+
3245
case let row as Component.Row:
3346
let ui = ComponentBoxUI.Row(
3447
id: row.id,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Created by Matt Ramotar on 3/27/22.
3+
// Copyright (c) 2022 Dropbox, Inc. All rights reserved.
4+
//
5+
6+
import Foundation
7+
import SwiftUI
8+
import componentbox
9+
10+
@available(iOS 14.0, *)
11+
extension componentbox.Padding {
12+
func build() -> EdgeInsets {
13+
14+
let top = CGFloat(self.top?.floatValue ?? 0)
15+
let bottom = CGFloat(self.bottom?.floatValue ?? 0)
16+
let leading = CGFloat(self.start?.floatValue ?? 0)
17+
let trailing = CGFloat(self.end?.floatValue ?? 0)
18+
19+
return EdgeInsets(top: top, leading: leading, bottom: bottom, trailing: trailing)
20+
}
21+
}

0 commit comments

Comments
 (0)