Skip to content

Commit 0acbd9e

Browse files
author
Alex Usbergo
committed
format
1 parent 2c4a3f4 commit 0acbd9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3890
-3217
lines changed

demo/src/AppDelegate.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import UIKit
21
import RenderInspector
32
import RenderNeutrino
3+
import UIKit
44

55
@UIApplicationMain
66
class AppDelegate: UIResponder, UIApplicationDelegate {
77

88
var window: UIWindow?
9-
func application(_ application: UIApplication, didFinishLaunchingWithOptions
10-
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
9+
10+
func application(
11+
_ application: UIApplication,
12+
didFinishLaunchingWithOptions
13+
launchOptions: [UIApplicationLaunchOptionsKey: Any]?
14+
) -> Bool {
1115
// Starts the inspector in debug mode.
12-
// #if DEBUG
13-
// startRenderInspectorServer()
14-
// #endif
16+
// #if DEBUG
17+
// startRenderInspectorServer()
18+
// #endif
1519
// Parse the stylesheet file.
1620
do {
1721
try UIStylesheetManager.default.load(file: "stylesheet")

demo/src/components/AppStoreEntry.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import UIKit
21
import RenderNeutrino
2+
import UIKit
33

4-
struct AppStoreEntry {
4+
enum AppStoreEntry {
55

66
class State: UIState {
77
var expanded: Bool = false
@@ -29,7 +29,7 @@ struct AppStoreEntry {
2929
makeLabel(
3030
text: "\(props.title)#\(state.counter)",
3131
layoutSpec: configureLabel),
32-
]),
32+
]),
3333
// Entry description (shown when the component is expanded).
3434
UINode<UIView>(layoutSpec: configureDescriptionContainer).children([
3535
makeLabel(
@@ -38,23 +38,23 @@ struct AppStoreEntry {
3838
makeButton(
3939
text: "Increase",
4040
onTouchUpInside: { [weak self] in self?.onIncrease() })
41-
]),
41+
]),
4242
// Touch overlay that covers the whole component.
4343
makeTapRecognizer(
4444
onTouchUpInside: { [weak self] in self?.onToggleExpand() },
4545
layoutSpec: configureTappableView),
46-
])
46+
]),
4747
])
4848
}
4949

