Swiftpack.co - openalloc/SwiftTextFieldPreset as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by openalloc.
openalloc/SwiftTextFieldPreset 1.2.1
A multi-platform SwiftUI component for text input with presets support
⭐️ 1
🕓 26 weeks ago
iOS macOS watchOS
.package(url: "https://github.com/openalloc/SwiftTextFieldPreset.git", from: "1.2.1")

SwiftTextFieldPreset

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.

Features

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.

Installation

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"),

Example

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 structs with additional values that can used to populate your target value/object via the onSelect callback.

TODO

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

See Also

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

License

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.

Contributing

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.

GitHub

link
Stars: 1
Last commit: 26 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Watch stacking era begins
26 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics