Sesame-iOS/Sesame-Watch Watch App/Settings/SettingsNumberInputView.swift

46 lines
1.1 KiB
Swift
Raw Normal View History

2023-08-09 16:29:18 +02:00
import SwiftUI
struct SettingsNumberInputView: View {
let title: String
@Binding
var value: Int
@State
private var text: String = ""
let footnote: String
var body: some View {
VStack(alignment: .leading) {
TextField(title, text: $text)
.onSubmit {
guard let newValue = Int(text) else {
return
}
value = newValue
}
.foregroundColor(.accentColor)
Text(footnote)
.font(.footnote)
.foregroundColor(.secondary)
Spacer()
}
.navigationTitle(title)
.navigationBarBackButtonHidden(false)
.onAppear {
text = "\(value)"
}
}
}
struct SettingsNumberInputView_Previews: PreviewProvider {
static var previews: some View {
SettingsNumberInputView(
title: "Title",
value: .constant(0),
footnote: "Some more text explaining the purpose of the text field.")
}
}