Fixed that loaded accounts didn't get displayed in AccountsTab by introducing App Data
This commit is contained in:
parent
d29965c77e
commit
72242d2cf7
|
@ -2,11 +2,13 @@ import SwiftUI
|
|||
|
||||
struct ContentView: View {
|
||||
|
||||
@ObservedObject var data: AppData = AppData()
|
||||
|
||||
@State private var selection = 0
|
||||
|
||||
var body: some View {
|
||||
TabView(selection: $selection) {
|
||||
AccountsTab()
|
||||
AccountsTab(data: data)
|
||||
.tabItem {
|
||||
VStack {
|
||||
Image("first")
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import Foundation
|
||||
import BankingUiSwift
|
||||
|
||||
|
||||
class AppData : ObservableObject {
|
||||
|
||||
@Inject private var presenter: BankingPresenterSwift
|
||||
|
||||
@Published var banks: [BUCCustomer] = []
|
||||
|
||||
|
||||
init() {
|
||||
banks = presenter.customers
|
||||
|
||||
presenter.addAccountsChangedListener { banks in
|
||||
self.banks = banks
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,23 +6,14 @@ struct AccountsTab: View {
|
|||
|
||||
@Inject private var presenter: BankingPresenterSwift
|
||||
|
||||
@State var banks: [BUCCustomer] = []
|
||||
|
||||
|
||||
init() {
|
||||
self.banks = presenter.customers
|
||||
}
|
||||
@ObservedObject var data: AppData
|
||||
|
||||
|
||||
var body: some View {
|
||||
presenter.addAccountsChangedListener { (customers) in // i think this will add a lot of listeners but i am not allowed to use this code in init()
|
||||
self.banks = customers
|
||||
}
|
||||
|
||||
return NavigationView {
|
||||
NavigationView {
|
||||
VStack {
|
||||
if self.banks.isEmpty == false {
|
||||
List(banks, id: \.id) { bank in
|
||||
if data.banks.isEmpty == false {
|
||||
List(data.banks, id: \.id) { bank in
|
||||
BankListItem(bank: bank)
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +31,12 @@ struct AccountsTab: View {
|
|||
|
||||
|
||||
struct AccountsTab_Previews: PreviewProvider {
|
||||
|
||||
static var previews: some View {
|
||||
AccountsTab()
|
||||
let data = AppData()
|
||||
data.banks = previewBanks
|
||||
|
||||
return AccountsTab(data: data)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue