Skip to content

Commit 2595cc3

Browse files
committed
Рефактор
Вынес ProgressView на большинстве экранов из ZStack на .overlay и добавил анимацию
1 parent 697b4bc commit 2595cc3

File tree

18 files changed

+256
-243
lines changed

18 files changed

+256
-243
lines changed

SwiftUI-WorkoutApp/Screens/Components/SendMessageView.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ struct SendMessageView: View {
3535
}
3636

3737
var body: some View {
38-
ZStack {
39-
VStack {
40-
HeaderForSheet(title: header)
41-
Group {
42-
textView
43-
sendButtonStack
44-
}
45-
.padding(.horizontal)
46-
Spacer()
38+
VStack {
39+
HeaderForSheet(title: header)
40+
Group {
41+
textView
42+
sendButtonStack
4743
}
44+
.padding(.horizontal)
45+
Spacer()
46+
}
47+
.overlay {
4848
ProgressView()
4949
.opacity(isLoading ? 1 : .zero)
5050
}
51+
.disabled(isLoading)
5152
.alert(errorTitle, isPresented: $showErrorAlert) {
5253
Button(action: dismissError) { TextOk() }
5354
}

SwiftUI-WorkoutApp/Screens/Components/UsersList/UsersListView.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ struct UsersListView: View {
1010
let mode: Mode
1111

1212
var body: some View {
13-
ZStack {
14-
Form {
15-
if !viewModel.friendRequests.isEmpty {
16-
friendRequestsSection
17-
}
18-
List(viewModel.users, id: \.self) { model in
19-
NavigationLink {
20-
UserDetailsView(from: model)
21-
.navigationBarTitleDisplayMode(.inline)
22-
} label: {
23-
UserViewCell(model: model)
24-
}
25-
.disabled(model.id == defaults.mainUserID)
13+
Form {
14+
if !viewModel.friendRequests.isEmpty {
15+
friendRequestsSection
16+
}
17+
List(viewModel.users, id: \.self) { model in
18+
NavigationLink {
19+
UserDetailsView(from: model)
20+
.navigationBarTitleDisplayMode(.inline)
21+
} label: {
22+
UserViewCell(model: model)
2623
}
24+
.disabled(model.id == defaults.mainUserID)
2725
}
28-
.opacity(viewModel.isLoading ? 0.5 : 1)
29-
.animation(.easeInOut, value: viewModel.isLoading)
26+
}
27+
.opacity(viewModel.isLoading ? 0.5 : 1)
28+
.overlay {
3029
ProgressView()
3130
.opacity(viewModel.isLoading ? 1 : .zero)
3231
}
32+
.animation(.easeInOut, value: viewModel.isLoading)
3333
.disabled(viewModel.isLoading || !network.isConnected)
3434
.alert(errorTitle, isPresented: $showErrorAlert) {
3535
Button(action: closeAlert) { TextOk() }

SwiftUI-WorkoutApp/Screens/Events/Detail/EventDetailsView.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,43 @@ struct EventDetailsView: View {
2828
}
2929

3030
var body: some View {
31-
ZStack {
32-
Form {
33-
mainInfo
34-
locationInfo
35-
if viewModel.event.hasDescription {
36-
descriptionSection
37-
}
38-
if defaults.isAuthorized {
39-
participantsSection
40-
}
41-
if let photos = viewModel.event.photos,
42-
!photos.isEmpty {
43-
PhotoSectionView(
44-
with: photos,
45-
canDelete: isAuthor,
46-
deleteClbk: deletePhoto
47-
)
48-
}
49-
authorSection
50-
if !viewModel.event.comments.isEmpty {
51-
commentsSection
52-
}
53-
if defaults.isAuthorized {
54-
AddCommentButton(isCreatingComment: $isCreatingComment)
55-
.sheet(isPresented: $isCreatingComment) {
56-
TextEntryView(
57-
mode: .newForEvent(id: viewModel.event.id),
58-
refreshClbk: refreshAction
59-
)
60-
}
61-
}
31+
Form {
32+
mainInfo
33+
locationInfo
34+
if viewModel.event.hasDescription {
35+
descriptionSection
6236
}
63-
.opacity(viewModel.isLoading ? 0.5 : 1)
64-
.animation(.easeInOut, value: viewModel.isLoading)
37+
if defaults.isAuthorized {
38+
participantsSection
39+
}
40+
if let photos = viewModel.event.photos,
41+
!photos.isEmpty {
42+
PhotoSectionView(
43+
with: photos,
44+
canDelete: isAuthor,
45+
deleteClbk: deletePhoto
46+
)
47+
}
48+
authorSection
49+
if !viewModel.event.comments.isEmpty {
50+
commentsSection
51+
}
52+
if defaults.isAuthorized {
53+
AddCommentButton(isCreatingComment: $isCreatingComment)
54+
.sheet(isPresented: $isCreatingComment) {
55+
TextEntryView(
56+
mode: .newForEvent(id: viewModel.event.id),
57+
refreshClbk: refreshAction
58+
)
59+
}
60+
}
61+
}
62+
.opacity(viewModel.isLoading ? 0.5 : 1)
63+
.overlay {
6564
ProgressView()
6665
.opacity(viewModel.isLoading ? 1 : .zero)
6766
}
67+
.animation(.easeInOut, value: viewModel.isLoading)
6868
.disabled(viewModel.isLoading)
6969
.sheet(item: $editComment) {
7070
TextEntryView(

SwiftUI-WorkoutApp/Screens/Events/Form/EventFormView.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ struct EventFormView: View {
2929
}
3030

3131
var body: some View {
32-
ZStack {
33-
Form {
34-
eventNameSection
35-
datePickerSection
36-
sportsGroundSection
37-
descriptionSection
38-
if !viewModel.newImages.isEmpty {
39-
pickedImagesList
40-
}
41-
pickImagesButton
32+
Form {
33+
eventNameSection
34+
datePickerSection
35+
sportsGroundSection
36+
descriptionSection
37+
if !viewModel.newImages.isEmpty {
38+
pickedImagesList
4239
}
43-
.opacity(viewModel.isLoading ? 0.5 : 1)
44-
.animation(.easeInOut, value: viewModel.isLoading)
40+
pickImagesButton
41+
}
42+
.opacity(viewModel.isLoading ? 0.5 : 1)
43+
.overlay {
4544
ProgressView()
4645
.opacity(viewModel.isLoading ? 1 : .zero)
4746
}
47+
.animation(.easeInOut, value: viewModel.isLoading)
4848
.disabled(viewModel.isLoading)
4949
.sheet(isPresented: $isShowingPicker) {
5050
ImagePicker(

SwiftUI-WorkoutApp/Screens/Events/List/EventsListView.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ struct EventsListView: View {
1616
NavigationView {
1717
VStack {
1818
segmentedControl
19-
ZStack {
20-
if showEmptyView {
21-
emptyView
22-
} else {
23-
eventsList
24-
}
25-
ProgressView()
26-
.opacity(viewModel.isLoading ? 1 : .zero)
19+
if showEmptyView {
20+
emptyView
21+
} else {
22+
eventsList
2723
}
2824
}
25+
.opacity(viewModel.isLoading ? 0.5 : 1)
26+
.overlay {
27+
ProgressView()
28+
.opacity(viewModel.isLoading ? 1 : .zero)
29+
}
30+
.animation(.default, value: viewModel.isLoading)
2931
.alert(alertMessage, isPresented: $showErrorAlert) {
3032
Button(action: closeAlert) { TextOk() }
3133
}

SwiftUI-WorkoutApp/Screens/Journals/EntriesList/JournalEntriesList.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ struct JournalEntriesList: View {
2525
}
2626

2727
var body: some View {
28-
ZStack {
29-
List {
30-
ForEach(viewModel.list) {
31-
JournalEntryCell(
32-
model: $0,
33-
deleteClbk: initiateDeletion,
34-
editClbk: setupEntryToEdit
35-
)
36-
}
28+
List {
29+
ForEach(viewModel.list) {
30+
JournalEntryCell(
31+
model: $0,
32+
deleteClbk: initiateDeletion,
33+
editClbk: setupEntryToEdit
34+
)
3735
}
38-
.opacity(viewModel.isLoading ? 0.5 : 1)
39-
.animation(.easeInOut, value: viewModel.isLoading)
36+
}
37+
.opacity(viewModel.isLoading ? 0.5 : 1)
38+
.overlay {
4039
ProgressView()
4140
.opacity(viewModel.isLoading ? 1 : .zero)
4241
}
42+
.animation(.default, value: viewModel.isLoading)
4343
.disabled(viewModel.isLoading)
4444
.sheet(item: $editEntry) {
4545
TextEntryView(

SwiftUI-WorkoutApp/Screens/Journals/JournalsList/JournalsListView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ struct JournalsListView: View {
2121
}
2222

2323
var body: some View {
24-
ZStack {
24+
Group {
2525
if viewModel.list.isEmpty {
2626
emptyContentView
2727
} else {
2828
journalsList
2929
}
30+
}
31+
.opacity(viewModel.isLoading ? 0.5 : 1)
32+
.overlay {
3033
ProgressView()
3134
.opacity(viewModel.isLoading ? 1 : .zero)
3235
}
36+
.animation(.default, value: viewModel.isLoading)
3337
.disabled(viewModel.isLoading)
3438
.confirmationDialog(
3539
Constants.Alert.deleteJournal,

SwiftUI-WorkoutApp/Screens/Journals/Settings/JournalSettingsView.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ struct JournalSettingsView: View {
2323
}
2424

2525
var body: some View {
26-
ZStack {
27-
VStack(spacing: .zero) {
28-
headerView
29-
Form {
30-
TextField("Название дневника", text: $journal.title)
31-
visibilitySettings
32-
commentsSettings
33-
saveButton
34-
}
26+
VStack(spacing: .zero) {
27+
headerView
28+
Form {
29+
TextField("Название дневника", text: $journal.title)
30+
visibilitySettings
31+
commentsSettings
32+
saveButton
3533
}
36-
.opacity(viewModel.isLoading ? 0.5 : 1)
37-
.animation(.easeInOut, value: viewModel.isLoading)
34+
}
35+
.opacity(viewModel.isLoading ? 0.5 : 1)
36+
.overlay {
3837
ProgressView()
3938
.opacity(viewModel.isLoading ? 1 : .zero)
4039
}
40+
.animation(.easeInOut, value: viewModel.isLoading)
4141
.disabled(viewModel.isLoading)
4242
.interactiveDismissDisabled(viewModel.isLoading)
4343
.onChange(of: viewModel.errorMessage, perform: setupErrorAlert)

SwiftUI-WorkoutApp/Screens/Messages/DialogList/DialogListView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ struct DialogListView: View {
1414
@State private var deleteDialogTask: Task<Void, Never>?
1515

1616
var body: some View {
17-
ZStack {
17+
Group {
1818
if viewModel.list.isEmpty {
1919
emptyContentView
2020
} else {
2121
dialogList
2222
}
23+
}
24+
.opacity(viewModel.isLoading ? 0.5 : 1)
25+
.overlay {
2326
ProgressView()
2427
.opacity(viewModel.isLoading ? 1 : .zero)
2528
}
29+
.animation(.default, value: viewModel.isLoading)
2630
.confirmationDialog(
2731
Constants.Alert.deleteDialog,
2832
isPresented: $showDeleteConfirmation,

SwiftUI-WorkoutApp/Screens/Profile/Detail/UserDetailsView.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ struct UserDetailsView: View {
2626
}
2727

2828
var body: some View {
29-
ZStack {
30-
Form {
31-
userInfoSection
32-
if !isMainUser {
33-
communicationSection
34-
}
35-
socialInfoSection
29+
Form {
30+
userInfoSection
31+
if !isMainUser {
32+
communicationSection
3633
}
37-
.disabled(viewModel.isLoading)
38-
.opacity(viewModel.user.isFull ? 1 : .zero)
39-
.animation(.default, value: viewModel.isLoading)
34+
socialInfoSection
35+
}
36+
.opacity(viewModel.user.isFull ? 1 : .zero)
37+
.overlay {
4038
ProgressView()
4139
.opacity(viewModel.isLoading ? 1 : .zero)
4240
}
41+
.animation(.default, value: viewModel.isLoading)
42+
.disabled(viewModel.isLoading)
4343
.alert(errorTitle, isPresented: $showErrorAlert) {
4444
Button(action: closeAlert) { TextOk() }
4545
}

0 commit comments

Comments
 (0)