Skip to content

Commit 6c03d76

Browse files
authored
fix(ios): remove segmented control background and fix reconnect lifecycle (#681)
- Remove .background(.bar) from segmented tab picker for cleaner look - Fix infinite connecting loop when navigating back to same connection - Add .onAppear reconnect when driver session is lost - Guard against session reuse resetting isConnecting state
1 parent d19118d commit 6c03d76

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

TableProMobile/TableProMobile/Views/ConnectedView.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ struct ConnectedView: View {
110110
.pickerStyle(.segmented)
111111
.padding(.horizontal)
112112
.padding(.vertical, 8)
113-
.background(.bar)
114113
}
115114
.background {
116115
Button("") { selectedTab = .tables }
@@ -187,6 +186,13 @@ struct ConnectedView: View {
187186
queryHistory = historyStorage.load(for: connection.id)
188187
}
189188
}
189+
.onAppear {
190+
let hasDriver = appState.connectionManager.session(for: connection.id)?.driver != nil
191+
if !hasDriver, !isConnecting {
192+
appError = nil
193+
Task { await connect() }
194+
}
195+
}
190196
.onChange(of: scenePhase) { _, phase in
191197
if phase == .active, session != nil {
192198
Task { await reconnectIfNeeded() }
@@ -224,27 +230,23 @@ struct ConnectedView: View {
224230
return
225231
}
226232

227-
isConnecting = true
228-
appError = nil
229-
230-
// Reuse existing session if still alive in ConnectionManager
231233
if let existing = appState.connectionManager.session(for: connection.id) {
232234
self.session = existing
233235
do {
234236
self.tables = try await existing.driver.fetchTables(schema: nil)
235-
guard !Task.isCancelled else { return }
237+
isConnecting = false
236238
await loadDatabases()
237239
await loadSchemas()
238240
} catch {
239-
// Session stale — disconnect and reconnect
241+
self.session = nil
240242
await appState.connectionManager.disconnect(connection.id)
241243
await connectFresh()
242-
return
243244
}
244-
isConnecting = false
245245
return
246246
}
247247

248+
isConnecting = true
249+
appError = nil
248250
await connectFresh()
249251
}
250252

0 commit comments

Comments
 (0)