5050
// Executed when the card is tapped.
51-
private func onToggleExpand() -> Void {
51+
private func onToggleExpand() {
5252
state.expanded = !state.expanded
5353
setNeedsRender(options: [.animateLayoutChanges(animator: self.defaultAnimator())])
5454
}
5555

5656
// Executed when the 'Increase' button is tapped.
57-
private func onIncrease() -> Void {
57+
private func onIncrease() {
5858
state.counter += 1
5959
setNeedsRender()
6060
}
@@ -120,8 +120,7 @@ struct AppStoreEntry {
120120

121121
// The main title.
122122
private func configureLabel(spec: UINode<UILabel>.LayoutSpec) {
123-
let font: UIFont = state.expanded ?
124-
S.typography.mediumBold.font : S.typography.medium.font
123+
let font: UIFont = state.expanded ? S.typography.mediumBold.font : S.typography.medium.font
125124
spec.set(\UILabel.yoga.height, 32)
126125
spec.set(\UILabel.yoga.width, 256)
127126
spec.set(\UILabel.font, font)
@@ -176,7 +175,7 @@ fileprivate func makeLabel(
176175
fileprivate func makeButton(
177176
reuseIdentifier: String = "button",
178177
text: String,
179-
onTouchUpInside: @escaping () -> Void = { },
178+
onTouchUpInside: @escaping () -> Void = {},
180179
layoutSpec: UINode<UIButton>.LayoutSpecClosure? = nil
181180
) -> UINode<UIButton> {
182181
func makeButton() -> UIButton {
@@ -197,9 +196,9 @@ fileprivate func makeButton(
197196

198197
fileprivate func makeTapRecognizer(
199198
reuseIdentifier: String = "tapRecognizer",
200-
onTouchUpInside: @escaping () -> Void = { },
199+
onTouchUpInside: @escaping () -> Void = {},
201200
layoutSpec: UINode<UIView>.LayoutSpecClosure? = nil
202-
)->UINode<UIView> {
201+
) -> UINode<UIView> {
203202
return UINode<UIView>(reuseIdentifier: reuseIdentifier) { config in
204203
config.view.onTap { _ in onTouchUpInside() }
205204
layoutSpec?(config)

demo/src/components/Counter.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import UIKit
21
import RenderNeutrino
2+
import UIKit
33

4-
5-
struct StylesheetCounter {
4+
enum StylesheetCounter {
65

76
class State: UIState {
87
var counter: Int = 0
@@ -11,12 +10,12 @@ struct StylesheetCounter {
1110

1211
class Component: UIComponent<State, UINilProps> {
1312
override func render(context: UIContextProtocol) -> UINodeProtocol {
14-
let node = UINode<UIView>(styles: [S.counterWrapper])
13+
let node = UINode<UIView>(styles: [S.counterWrapper])
1514
return node.children([
1615
UINode<UILabel>(styles: [S.counterLabel], layoutSpec: configureLabel),
1716
UINode<UIButton>(
1817
styles: [S.counterButton],
19-
layoutSpec: configureButton)
18+
layoutSpec: configureButton),
2019
])
2120
}
2221

demo/src/components/CustomNavigationBar.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import RenderNeutrino
22

3-
struct Track {
3+
enum Track {
44

55
class NavigationBar: UINavigationBarComponent {
66
// Example of additional payload.
@@ -32,8 +32,7 @@ struct Track {
3232
spec.view.yoga.width = s
3333
spec.view.yoga.height = s
3434
spec.view.cornerRadius = s/2
35-
spec.view.alpha =
36-
pow(self.props.scrollProgress(currentHeight: self.state.height), 4)
35+
spec.view.alpha = pow(self.props.scrollProgress(currentHeight: self.state.height), 4)
3736

3837
// The mm:ss format string.
3938
guard let userInfo = self.props.userInfo(as: UserInfo.self) else { return }
@@ -47,7 +46,7 @@ struct Track {
4746
let button = UINode<UIButton>(styles: [S.trackNavigationBarButton]) { spec in
4847
spec.view.yoga.position = .absolute
4948
spec.view.yoga.top = self.state.height - 16
50-
spec.view.onTap { [weak self] _ in self?.didTapPlayButton() }
49+
spec.view.onTap { [weak self] _ in self?.didTapPlayButton() }
5150

5251
// Button label.
5352
guard let userInfo = self.props.userInfo(as: UserInfo.self) else { return }
@@ -56,7 +55,7 @@ struct Track {
5655
}
5756
return main.children([
5857
circle,
59-
button
58+
button,
6059
])
6160
}
6261

@@ -75,10 +74,11 @@ struct Track {
7574
return
7675
}
7776
// Schedule a timer.
78-
userInfo.timer = Timer(timeInterval: 1, repeats: true) { [weak self]_ in
79-
userInfo.elaspedTime += 1
80-
self?.setNeedsRender()
81-
}
77+
userInfo.timer
78+
= Timer(timeInterval: 1, repeats: true) { [weak self] _ in
79+
userInfo.elaspedTime += 1
80+
self?.setNeedsRender()
81+
}
8282

8383
guard let timer = userInfo.timer else { return }
8484
RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)
@@ -96,9 +96,11 @@ struct Track {
9696
/// Model for one the dummy track cells.
9797
class TrackProps: UIProps {
9898
var id: String = NSUUID().uuidString.lowercased()
99+
99100
lazy var title: String = {
100101
return "unknown artist\n" + "track " + self.id.replacingOccurrences(of: "-", with: "")
101102
}()
103+
102104
var cover: UIImage? = Random.image()
103105
}
104106

@@ -114,7 +116,7 @@ struct Track {
114116
},
115117
UINode<UILabel>(styles: [S.trackTitle]) { spec in
116118
spec.set(\UILabel.text, props.title)
117-
}
119+
},
118120
])
119121
return wrapper
120122
}

demo/src/components/FacebookPost.swift

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ protocol PostComponentDelegate: class {
55
func fetchComments(component: Post.PostComponent, post: Post.PostProps)
66
}
77

8-
struct Post {
8+
enum Post {
99

1010
class PostProps: UIProps {
1111
weak var delegate: PostComponentDelegate?
1212

1313
enum FetchStatus { case notFetched, fetching, fetched }
1414
var fetchStatus: FetchStatus = .notFetched
15-
15+
1616
var id: String = NSUUID().uuidString.lowercased()
1717
var text: String = Random.sentence()
1818
var attachment: UIImage? = Random.image()
@@ -42,12 +42,12 @@ struct Post {
4242
return UINode<UIView>(
4343
reuseIdentifier: S.postWrapper.id,
4444
styles: [S.postWrapper]).children([
45-
makeHeaderFragment(),
46-
makeBodyFragment(),
47-
makeAttachmentFragment(),
48-
makeStatsFragment(),
49-
makeCommentsFragment(),
50-
])
45+
makeHeaderFragment(),
46+
makeBodyFragment(),
47+
makeAttachmentFragment(),
48+
makeStatsFragment(),
49+
makeCommentsFragment(),
50+
])
5151
}
5252

5353
/// Returns the author avatar and fullname fragment.
@@ -58,11 +58,11 @@ struct Post {
5858
styles: [S.postHeader])
5959
let headerTextWrapper = UINode<UIView>(styles: [S.postHeaderTextWrapper])
6060
return header.children([
61-
UINode<UIImageView>(styles: [S.postAvatar]){ $0.set(\UIImageView.image, props.avatar)},
61+
UINode<UIImageView>(styles: [S.postAvatar]) { $0.set(\UIImageView.image, props.avatar) },
6262
headerTextWrapper.children([
6363
UINode<UILabel>(styles: [S.postAuthorName]) { $0.set(\UILabel.text, props.author) },
6464
UINode<UILabel>(styles: [S.postCaption]) { $0.set(\UILabel.text, "Just now") },
65-
])
65+
]),
6666
])
6767
}
6868

@@ -92,7 +92,8 @@ struct Post {
9292
let props = self.props
9393
let wrapper = UINode<UIView>(
9494
reuseIdentifier: S.postStats.id,
95-
styles: [S.postStats]) {
95+
styles: [S.postStats]
96+
) {
9697
$0.view.onTap { [weak self] _ in
9798
guard let `self` = self, props.fetchStatus == .notFetched else { return }
9899
props.delegate?.fetchComments(component: self, post: props)
@@ -123,12 +124,13 @@ struct Post {
123124
let wrapper = UINode<UIView>(
124125
reuseIdentifier: S.postCommentsWrapper.id,
125126
styles: [S.postCommentsWrapper])
126-
wrapper.children(props.comments.map {
127-
context.transientComponent(
128-
CommentComponent.self,
129-
props: $0,
130-
parent: self).asNode()
131-
})
127+
wrapper.children(
128+
props.comments.map {
129+
context.transientComponent(
130+
CommentComponent.self,
131+
props: $0,
132+
parent: self).asNode()
133+
})
132134
return wrapper
133135
}
134136
}
@@ -145,9 +147,9 @@ struct Post {
145147
return UINode<UIView>(
146148
reuseIdentifier: S.postComment.id,
147149
styles: [S.postComment]).children([
148-
UINode<UILabel>(styles: [S.postCommentAuthor]) { $0.set(\UILabel.text, props.author) },
149-
UINode<UILabel>(styles: [S.postCommentLabel]) { $0.set(\UILabel.text, props.text) }
150-
])
150+
UINode<UILabel>(styles: [S.postCommentAuthor]) { $0.set(\UILabel.text, props.author) },
151+
UINode<UILabel>(styles: [S.postCommentLabel]) { $0.set(\UILabel.text, props.text) },
152+
])
151153
}
152154
}
153155

demo/src/components/GettingStarted.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import UIKit
21
import RenderNeutrino
2+
import UIKit
33

44
// MARK: - Example 1
55

@@ -53,7 +53,7 @@ class SimpleCounterComponent2: UIComponent<CounterState, UINilProps> {
5353

5454
return container.children([
5555
label,
56-
])
56+
])
5757
}
5858

5959
/// Defines the layout and view specification for the container node.
@@ -90,7 +90,7 @@ class SimpleCounterComponent2: UIComponent<CounterState, UINilProps> {
9090
// MARK: - Example 3
9191

9292
class CounterProps: UIProps {
93-
var format: String = "Number of taps: %d"
93+
var format: String = "Number of taps: %d"
9494
}
9595

9696
class SimpleCounterComponent3: UIComponent<CounterState, CounterProps> {
@@ -102,7 +102,7 @@ class SimpleCounterComponent3: UIComponent<CounterState, CounterProps> {
102102

103103
return container.children([
104104
label,
105-
])
105+
])
106106
}
107107

108108
/// Defines the layout and view specification for the container node.
@@ -139,7 +139,7 @@ class SimpleCounterComponent3: UIComponent<CounterState, CounterProps> {
139139
// MARK: - Example 4
140140

141141
// We can define a namespace for our style.
142-
struct Style {
142+
enum Style {
143143
struct Palette {
144144
static let background: UIColor = .red
145145
static let text: UIColor = .white
@@ -202,7 +202,7 @@ class SimpleCounterComponent5: UIComponent<CounterState, CounterProps> {
202202
layoutSpec: labelLayoutSpec)
203203
return container.children([
204204
label,
205-
])
205+
])
206206
}
207207

208208
/// Defines the layout and view specification for the container node.

demo/src/components/Index.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import UIKit
21
import RenderNeutrino
2+
import UIKit
33

4-
struct Index {
4+
enum Index {
55

6-
class CellProps: UITableCellProps { }
6+
class CellProps: UITableCellProps {}
77

88
class Cell: UIStatelessComponent<CellProps> {
99
/// Builds the node hierarchy for this component.
@@ -17,16 +17,15 @@ struct Index {
1717
config.set(\UIView.yoga.flexGrow, 1)
1818
config.set(\UIView.yoga.flexShrink, 1)
1919
}.children([
20-
label(text: props.title, bold: true),
21-
label(text: props.subtitle),
22-
])
20+
label(text: props.title, bold: true),
21+
label(text: props.subtitle),
22+
]),
2323
])
2424
}
2525

2626
private func configureContentView(spec: UINode<UIView>.LayoutSpec) {
2727
let animator = UIViewPropertyAnimator(duration: 0.6, curve: .easeIn, animations: nil)
28-
let bkg = props.isHighlighted ?
29-
S.palette.primaryAccent.color : S.palette.primary.color
28+
let bkg = props.isHighlighted ? S.palette.primaryAccent.color : S.palette.primary.color
3029
/// Animates the background color when the cell is selected.
3130
spec.set(\UIView.yoga.flexDirection, .row)
3231
spec.set(\UIView.yoga.width, spec.canvasSize.width)

0 commit comments

Comments
 (0)