Skip to content

Commit 88e4352

Browse files
committed
Доработки
1. Для iOS 16+ добавил `axis: .vertical` в текстфилд 2. Поменял `transition` для отображения ошибки под текстфилдом 3. Если для `CachedImage` нет колбэка, то не добавляем `onTapGesture`, чтобы жесты не перехватывало 4. Для вьюхи с комментарием добавил действие перехода в профиль и заменил все колбэки на один с вложенным `enum` 5. Добавил цвет `swTabBar` 6. Рефактор
1 parent ae49399 commit 88e4352

16 files changed

+194
-64
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"colors" : [
3+
{
4+
"color" : {
5+
"color-space" : "srgb",
6+
"components" : {
7+
"alpha" : "0.940",
8+
"blue" : "0xFF",
9+
"green" : "0xFF",
10+
"red" : "0xFF"
11+
}
12+
},
13+
"idiom" : "universal"
14+
},
15+
{
16+
"appearances" : [
17+
{
18+
"appearance" : "luminosity",
19+
"value" : "dark"
20+
}
21+
],
22+
"color" : {
23+
"color-space" : "srgb",
24+
"components" : {
25+
"alpha" : "0.900",
26+
"blue" : "0x1A",
27+
"green" : "0x1A",
28+
"red" : "0x1A"
29+
}
30+
},
31+
"idiom" : "universal"
32+
}
33+
],
34+
"info" : {
35+
"author" : "xcode",
36+
"version" : 1
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import SwiftUI
22

33
/// Модификатор, добавляющий бордюр выбранной формы с цветом `swAccent`
4-
public struct BorderedClipshapeModifier: ViewModifier {
4+
struct BorderedClipShapeModifier: ViewModifier {
55
let clipShape: ClipShape
66

7-
public func body(content: Content) -> some View {
7+
func body(content: Content) -> some View {
88
switch clipShape {
9-
case .roundedRectangle:
9+
case .roundedRect:
1010
content
1111
.clipShape(
12-
RoundedRectangle(cornerRadius: 12, style: .continuous)
12+
RoundedRectangle(cornerRadius: 12)
1313
)
1414
.overlay {
15-
RoundedRectangle(cornerRadius: 12, style: .continuous)
15+
RoundedRectangle(cornerRadius: 12)
1616
.stroke(Color.swAccent, lineWidth: 2)
1717
}
1818
case .circle:
1919
content
20-
.clipShape(Circle())
20+
.clipShape(.circle)
2121
.overlay {
2222
Circle()
2323
.stroke(Color.swAccent, lineWidth: 2)
@@ -26,9 +26,9 @@ public struct BorderedClipshapeModifier: ViewModifier {
2626
}
2727
}
2828

29-
public extension BorderedClipshapeModifier {
29+
extension BorderedClipShapeModifier {
3030
enum ClipShape {
31-
case roundedRectangle
31+
case roundedRect
3232
case circle
3333
}
3434
}
@@ -40,12 +40,12 @@ public extension BorderedClipshapeModifier {
4040
.resizable()
4141
.scaledToFit()
4242
.frame(width: 80, height: 80)
43-
.borderedClipshape(.circle)
43+
.borderedCircleClipShape()
4444
Image.defaultWorkout
4545
.resizable()
4646
.scaledToFit()
4747
.frame(width: 120, height: 120)
48-
.borderedClipshape(.roundedRectangle)
48+
.borderedRoundedRectClipShape()
4949
}
5050
}
5151
#endif

Sources/SWDesignSystem/Internal/CardBackgroundModifier.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct CardBackgroundModifier: ViewModifier {
1010
content
1111
.padding(padding)
1212
.background {
13-
RoundedRectangle(cornerRadius: 12, style: .continuous)
13+
RoundedRectangle(cornerRadius: 12)
1414
.fill(Color.swCardBackground)
1515
.withShadow()
1616
}

Sources/SWDesignSystem/Public/CachedImage/CachedImage.swift

+13-5
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,24 @@ public struct CachedImage: View {
2121

2222
public var body: some View {
2323
CachedAsyncImage991(url: url) { uiImage in
24-
Image(uiImage: uiImage)
25-
.resizable()
26-
.scaledToFill()
27-
.onTapGesture { didTapImage?(uiImage) }
24+
if let didTapImage {
25+
makeImageView(uiImage)
26+
.onTapGesture { didTapImage(uiImage) }
27+
} else {
28+
makeImageView(uiImage)
29+
}
2830
} placeholder: {
2931
DefaultWorkoutImage(size: mode.size)
3032
}
3133
.frame(width: mode.size.width, height: mode.size.height)
3234
.clipped()
33-
.cornerRadius(cornerRadius)
35+
.clipShape(.rect(cornerRadius: cornerRadius))
36+
}
37+
38+
private func makeImageView(_ uiImage: UIImage) -> some View {
39+
Image(uiImage: uiImage)
40+
.resizable()
41+
.scaledToFill()
3442
}
3543
}
3644

Sources/SWDesignSystem/Public/Color+.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public extension Color {
3333
static let swSearchBackground = Color(.swSearchBackground)
3434
/// Ошибки
3535
static let swError = Color(.swError)
36+
/// Цвет таббара
37+
static let swTabBar = Color(.swTabBar)
3638
}
3739

3840
#if DEBUG
@@ -41,13 +43,13 @@ public extension Color {
4143
.swBackground, .swCardBackground, .swSmallElements, .swSeparators,
4244
.swMainText, .swAccent, .swFilledButtonText, .swFilledButtonPressed,
4345
.swDisabledButton, .swDisabledButtonText, .swTintedButton,
44-
.swTintedButtonPressed, .swAddPhotoButton, .swError
46+
.swTintedButtonPressed, .swAddPhotoButton, .swError, .swTabBar
4547
]
4648
return ScrollView {
4749
VStack(spacing: 4) {
4850
ForEach(colors, id: \.self) { color in
4951
Circle()
50-
.foregroundStyle(color)
52+
.fill(color)
5153
.frame(width: 50, height: 50)
5254
}
5355
}

Sources/SWDesignSystem/Public/Icons.swift

-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,5 @@ public enum Icons {
7979
}
8080
}
8181
}
82-
.previewDisplayName("Icons")
8382
}
8483
#endif

Sources/SWDesignSystem/Public/ProfileView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct ProfileView: View {
3030
public var body: some View {
3131
VStack(spacing: 12) {
3232
CachedImage(url: imageURL, mode: .profileAvatar)
33-
.borderedClipshape(.roundedRectangle)
33+
.borderedRoundedRectClipShape()
3434
VStack(spacing: 8) {
3535
Text(login)
3636
.lineLimit(2)

Sources/SWDesignSystem/Public/Rows/CommentRowView.swift

+51-25
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ public struct CommentRowView: View {
88
private let bodyText: String
99
private let isCommentByMainUser: Bool
1010
private let isNetworkConnected: Bool
11-
private let reportAction: () -> Void
12-
private let editAction: () -> Void
13-
private let deleteAction: () -> Void
11+
private let action: (Action) -> Void
1412

1513
public init(
1614
avatarURL: URL?,
@@ -19,19 +17,15 @@ public struct CommentRowView: View {
1917
bodyText: String,
2018
isCommentByMainUser: Bool,
2119
isNetworkConnected: Bool,
22-
reportAction: @escaping () -> Void,
23-
editAction: @escaping () -> Void,
24-
deleteAction: @escaping () -> Void
20+
action: @escaping (Action) -> Void
2521
) {
2622
self.avatarURL = avatarURL
2723
self.userName = userName
2824
self.dateText = dateText
2925
self.bodyText = bodyText
3026
self.isCommentByMainUser = isCommentByMainUser
3127
self.isNetworkConnected = isNetworkConnected
32-
self.reportAction = reportAction
33-
self.editAction = editAction
34-
self.deleteAction = deleteAction
28+
self.action = action
3529
}
3630

3731
public var body: some View {
@@ -44,6 +38,8 @@ public struct CommentRowView: View {
4438
}
4539
.lineLimit(1)
4640
.frame(maxWidth: .infinity, alignment: .leading)
41+
.contentShape(.rect)
42+
.onTapGesture { action(.openProfile) }
4743
if isNetworkConnected {
4844
menuButton
4945
}
@@ -54,23 +50,40 @@ public struct CommentRowView: View {
5450
}
5551
}
5652

53+
public extension CommentRowView {
54+
enum Action {
55+
/// Пожаловаться
56+
case report
57+
/// Редактировать
58+
case edit
59+
/// Удалить
60+
case delete
61+
/// Открыть профиль автора комментария
62+
case openProfile
63+
}
64+
}
65+
5766
private extension CommentRowView {
5867
var leadingImage: some View {
59-
CachedImage(url: avatarURL, mode: .commentAvatar)
60-
.borderedClipshape()
68+
CachedImage(
69+
url: avatarURL,
70+
mode: .commentAvatar,
71+
didTapImage: { _ in action(.openProfile) }
72+
)
73+
.borderedCircleClipShape()
6174
}
6275

6376
var menuButton: some View {
6477
Menu {
6578
if isCommentByMainUser {
66-
Button(action: editAction) {
79+
Button(action: { action(.edit) }) {
6780
Label("Изменить", systemImage: Icons.Regular.pencil.rawValue)
6881
}
69-
Button(role: .destructive, action: deleteAction) {
82+
Button(role: .destructive, action: { action(.delete) }) {
7083
Label("Удалить", systemImage: Icons.Regular.trash.rawValue)
7184
}
7285
} else {
73-
Button(role: .destructive, action: reportAction) {
86+
Button(role: .destructive, action: { action(.report) }) {
7487
Label("Пожаловаться", systemImage: Icons.Regular.exclamation.rawValue)
7588
}
7689
}
@@ -106,16 +119,29 @@ private extension CommentRowView {
106119

107120
#if DEBUG
108121
#Preview {
109-
CommentRowView(
110-
avatarURL: .init(string: "https://workout.su/uploads/avatars/2019/10/2019-10-07-01-10-08-yow.jpg")!,
111-
userName: "Kahar",
112-
dateText: "21 мая 2023",
113-
bodyText: "Классная площадка, часто тренируюсь здесь с друзьями",
114-
isCommentByMainUser: false,
115-
isNetworkConnected: true,
116-
reportAction: {},
117-
editAction: {},
118-
deleteAction: {}
119-
)
122+
VStack(spacing: 20) {
123+
CommentRowView(
124+
avatarURL: .init(string: "https://workout.su/uploads/avatars/2019/10/2019-10-07-01-10-08-yow.jpg")!,
125+
userName: "Kahar",
126+
dateText: "21 мая 2023",
127+
bodyText: "Классная площадка, часто тренируюсь здесь с друзьями",
128+
isCommentByMainUser: false,
129+
isNetworkConnected: true,
130+
action: { option in
131+
print("action: \(option)")
132+
}
133+
)
134+
CommentRowView(
135+
avatarURL: .init(string: "https://workout.su/uploads/avatars/2019/10/2019-10-07-01-10-08-yow.jpg")!,
136+
userName: "Kahar",
137+
dateText: "21 мая 2023",
138+
bodyText: "Классная площадка, часто тренируюсь здесь с друзьями",
139+
isCommentByMainUser: true,
140+
isNetworkConnected: true,
141+
action: { option in
142+
print("action: \(option)")
143+
}
144+
)
145+
}
120146
}
121147
#endif

Sources/SWDesignSystem/Public/Rows/DialogRowView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public extension DialogRowView {
5858
private extension DialogRowView {
5959
var leadingImage: some View {
6060
CachedImage(url: model.avatarURL, mode: .userListItem)
61-
.borderedClipshape()
61+
.borderedCircleClipShape()
6262
}
6363

6464
var authorNameView: some View {

Sources/SWDesignSystem/Public/Rows/ListRowView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public extension ListRowView {
5151
}
5252

5353
public static func makeIconView(with name: Icons.Regular) -> some View {
54-
RoundedRectangle(cornerRadius: 8, style: .continuous)
54+
RoundedRectangle(cornerRadius: 8)
5555
.fill(Color.swTintedButton)
5656
.frame(width: 34, height: 34)
5757
.overlay {

Sources/SWDesignSystem/Public/Rows/ParkRowView.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ private extension ParkRowView {
7676
#if DEBUG
7777
#Preview {
7878
VStack(spacing: 12) {
79-
ParkRowView(
80-
imageURL: URL(string: "https://workout.su/uploads/userfiles/измайлово.jpg"),
81-
title: "N° 3 Легендарная / Средняя",
82-
address: "м. Партизанская, улица 2-я Советская",
83-
usersTrainHereText: "Тренируются 5 человек"
84-
)
79+
Button {
80+
print("tap!")
81+
} label: {
82+
ParkRowView(
83+
imageURL: URL(string: "https://workout.su/uploads/userfiles/измайлово.jpg"),
84+
title: "N° 3 Легендарная / Средняя",
85+
address: "м. Партизанская, улица 2-я Советская",
86+
usersTrainHereText: "Тренируются 5 человек"
87+
)
88+
}
8589
ParkRowView(
8690
imageURL: URL(string: "https://workout.su/uploads/userfiles/измайлово.jpg"),
8791
title: "N° 3 Легендарная / Средняя",

Sources/SWDesignSystem/Public/Rows/UserRowView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private extension UserRowView {
104104

105105
var leadingImage: some View {
106106
CachedImage(url: baseModel.imageURL, mode: .userListItem)
107-
.borderedClipshape()
107+
.borderedCircleClipShape()
108108
}
109109

110110
var userNameView: some View {

Sources/SWDesignSystem/Public/SWButtonStyle.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public struct SWButtonStyle: ButtonStyle {
3838
.padding(.horizontal, size.horizontalPadding)
3939
.frame(maxWidth: maxWidth)
4040
.background {
41-
RoundedRectangle(cornerRadius: 12, style: .continuous)
41+
RoundedRectangle(cornerRadius: 12)
4242
.fill(backgroundColor(configuration.isPressed))
4343
}
4444
.scaleEffect(configuration.isPressed ? 0.98 : 1)
@@ -178,6 +178,5 @@ extension SWButtonStyle.Size {
178178
.listRowBackground(Color.clear)
179179
}
180180
.listStyle(.grouped)
181-
.previewDisplayName("SWButtonStyle")
182181
}
183182
#endif

0 commit comments

Comments
 (0)