Skip to content

Commit ed700c9

Browse files
authored
Избавляюсь от негибких габаритов (#289)
При повороте экрана эти габариты ломали UI
1 parent 59aff55 commit ed700c9

File tree

5 files changed

+24
-35
lines changed

5 files changed

+24
-35
lines changed

SwiftUI-WorkoutApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@
874874
CLANG_TIDY_MISC_REDUNDANT_EXPRESSION = YES;
875875
CLANG_WARN_SEMICOLON_BEFORE_METHOD_BODY = YES;
876876
CODE_SIGN_STYLE = Automatic;
877-
CURRENT_PROJECT_VERSION = 1;
877+
CURRENT_PROJECT_VERSION = 2;
878878
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
879879
DEVELOPMENT_TEAM = CR68PP2Z3F;
880880
ENABLE_PREVIEWS = YES;
@@ -926,7 +926,7 @@
926926
CLANG_TIDY_MISC_REDUNDANT_EXPRESSION = YES;
927927
CLANG_WARN_SEMICOLON_BEFORE_METHOD_BODY = YES;
928928
CODE_SIGN_STYLE = Automatic;
929-
CURRENT_PROJECT_VERSION = 1;
929+
CURRENT_PROJECT_VERSION = 2;
930930
DEVELOPMENT_ASSET_PATHS = "SwiftUI-WorkoutApp/Preview\\ Content/PreviewContent.swift SwiftUI-WorkoutApp/Preview\\ Content";
931931
DEVELOPMENT_TEAM = CR68PP2Z3F;
932932
ENABLE_PREVIEWS = YES;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ extension ImagePickerViews {
3333
) -> some View {
3434
LazyVGrid(
3535
columns: .init(
36-
repeating: .init(
37-
.flexible(minimum: UIScreen.main.bounds.size.width * 0.287),
38-
spacing: 11
39-
),
36+
repeating: .init(.flexible(minimum: 50), spacing: 11),
4037
count: 3
4138
),
4239
spacing: 12

SwiftUI-WorkoutApp/Screens/Common/ParkLocation/MapSnapshotView.swift

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ import SwiftUI
66
/// Снапшот карты
77
struct MapSnapshotView: View {
88
let mapModel: MapModel
9-
let size: CGSize
9+
private let height: CGFloat = 153
1010
@State private var snapshotImage: UIImage?
1111

1212
var body: some View {
13-
contentView
14-
.animation(.easeInOut, value: snapshotImage)
15-
.onAppear(perform: generateSnapshot)
16-
.onChange(of: mapModel) { _ in
17-
generateSnapshot()
18-
}
13+
GeometryReader { geo in
14+
makeContentView(width: geo.size.width)
15+
.animation(.easeInOut, value: snapshotImage)
16+
.clipShape(.rect(cornerRadius: 8))
17+
.onAppear { generateSnapshot(size: geo.size) }
18+
.onChange(of: mapModel) { _ in generateSnapshot(size: geo.size) }
19+
.onChange(of: geo.size, perform: generateSnapshot)
20+
}
21+
.frame(height: height)
1922
}
2023
}
2124

@@ -35,25 +38,28 @@ extension MapSnapshotView {
3538
}
3639

3740
private extension MapSnapshotView {
38-
var contentView: some View {
41+
func makeContentView(width: CGFloat) -> some View {
3942
ZStack {
4043
if let image = snapshotImage {
4144
Image(uiImage: image)
42-
.transition(.scale)
45+
.resizable()
46+
.scaledToFit()
47+
.frame(width: width, height: height)
48+
.transition(.opacity.combined(with: .scale))
4349
} else {
4450
Image.defaultWorkout
4551
.resizable()
4652
.scaledToFit()
47-
.frame(width: size.width, height: size.height)
53+
.frame(width: width, height: height)
4854
.background(.black)
49-
.cornerRadius(12)
55+
.clipShape(.rect(cornerRadius: 12))
5056
.transition(.opacity.combined(with: .scale))
5157
}
5258
}
5359
}
5460

5561
@MainActor
56-
func generateSnapshot() {
62+
func generateSnapshot(size: CGSize) {
5763
guard mapModel.isComplete else { return }
5864
let regionRadius: CLLocationDistance = 1000
5965
let options = MKMapSnapshotter.Options()
@@ -105,8 +111,7 @@ private extension MapSnapshotView {
105111
mapModel: .init(
106112
latitude: 55.687001,
107113
longitude: 37.504467
108-
),
109-
size: .init(width: 350, height: 150)
114+
)
110115
)
111116
}
112117
}

SwiftUI-WorkoutApp/Screens/Common/ParkLocation/ParkLocationInfoView.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,13 @@ import SWUtils
55

66
/// Содержит снапшот карты, адрес и ссылку на построение маршрута в `Apple Maps`
77
struct ParkLocationInfoView: View {
8-
@MainActor
9-
private var screenWidth: CGFloat { UIScreen.main.bounds.size.width }
108
let snapshotModel: MapSnapshotView.MapModel
119
let address: String
1210
let appleMapsURL: URL?
1311

1412
var body: some View {
1513
VStack(spacing: 12) {
16-
MapSnapshotView(
17-
mapModel: snapshotModel,
18-
size: .init(
19-
width: screenWidth - 24 - 32, // 2 * 12 и 2 * 16 - отступы по бокам в фигме
20-
height: 153
21-
)
22-
)
23-
.cornerRadius(8)
14+
MapSnapshotView(mapModel: snapshotModel)
2415
if !address.isEmpty {
2516
Text(address)
2617
.font(.headline)

SwiftUI-WorkoutApp/Screens/Common/PhotoSection/PhotoSectionView.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import SWModels
55
/// Галерея с фотографиями
66
@MainActor
77
struct PhotoSectionView: View {
8-
private var screenWidth: CGFloat { UIScreen.main.bounds.size.width }
98
private let photos: [Photo]
109
/// `true` - есть доступ на удаление фото, `false` - нет доступа
1110
///
@@ -69,10 +68,7 @@ private extension PhotoSectionView {
6968
var gridView: some View {
7069
LazyVGrid(
7170
columns: .init(
72-
repeating: .init(
73-
.flexible(minimum: screenWidth * 0.282),
74-
spacing: 2
75-
),
71+
repeating: .init(.flexible(minimum: 50), spacing: 2),
7672
count: columns
7773
),
7874
spacing: 2

0 commit comments

Comments
 (0)