forked from shadowfacts/Tusker
Fix preferences not checking current account correctly when multiple scenes open
This commit is contained in:
parent
a13d5d5a82
commit
77c9fac3ce
|
@ -14,7 +14,7 @@ class PreferencesNavigationController: UINavigationController {
|
||||||
private var isSwitchingAccounts = false
|
private var isSwitchingAccounts = false
|
||||||
|
|
||||||
init(mastodonController: MastodonController) {
|
init(mastodonController: MastodonController) {
|
||||||
let view = PreferencesView()
|
let view = PreferencesView(mastodonController: mastodonController)
|
||||||
let hostingController = UIHostingController(rootView: view)
|
let hostingController = UIHostingController(rootView: view)
|
||||||
super.init(rootViewController: hostingController)
|
super.init(rootViewController: hostingController)
|
||||||
hostingController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
hostingController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
||||||
|
|
|
@ -8,8 +8,13 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct PreferencesView: View {
|
struct PreferencesView: View {
|
||||||
|
let mastodonController: MastodonController
|
||||||
@ObservedObject var localData = LocalData.shared
|
@ObservedObject var localData = LocalData.shared
|
||||||
@State private var showingLogoutConfirmation = false
|
@State private var showingLogoutConfirmation = false
|
||||||
|
|
||||||
|
init(mastodonController: MastodonController) {
|
||||||
|
self.mastodonController = mastodonController
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
// workaround: the navigation view is provided by MyProfileTableViewController so that it can inject the Done button
|
||||||
|
@ -30,7 +35,7 @@ struct PreferencesView: View {
|
||||||
.foregroundColor(.primary)
|
.foregroundColor(.primary)
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
if account == self.localData.getMostRecentAccount() {
|
if account == mastodonController.accountInfo! {
|
||||||
Image(systemName: "checkmark")
|
Image(systemName: "checkmark")
|
||||||
.renderingMode(.template)
|
.renderingMode(.template)
|
||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
|
@ -43,7 +48,7 @@ struct PreferencesView: View {
|
||||||
}.onDelete { (indices: IndexSet) in
|
}.onDelete { (indices: IndexSet) in
|
||||||
var indices = indices
|
var indices = indices
|
||||||
var logoutFromCurrent = false
|
var logoutFromCurrent = false
|
||||||
if let index = indices.first(where: { localData.accounts[$0] == localData.getMostRecentAccount() }) {
|
if let index = indices.first(where: { localData.accounts[$0] == mastodonController.accountInfo! }) {
|
||||||
logoutFromCurrent = true
|
logoutFromCurrent = true
|
||||||
indices.remove(index)
|
indices.remove(index)
|
||||||
}
|
}
|
||||||
|
@ -102,10 +107,10 @@ struct PreferencesView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
//#if DEBUG
|
||||||
struct PreferencesView_Previews : PreviewProvider {
|
//struct PreferencesView_Previews : PreviewProvider {
|
||||||
static var previews: some View {
|
// static var previews: some View {
|
||||||
return PreferencesView()
|
// return PreferencesView()
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
#endif
|
//#endif
|
||||||
|
|
Loading…
Reference in New Issue