From 04aa600e0d7d61319294ea5939703424c1d82eac Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 24 Jul 2024 18:05:33 -0400 Subject: [PATCH] address PR comments --- .../dydxFormatter/dydxNumberInputFormatter.swift | 2 +- .../Shared/dydxComponents/dydxSliderInputView.swift | 10 +++++++--- .../Shared/dydxComponents/dydxTitledNumberField.swift | 11 ++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/dydx/dydxFormatter/dydxFormatter/dydxNumberInputFormatter.swift b/dydx/dydxFormatter/dydxFormatter/dydxNumberInputFormatter.swift index 779701601..c81d4bb12 100644 --- a/dydx/dydxFormatter/dydxFormatter/dydxNumberInputFormatter.swift +++ b/dydx/dydxFormatter/dydxFormatter/dydxNumberInputFormatter.swift @@ -12,7 +12,7 @@ import Foundation public class dydxNumberInputFormatter: NumberFormatter { /// if greater than 0, numbers will be rounded to nearest 10, 100, 1000, etc. If less than 0 numbers will be rounded to nearest 0.1, 0.01, .001 - var fractionDigits: Int { + public var fractionDigits: Int { get { maximumFractionDigits } diff --git a/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxSliderInputView.swift b/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxSliderInputView.swift index 0cfafb048..8954aa2e4 100644 --- a/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxSliderInputView.swift +++ b/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxSliderInputView.swift @@ -17,7 +17,11 @@ public class dydxSliderInputViewModel: PlatformViewModel { @Published public var minValue: Double = 0 @Published public var maxValue: Double = 0 /// number of decimals after the decimal place to display - @Published public var precision: Int = 0 + @Published public var precision: Int = 0 { + didSet { + numberFormatter.fractionDigits = precision + } + } @Published public private(set) var valueAsString: String = "" @Published public var value: Double? { didSet { @@ -25,9 +29,9 @@ public class dydxSliderInputViewModel: PlatformViewModel { } } - var numberFormatter: dydxNumberInputFormatter { + private lazy var numberFormatter: dydxNumberInputFormatter = { dydxNumberInputFormatter(fractionDigits: precision) - } + }() init(title: String?, accessoryTitle: String? = nil, precision: Int) { self.title = title diff --git a/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxTitledNumberField.swift b/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxTitledNumberField.swift index d92427aa4..5e1c8cbd4 100644 --- a/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxTitledNumberField.swift +++ b/dydx/dydxViews/dydxViews/Shared/dydxComponents/dydxTitledNumberField.swift @@ -83,9 +83,14 @@ private struct NumberTextField: View { let minValue: Double let maxValue: Double let precision: Int - - private var numberFormatter: dydxNumberInputFormatter { - dydxNumberInputFormatter(fractionDigits: precision) + let numberFormatter: dydxNumberInputFormatter + + init(actualValue: Binding, minValue: Double, maxValue: Double, precision: Int) { + self._actualValue = actualValue + self.minValue = minValue + self.maxValue = maxValue + self.precision = precision + self.numberFormatter = dydxNumberInputFormatter(fractionDigits: precision) } private var keyboardType: UIKeyboardType {