Refactor account tag determination so that SwiftUI would stop freaking out

This commit is contained in:
Maurice Parker 2019-09-16 05:42:36 -05:00
parent e3270f5ef4
commit 5d8d0d19df
1 changed files with 6 additions and 6 deletions

View File

@ -17,6 +17,8 @@ struct SettingsView : View {
@Environment(\.viewController) private var viewController: UIViewController? @Environment(\.viewController) private var viewController: UIViewController?
@Environment(\.sceneCoordinator) private var coordinator: SceneCoordinator? @Environment(\.sceneCoordinator) private var coordinator: SceneCoordinator?
@State private var accountAction: Int? = nil
@State private var isWebsitePresented: Bool = false @State private var isWebsitePresented: Bool = false
@State private var website: String? = nil @State private var website: String? = nil
@ -39,16 +41,14 @@ struct SettingsView : View {
} }
} }
@State private var accountAction: Int? = nil
func buildAccountsSection() -> some View { func buildAccountsSection() -> some View {
Section(header: Text("ACCOUNTS").padding(.top, 22.0)) { Section(header: Text("ACCOUNTS").padding(.top, 22.0)) {
ForEach(0..<viewModel.accounts.count) { index in ForEach(viewModel.accounts) { account in
NavigationLink(destination: SettingsDetailAccountView(viewModel: SettingsDetailAccountView.ViewModel(self.viewModel.accounts[index])), tag: index, selection: self.$accountAction) { NavigationLink(destination: SettingsDetailAccountView(viewModel: SettingsDetailAccountView.ViewModel(account)), tag: self.viewModel.accounts.firstIndex(of: account) ?? -1, selection: self.$accountAction) {
Text(verbatim: self.viewModel.accounts[index].nameForDisplay) Text(verbatim: account.nameForDisplay)
} }
.modifier(VibrantSelectAction(action: { .modifier(VibrantSelectAction(action: {
self.accountAction = index self.accountAction = self.viewModel.accounts.firstIndex(of: account)
})) }))
} }
NavigationLink(destination: SettingsAddAccountView(), tag: 1000, selection: $accountAction) { NavigationLink(destination: SettingsAddAccountView(), tag: 1000, selection: $accountAction) {