Skip to content

Commit 6abefca

Browse files
committed
Fix changing the number, now causes the text to update
1 parent 76e6e63 commit 6abefca

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Sources/NumericText/NumericTextField.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct NumericTextField: View {
2525
public init(_ titleKey: LocalizedStringKey, number: Binding<NSNumber?>, isDecimalAllowed: Bool, onEditingChanged: @escaping (Bool) -> Void = { _ in }, onCommit: @escaping () -> Void = {}) {
2626
_number = number
2727
if let number = number.wrappedValue, let string = decimalNumberFormatter.string(from: number) {
28-
_string = State(initialValue: string)
28+
_string = State(initialValue: string)
2929
} else {
3030
_string = State(initialValue: "")
3131
}

Sources/NumericText/NumericTextModifier.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public struct NumericTextModifier: ViewModifier {
3232
}
3333
number = decimalNumberFormatter.number(from: numeric)
3434
}
35+
.onChange(of: number, perform: { newValue in
36+
if let number = newValue {
37+
text = decimalNumberFormatter.string(from: number) ?? ""
38+
} else {
39+
text = ""
40+
}
41+
})
3542
}
3643
}
3744

0 commit comments

Comments
 (0)