Skip to content

Commit e0bfbc6

Browse files
authored
Правки пикера фото (#250)
* Правки пикера фото - Если лимит на добавление фото исчерпан, сразу так и пишем вместо "Добавьте фото, максимум Х" - Добавил превью для пикера на самые важные сценарии * Поднял версию билда до 6
1 parent be1e165 commit e0bfbc6

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

SwiftUI-WorkoutApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@
846846
CLANG_TIDY_MISC_REDUNDANT_EXPRESSION = YES;
847847
CLANG_WARN_SEMICOLON_BEFORE_METHOD_BODY = YES;
848848
CODE_SIGN_STYLE = Automatic;
849-
CURRENT_PROJECT_VERSION = 5;
849+
CURRENT_PROJECT_VERSION = 6;
850850
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
851851
DEVELOPMENT_TEAM = CR68PP2Z3F;
852852
ENABLE_PREVIEWS = YES;
@@ -896,7 +896,7 @@
896896
CLANG_TIDY_MISC_REDUNDANT_EXPRESSION = YES;
897897
CLANG_WARN_SEMICOLON_BEFORE_METHOD_BODY = YES;
898898
CODE_SIGN_STYLE = Automatic;
899-
CURRENT_PROJECT_VERSION = 5;
899+
CURRENT_PROJECT_VERSION = 6;
900900
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
901901
DEVELOPMENT_TEAM = CR68PP2Z3F;
902902
ENABLE_PREVIEWS = YES;

SwiftUI-WorkoutApp/Screens/Common/ImagePicker/PickedImagesGrid.swift

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct PickedImagesGrid: View {
2121
/// Сколько еще можно выбрать фотографий
2222
let selectionLimit: Int
2323
/// Обработать добавление лишних фотографий
24+
///
25+
/// У стандартного пикера есть баг: иногда можно нажать на фото больше раз, чем позволяет лимит
2426
let processExtraImages: () -> Void
2527

2628
var body: some View {
@@ -94,13 +96,12 @@ private extension PickedImagesGrid {
9496
}
9597

9698
var subtitle: String {
97-
if images.isEmpty {
98-
String(format: NSLocalizedString("Добавьте фото, максимум %lld", comment: ""), selectionLimit)
99-
} else {
100-
selectionLimit > 0
101-
? String(format: NSLocalizedString("Можно добавить ещё %lld", comment: ""), selectionLimit)
102-
: NSLocalizedString("Добавлено максимальное количество фотографий", comment: "")
99+
guard selectionLimit > 0 else {
100+
return NSLocalizedString("Добавлено максимальное количество фотографий", comment: "")
103101
}
102+
return images.isEmpty
103+
? String(format: NSLocalizedString("Добавьте фото, максимум %lld", comment: ""), selectionLimit)
104+
: String(format: NSLocalizedString("Можно добавить ещё %lld", comment: ""), selectionLimit)
104105
}
105106

106107
func deletePhoto(at index: Int) {
@@ -110,14 +111,44 @@ private extension PickedImagesGrid {
110111
}
111112

112113
#if DEBUG
113-
#Preview {
114+
#Preview("Лимит 10, есть 0") {
114115
PickedImagesGrid(
115-
images: .constant([
116-
.init(systemName: "person")!,
117-
.init(systemName: "book")!
118-
]),
116+
images: .constant([]),
119117
showImagePicker: .constant(false),
120-
selectionLimit: 5,
118+
selectionLimit: 10,
119+
processExtraImages: {}
120+
)
121+
}
122+
123+
#Preview("Лимит 7, есть 3") {
124+
let images: [UIImage] = Array(1 ... 3).map {
125+
.init(systemName: "\($0).circle.fill")!
126+
}
127+
PickedImagesGrid(
128+
images: .constant(images),
129+
showImagePicker: .constant(false),
130+
selectionLimit: 7,
131+
processExtraImages: {}
132+
)
133+
}
134+
135+
#Preview("Лимит 0, есть 10") {
136+
let images: [UIImage] = Array(1 ... 10).map {
137+
.init(systemName: "\($0).circle.fill")!
138+
}
139+
PickedImagesGrid(
140+
images: .constant(images),
141+
showImagePicker: .constant(false),
142+
selectionLimit: 0,
143+
processExtraImages: {}
144+
)
145+
}
146+
147+
#Preview("Лимит 0, есть 0") {
148+
PickedImagesGrid(
149+
images: .constant([]),
150+
showImagePicker: .constant(false),
151+
selectionLimit: 0,
121152
processExtraImages: {}
122153
)
123154
}

0 commit comments

Comments
 (0)