mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Wraps and Restores TickMarkSlider
This commit is contained in:
@@ -15,18 +15,15 @@ struct TimelineCustomizerView: View {
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Section {
|
||||
Section(header: Text("ICON_SIZE", tableName: "Settings")) {
|
||||
|
||||
ZStack {
|
||||
Picker(selection: $appDefaults.timelineIconSize) {
|
||||
ForEach(IconSize.allCases, id: \.self) { size in
|
||||
Text(size.description)
|
||||
}
|
||||
} label: {
|
||||
Text("ICON_SIZE", tableName: "Settings")
|
||||
}
|
||||
TickMarkSliderView(minValue: 1, maxValue: 3, currentValue: Binding(get: {
|
||||
Float(appDefaults.timelineIconSize.rawValue)
|
||||
}, set: { AppDefaults.shared.timelineIconSize = IconSize(rawValue: Int($0))! }))
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 4)
|
||||
.padding(.vertical, 8)
|
||||
.listRowInsets(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15))
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 8)
|
||||
@@ -37,18 +34,14 @@ struct TimelineCustomizerView: View {
|
||||
.listRowBackground(Color.clear)
|
||||
.listRowSeparator(.hidden)
|
||||
|
||||
Section {
|
||||
Section(header: Text("NUMBER_OF_LINES", tableName: "Settings")) {
|
||||
ZStack {
|
||||
Picker(selection: $appDefaults.timelineNumberOfLines) {
|
||||
ForEach(1...5, id: \.self) { size in
|
||||
Text("\(size)")
|
||||
}
|
||||
} label: {
|
||||
Text("NUMBER_OF_LINES", tableName: "Settings")
|
||||
}
|
||||
TickMarkSliderView(minValue: 1, maxValue: 5, currentValue: Binding(get: {
|
||||
Float(appDefaults.timelineNumberOfLines)
|
||||
}, set: { appDefaults.timelineNumberOfLines = Int($0) }))
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.vertical, 4)
|
||||
.padding(.vertical, 8)
|
||||
.listRowInsets(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15))
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 8)
|
||||
|
||||
@@ -7,6 +7,53 @@
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
struct TickMarkSliderView: UIViewRepresentable {
|
||||
|
||||
var minValue: Int
|
||||
var maxValue: Int
|
||||
@Binding var currentValue: Float
|
||||
|
||||
func makeUIView(context: Context) -> TickMarkSlider {
|
||||
let slider = TickMarkSlider()
|
||||
slider.minimumValue = Float(minValue)
|
||||
slider.maximumValue = Float(maxValue)
|
||||
slider.value = currentValue
|
||||
slider.addTickMarks()
|
||||
return slider
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: TickMarkSlider, context: Context) {
|
||||
uiView.addTarget(
|
||||
context.coordinator,
|
||||
action: #selector(Coordinator.valueChanged(_:)),
|
||||
for: .valueChanged
|
||||
)
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
Coordinator(value: $currentValue)
|
||||
}
|
||||
|
||||
class Coordinator: NSObject {
|
||||
var value: Binding<Float>
|
||||
|
||||
init(value: Binding<Float>) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
// Create a valueChanged(_:) action
|
||||
@objc func valueChanged(_ sender: Any) {
|
||||
if let slider = sender as? UISlider {
|
||||
self.value.wrappedValue = Float(slider.value.rounded())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
typealias UIViewType = TickMarkSlider
|
||||
}
|
||||
|
||||
class TickMarkSlider: UISlider {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user