Skip to content

Commit 0a5d50e

Browse files
committed
fix: require calculator input callbacks
1 parent d9996ed commit 0a5d50e

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

Bitkit/Components/Widgets/CalculatorWidget.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ struct CalculatorWidget: View {
345345

346346
struct CalculatorWidgetWideContent: View {
347347
let values: CalculatorWidgetValues
348-
var activeInput: CalculatorMoneyType?
349-
var onSelectInput: ((CalculatorMoneyType) -> Void)?
348+
let activeInput: CalculatorMoneyType?
349+
let onSelectInput: (CalculatorMoneyType) -> Void
350350

351351
var body: some View {
352352
VStack(spacing: 16) {
@@ -361,7 +361,7 @@ struct CalculatorWidgetWideContent: View {
361361
isActive: activeInput == .bitcoin,
362362
accessibilityIdentifier: "CalculatorBtcInput"
363363
) {
364-
onSelectInput?(.bitcoin)
364+
onSelectInput(.bitcoin)
365365
}
366366

367367
CalculatorWidgetRow(
@@ -375,7 +375,7 @@ struct CalculatorWidgetWideContent: View {
375375
isActive: activeInput == .fiat,
376376
accessibilityIdentifier: "CalculatorFiatInput"
377377
) {
378-
onSelectInput?(.fiat)
378+
onSelectInput(.fiat)
379379
}
380380
}
381381
}

Bitkit/Views/Widgets/CalculatorWidgetPreviewView.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct CalculatorWidgetPreviewView: View {
88

99
// TODO: revert to 0 to re-enable the compact widget preview
1010
@State private var carouselPage: Int = 1
11+
@State private var previewActiveInput: CalculatorMoneyType?
1112
@State private var showDeleteAlert = false
1213
@State private var values = CalculatorWidgetValues()
1314

@@ -60,6 +61,9 @@ struct CalculatorWidgetPreviewView: View {
6061
.onChange(of: currency.rates) {
6162
hydrateValues()
6263
}
64+
.onDisappear {
65+
previewActiveInput = nil
66+
}
6367
.alert(
6468
t("widgets__delete__title"),
6569
isPresented: $showDeleteAlert,
@@ -96,11 +100,15 @@ struct CalculatorWidgetPreviewView: View {
96100
private var widePage: some View {
97101
VStack {
98102
Spacer(minLength: 0)
99-
CalculatorWidgetWideContent(values: values)
100-
.padding(16)
101-
.background(Color.gray6)
102-
.cornerRadius(16)
103-
.frame(maxWidth: .infinity)
103+
CalculatorWidgetWideContent(
104+
values: values,
105+
activeInput: previewActiveInput,
106+
onSelectInput: selectInput
107+
)
108+
.padding(16)
109+
.background(Color.gray6)
110+
.cornerRadius(16)
111+
.frame(maxWidth: .infinity)
104112
Spacer(minLength: 0)
105113
}
106114
}
@@ -192,6 +200,10 @@ struct CalculatorWidgetPreviewView: View {
192200
return CalculatorWidgetFormatter.fiatRawValue(from: converted.value)
193201
}
194202

203+
private func selectInput(_ input: CalculatorMoneyType) {
204+
previewActiveInput = input
205+
}
206+
195207
private func onSave() {
196208
widgets.saveWidget(widgetType)
197209
navigation.reset()

0 commit comments

Comments
 (0)