Skip to content

Commit f1bab1d

Browse files
constantine-frymeta-codesync[bot]
authored andcommitted
Add a sample for CollectionViewCell
Summary: ditto Reviewed By: saadhzahid Differential Revision: D87453439 fbshipit-source-id: 526adb4d0ab79bdfaf18524e8a89687767c99210
1 parent 0c1ab2a commit f1bab1d

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

Sources/QuickLayout/docs/docs/code-samples.mdx

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,48 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
88

99
Here is few more samples to get you started.
1010

11+
```swift
12+
import QuickLayout
13+
14+
@QuickLayout
15+
final class FoobarCell: UICollectionViewCell {
16+
17+
private let imageView = UIImageView()
18+
private let titleLabel = UILabel()
19+
private let subtitleLabel = UILabel()
20+
21+
var body: Layout {
22+
HStack(spacing: 12) {
23+
imageView
24+
.resizable()
25+
.frame(width: 60, height: 60)
26+
VStack(alignment: .leading, spacing: 4) {
27+
titleLabel
28+
subtitleLabel
29+
}
30+
Spacer()
31+
}
32+
.padding(.horizontal, 16)
33+
.padding(.vertical, 8)
34+
}
35+
36+
func configure(image: UIImage?, title: String, subtitle: String) {
37+
imageView.image = image
38+
titleLabel.text = title
39+
subtitleLabel.text = subtitle
40+
setNeedsLayout() // Make sure this method is called to trigger the layout.
41+
}
42+
43+
override func prepareForReuse() {
44+
super.prepareForReuse()
45+
imageView.image = nil
46+
titleLabel.text = nil
47+
subtitleLabel.text = nil
48+
}
49+
}
50+
```
51+
----
52+
1153
<img width="200" src={useBaseUrl('img/sample_screenshot_1.png')} />
1254
<br/><br/>
1355

@@ -25,12 +67,12 @@ class LoginView: UIView {
2567
}
2668
}
2769

28-
let appIconView = IconView()
29-
let usernameField = TextField()
30-
let passwordField = PasswordField()
31-
let logInButton = PillButton(title: "Log in")
32-
let forgotPasswordButton = TextButton(title: "Forgot password?")
33-
let createAccountButton = PillButton(title: "Create new account")
70+
let appIconView = UIImageView()
71+
let usernameField = UITextField()
72+
let passwordField = UIButton()
73+
let logInButton = UIButton()
74+
let forgotPasswordButton = UIButton()
75+
let createAccountButton = UIButton()
3476

3577
var body: Layout {
3678
VStack {

0 commit comments

Comments
 (0)