Skip to content

Commit bea6d51

Browse files
authored
Fix crash (#31)
* remove use of Zstack inlieu of overlays to avoid nav stack crash * var cleanup * fix another crash condition from incorrect navbar hidding * remove problematic comma * remove extra condition
1 parent 8468324 commit bea6d51

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

Django Files/Views/ContentView.swift

+20-27
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ struct ContentView: View {
1313
@Environment(\.dismiss) private var dismiss
1414

1515
@Query private var items: [DjangoFilesSession]
16-
@State private var showSidebarButton: Bool = false
1716
@State private var showingEditor = false
1817
@State private var columnVisibility = NavigationSplitViewVisibility.detailOnly
1918
@State private var selectedServer: DjangoFilesSession?
@@ -61,7 +60,6 @@ struct ContentView: View {
6160
}
6261
}
6362
}
64-
.toolbar(removing: !showSidebarButton ? .sidebarToggle : nil)
6563
} detail: {
6664
if let server = selectedServer {
6765
if server.auth {
@@ -70,25 +68,22 @@ struct ContentView: View {
7068
selectedServer: server,
7169
columnVisibility: $columnVisibility,
7270
showingEditor: $showingEditor,
73-
needsRefresh: $needsRefresh,
74-
showSidebarButton: $showSidebarButton
71+
needsRefresh: $needsRefresh
7572
)
7673
.id(server.url)
7774
.onAppear {
78-
showSidebarButton = false
7975
columnVisibility = .detailOnly
8076
}
77+
.toolbarVisibility(.hidden, for: .navigationBar)
8178
} else {
8279
LoginView(
8380
selectedServer: server,
8481
onLoginSuccess: {
8582
needsRefresh = true
86-
showSidebarButton = false
8783
}
8884
)
8985
.id(server.url)
9086
.onAppear {
91-
showSidebarButton = true
9287
columnVisibility = .detailOnly
9388
}
9489
}
@@ -145,25 +140,16 @@ public struct AuthViewContainer: View {
145140
@Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>
146141
@Query private var items: [DjangoFilesSession]
147142

143+
@State private var isAuthViewLoading: Bool = true
144+
148145
var viewingSettings: Binding<Bool>
149146
let selectedServer: DjangoFilesSession
150147
var columnVisibility: Binding<NavigationSplitViewVisibility>
151148
var showingEditor: Binding<Bool>
152149
var needsRefresh: Binding<Bool>
153-
var showSidebarButton: Binding<Bool>
154150

155151
@State private var authController: AuthController = AuthController()
156152

157-
var backButton : some View { Button(action: {
158-
self.presentationMode.wrappedValue.dismiss()
159-
}) {
160-
HStack {
161-
if !UIDevice.current.localizedModel.contains("iPad") {
162-
Text("Server List")
163-
}
164-
}
165-
}
166-
}
167153
public var body: some View {
168154
if viewingSettings.wrappedValue{
169155
SessionSelector(session: selectedServer, viewingSelect: viewingSettings)
@@ -172,22 +158,22 @@ public struct AuthViewContainer: View {
172158
}
173159
}
174160
else if selectedServer.url != "" {
175-
ZStack{
176-
Color.djangoFilesBackground.ignoresSafeArea()
177-
LoadingView().frame(width: 100, height: 100)
161+
Color.djangoFilesBackground.ignoresSafeArea()
162+
.overlay{
178163
AuthView(
179164
authController: authController,
180165
httpsUrl: selectedServer.url,
181166
doReset: authController.url?.absoluteString ?? "" != selectedServer.url || !selectedServer.auth,
182167
session: selectedServer
183168
)
184169
.onStartedLoading {
170+
isAuthViewLoading = true
185171
}
186172
.onCancelled {
173+
isAuthViewLoading = false
187174
dismiss()
188175
}
189176
.onAppear(){
190-
showSidebarButton.wrappedValue = false
191177
columnVisibility.wrappedValue = .detailOnly
192178
if needsRefresh.wrappedValue {
193179
authController.reset()
@@ -197,11 +183,17 @@ public struct AuthViewContainer: View {
197183
authController.onStartedLoadingAction = {
198184
}
199185

186+
authController.onLoadedAction = {
187+
isAuthViewLoading = false
188+
189+
}
200190
authController.onCancelledAction = {
191+
isAuthViewLoading = false
201192
dismiss()
202193
}
203194

204195
authController.onSchemeRedirectAction = {
196+
isAuthViewLoading = false
205197
guard let resolve = authController.schemeURL else{
206198
return
207199
}
@@ -210,15 +202,13 @@ public struct AuthViewContainer: View {
210202
if UIDevice.current.userInterfaceIdiom == .phone{
211203
self.presentationMode.wrappedValue.dismiss()
212204
}
213-
showSidebarButton.wrappedValue = true
214205
columnVisibility.wrappedValue = .all
215206
break
216207
case "serversettings":
217208
viewingSettings.wrappedValue = true
218209
break
219210
case "logout":
220211
selectedServer.auth = false
221-
showSidebarButton.wrappedValue = true
222212
columnVisibility.wrappedValue = .automatic
223213
modelContext.insert(selectedServer)
224214
do {
@@ -233,11 +223,14 @@ public struct AuthViewContainer: View {
233223
}
234224
}
235225
}
226+
.overlay {
227+
if isAuthViewLoading {
228+
LoadingView().frame(width: 100, height: 100)
229+
}
230+
}
236231
}
237-
.frame(maxWidth: .infinity, maxHeight: .infinity)
238232
.edgesIgnoringSafeArea(.all)
239-
.navigationTitle(Text(""))
240-
.navigationBarHidden(true)
233+
.frame(maxWidth: .infinity, maxHeight: .infinity)
241234
}
242235
else {
243236
Text("Loading...")

0 commit comments

Comments
 (0)