Skip to content

Commit 45444f7

Browse files
committed
Clean.
1 parent f39f6ad commit 45444f7

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

en/tutorials/how-add-view-to-swiftui-library.md

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,34 @@ Library provides access to available SwiftUI View, modifiers, images, etc. You c
1212
First of all, let's implement our custom View, which will be responsible for the user's profile.
1313

1414
```swift
15-
//filename: UserProfileView.swift
16-
1715
struct User {
18-
let name: String
19-
let imageName: String
20-
let githubProfile: String
16+
17+
let name: String
18+
let imageName: String
19+
let githubProfile: String
2120
}
21+
```
2222

23+
```swift
2324
struct UserProfileView: View {
24-
let user: User
25-
26-
var body: some View {
27-
HStack {
28-
Image(user.imageName)
29-
.resizable()
30-
.frame(width: 40, height: 40)
31-
.clipShape(Circle())
32-
33-
VStack(alignment: .leading) {
34-
Text(user.name)
35-
Text(user.githubProfile)
36-
.foregroundColor(.gray)
37-
}
38-
}
39-
.padding(.all)
40-
}
25+
26+
let user: User
27+
28+
var body: some View {
29+
HStack {
30+
Image(user.imageName)
31+
.resizable()
32+
.frame(width: 40, height: 40)
33+
.clipShape(Circle())
34+
35+
VStack(alignment: .leading) {
36+
Text(user.name)
37+
Text(user.githubProfile)
38+
.foregroundColor(.gray)
39+
}
40+
}
41+
.padding(.all)
42+
}
4143
}
4244
```
4345

@@ -60,7 +62,13 @@ struct UserProfileLibrary: LibraryContentProvider {
6062
@LibraryContentBuilder
6163
var views: [LibraryItem] {
6264
LibraryItem(
63-
UserProfileView(user: User(name: "Nikita", imageName: "Nikita", githubProfile: "wmorgue")),
65+
UserProfileView(
66+
user: User(
67+
name: "Nikita",
68+
imageName: "Nikita",
69+
githubProfile: "wmorgue"
70+
)
71+
),
6472
visible: true, // whether it's visible in the Xcode library
6573
title: "User Profile", // the custom name shown in the library
6674
category: .control, // a category to find you custom views faster
@@ -69,6 +77,7 @@ struct UserProfileLibrary: LibraryContentProvider {
6977
}
7078
}
7179
```
80+
7281
The way we add a view to View Library is quite similar to how we make our view support preview function.
7382
The `LibraryContentProvider` protocol provides an ability to add custom views to the Xcode library.
7483
After that, we go to the `ContentView.swift` file and add the user view.
@@ -82,7 +91,13 @@ Caveat:
8291
3. When you use the system component, it will prefill all the parameters with usable default values. In our case, we get a user as our default value `User()`:
8392

8493
```swift
85-
UserProfileView(user: User(name: "Nikita", imageName: "Nikita", githubProfile: "wmorgue"))
94+
UserProfileView(
95+
user: User(
96+
name: "Nikita",
97+
imageName: "Nikita",
98+
githubProfile: "wmorgue
99+
)
100+
)
86101
```
87102
88103
Just waiting for changes in future versions to be able to add a description and icon.

ru/tutorials/how-add-view-to-swiftui-library.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ struct UserProfileLibrary: LibraryContentProvider {
6060
user: User(
6161
name: "Nikita",
6262
imageName: "Nikita",
63-
githubProfile: "wmorgue")
63+
githubProfile: "wmorgue"
64+
)
6465
),
6566
visible: true, // будет ли доступна наша View в библиотеке
6667
title: "User Profile", // заголовок, который будет отображаться

0 commit comments

Comments
 (0)