From 959e527d12ef7eafd454408a9c80ec5338a82d3a Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 8 Aug 2020 18:09:29 +0200 Subject: [PATCH] Fixed that if initially no TAN procedure was selected and user selected first entry, that selectedTanProcedureChanged() callback didn't get called --- .../BankingiOSApp/ui/TanProcedurePicker.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/TanProcedurePicker.swift b/ui/BankingiOSApp/BankingiOSApp/ui/TanProcedurePicker.swift index 4d7f56a2..c88b91bf 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/TanProcedurePicker.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/TanProcedurePicker.swift @@ -11,15 +11,17 @@ struct TanProcedurePicker: View { private var customersTanProcedures: [TanProcedure] = [] + private let initiallySelectedTanProcedure: TanProcedure? + @State private var selectedTanProcedureIndex: Int private var selectedTanProcedureIndexBinding: Binding { Binding( get: { self.selectedTanProcedureIndex }, - set: { - if (self.selectedTanProcedureIndex != $0) { // only if TAN procedure has really changed - self.selectedTanProcedureIndex = $0 - self.dispatchSelectedTanProcedureChanged(self.customersTanProcedures[$0]) + set: { newValue in + if (self.selectedTanProcedureIndex != newValue || self.initiallySelectedTanProcedure == nil) { // only if TAN procedure has really changed + self.selectedTanProcedureIndex = newValue + self.dispatchSelectedTanProcedureChanged(self.customersTanProcedures[newValue]) } }) } @@ -33,9 +35,10 @@ struct TanProcedurePicker: View { self.customersTanProcedures = bank.supportedTanProcedures.filter( {$0.type != .chiptanusb } ) // USB tan generators are not supported on iOS - let selectedTanProcedureType = initiallySelectedTanProcedure?.type ?? bank.selectedTanProcedure?.type + self.initiallySelectedTanProcedure = initiallySelectedTanProcedure ?? bank.selectedTanProcedure + let initiallySelectedTanProcedureType = self.initiallySelectedTanProcedure?.type - _selectedTanProcedureIndex = State(initialValue: customersTanProcedures.firstIndex(where: { $0.type == selectedTanProcedureType } ) + _selectedTanProcedureIndex = State(initialValue: customersTanProcedures.firstIndex(where: { $0.type == initiallySelectedTanProcedureType } ) ?? bank.supportedTanProcedures.firstIndex(where: { $0.type != .chiptanmanuell && $0.type != .chiptanusb } ) ?? 0) }