A multi-platform SwiftUI component for text input with presets support
Available as an open source library to be incorporated in SwiftUI apps.
SwiftTextFieldPreset is part of the OpenAlloc family of open source Swift software tools.
iOS | watchOS | Presets Picker |
---|---|---|
- Builds on existing
TextField
component - Presently targeting .macOS(.v13), .iOS(.v16), .watchOS(.v9)
- Only Apple's Collections as an external dependency
- Note: with WatchOS 10, it seems to be no longer possible to integrate the presets button into the TextField. Now separated in a VStack.
In your Package.swift
:
To package .dependencies
add
.package(url: "https://github.com/openalloc/SwiftTextFieldPreset.git", .upToNextMajor(from: "1.1.2")),
To product .dependencies
add
.product(name: "TextFieldPreset", package: "SwiftTextFieldPreset"),
A simple example where the presets are String
type:
import SwiftUI
import TextFieldPreset
import Collections
struct MyView: View {
let presets: OrderedDictionary = [
"Machine/Free Weights": [
"Abdominal",
"Arm Curl",
],
"Bodyweight": [
"Crunch",
"Jumping-jack",
],
]
@State var name: String = "New Exercise"
var body: some View {
Form {
TextFieldPreset($name, prompt: "Enter name", axis: .vertical, presets: presets, pickerLabel: {
Text($0.description)
})
}
}
}
Note that presets can be more than String
, such as struct
s with additional values that can used to populate your target value/object via the onSelect
callback.
Please submit pull requests if you'd like to tackle any of these. Thanks!
- Usage documentation in this README
- See if earlier versions of platforms can be supported
This library is a member of the OpenAlloc Project.
- OpenAlloc - product website for all the OpenAlloc apps and libraries
- OpenAlloc Project - Github site for the development project, including full source code
Copyright 2023 OpenAlloc LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributions are welcome. You are encouraged to submit pull requests to fix bugs, improve documentation, or offer new features.
The pull request need not be a production-ready feature or fix. It can be a draft of proposed changes, or simply a test to show that expected behavior is buggy. Discussion on the pull request can proceed from there.