Setup gas price slider

This commit is contained in:
Ivan Grachyov 2021-12-14 00:10:45 +03:00
parent 7b16abd536
commit 7e67de8381
4 changed files with 37 additions and 3 deletions

View File

@ -141,6 +141,7 @@ extension ApproveTransactionViewController: UITableViewDataSource {
return cell return cell
case .gasPriceSlider: case .gasPriceSlider:
let cell = tableView.dequeueReusableCellOfType(GasPriceSliderTableViewCell.self, for: indexPath) let cell = tableView.dequeueReusableCellOfType(GasPriceSliderTableViewCell.self, for: indexPath)
cell.setup(value: nil, isEnabled: false, delegate: self)
return cell return cell
} }
@ -155,3 +156,11 @@ extension ApproveTransactionViewController: UITableViewDataSource {
} }
} }
extension ApproveTransactionViewController: GasPriceSliderDelegate {
func sliderValueChanged(value: Double) {
// TODO: update accorging to new value
}
}

View File

@ -2,12 +2,35 @@
import UIKit import UIKit
protocol GasPriceSliderDelegate: AnyObject {
func sliderValueChanged(value: Double)
}
class GasPriceSliderTableViewCell: UITableViewCell { class GasPriceSliderTableViewCell: UITableViewCell {
@IBOutlet weak var slowSpeedLabel: UILabel!
@IBOutlet weak var fastSpeedLabel: UILabel!
private weak var sliderDelegate: GasPriceSliderDelegate?
@IBOutlet weak var slider: UISlider! @IBOutlet weak var slider: UISlider!
@IBAction func sliderValueChanged(_ sender: Any) { @IBAction func sliderValueChanged(_ sender: Any) {
sliderDelegate?.sliderValueChanged(value: Double(slider.value))
}
func setup(value: Double?, isEnabled: Bool, delegate: GasPriceSliderDelegate) {
sliderDelegate = delegate
update(value: value, isEnabled: isEnabled)
}
func update(value: Double?, isEnabled: Bool) {
slider.isEnabled = isEnabled
slowSpeedLabel.alpha = isEnabled ? 1 : 0.5
fastSpeedLabel.alpha = isEnabled ? 1 : 0.5
if let value = value {
slider.value = Float(value)
}
} }
} }

View File

@ -28,7 +28,7 @@
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="qd0-pb-veR"> <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.33000000000000002" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="qd0-pb-veR">
<rect key="frame" x="49" y="16" width="228" height="34"/> <rect key="frame" x="49" y="16" width="228" height="34"/>
<constraints> <constraints>
<constraint firstAttribute="height" constant="33" id="p8e-ar-5IX"/> <constraint firstAttribute="height" constant="33" id="p8e-ar-5IX"/>
@ -51,7 +51,9 @@
</tableViewCellContentView> </tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/> <viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<connections> <connections>
<outlet property="fastSpeedLabel" destination="Icb-yb-97Y" id="Td0-vW-AYd"/>
<outlet property="slider" destination="qd0-pb-veR" id="JCq-Fs-VPp"/> <outlet property="slider" destination="qd0-pb-veR" id="JCq-Fs-VPp"/>
<outlet property="slowSpeedLabel" destination="ISk-hp-Adc" id="kcW-Fl-ttL"/>
</connections> </connections>
<point key="canvasLocation" x="140.57971014492756" y="143.63839285714286"/> <point key="canvasLocation" x="140.57971014492756" y="143.63839285714286"/>
</tableViewCell> </tableViewCell>

View File

@ -441,9 +441,9 @@
2C40709227667A8600AB3D55 /* ImageWithLabelTableViewCell.swift */, 2C40709227667A8600AB3D55 /* ImageWithLabelTableViewCell.swift */,
2C40709327667A8600AB3D55 /* ImageWithLabelTableViewCell.xib */, 2C40709327667A8600AB3D55 /* ImageWithLabelTableViewCell.xib */,
2C40708E27667A6600AB3D55 /* MultilineLabelTableViewCell.swift */, 2C40708E27667A6600AB3D55 /* MultilineLabelTableViewCell.swift */,
2C40708F27667A6600AB3D55 /* MultilineLabelTableViewCell.xib */,
2CC8C5A02767D3B30083FB1B /* GasPriceSliderTableViewCell.swift */, 2CC8C5A02767D3B30083FB1B /* GasPriceSliderTableViewCell.swift */,
2CC8C5A12767D3B30083FB1B /* GasPriceSliderTableViewCell.xib */, 2CC8C5A12767D3B30083FB1B /* GasPriceSliderTableViewCell.xib */,
2C40708F27667A6600AB3D55 /* MultilineLabelTableViewCell.xib */,
); );
path = Approve; path = Approve;
sourceTree = "<group>"; sourceTree = "<group>";