toastersocks / multipicker Goto Github PK
View Code? Open in Web Editor NEWA Picker for iOS that can be used to choose from one, one or none, or multiple options.
License: MIT License
A Picker for iOS that can be used to choose from one, one or none, or multiple options.
License: MIT License
Right now, in navigationLink
style pickers, when an optional binding is given to selection
and there is nothing selected, the choice is represented by the string "(None)". This is localizable, but not otherwise configurable.
There should be a way to configure how the "none" choice is represented, with "(None)" being default.
It should be configurable with some View
with a convenience String
option.
I'm not sure if these should be init parameters, or view modifiers though.
I'm hesitant to add more parameters to the init because:
SwiftUI.Picker
APIViewBuilder
closure parameters.init
APIMultiPicker
sBut on the other hand:
MultiPicker
Right now the selection indicator is always a checkmark that matches SwiftUI's Picker
. It might be nice for this to be configurable.
There should be a way to configure what the selection indicator is with the current checkmark being default.
Pass in a ViewBuilder
closure to make the selection indicator be whatever we want.
There could be a default set of selection indicators such as checkmark, bullet, highlight, radioButton, etc...
We could combine these two approaches with a set of built-in indicators, but also allow a totally custom indicator.
I would lean more towards a view modifier rather than init parameter for this one.
Wrong initialiser used when I was using this struct:
struct CurrencyPair: Hashable, Identifiable, Codable {
var id: String { description }
var base: String
var quote: String
var enabled: Bool
var description: String {
"\(base)/\(quote)"
}
}
with this code:
@State private var currencyPairSelection: Set<CurrencyPair>
@State private var currencyPairOptions: [CurrencyPair]
var settings: Settings
init(settings: Settings) {
self.settings = settings
_currencyPairOptions = State(initialValue: settings.currencyPairs)
let set = Set(settings.currencyPairs.filter { $0.enabled })
_currencyPairSelection = State(initialValue: set)
}
MultiPicker(selection: $currencyPairSelection, content: {
ForEach(currencyPairOptions, id: \.self) { option in
Text(option.description).mpTag(option)
}
}, label: {
Text("Enabled Currencies")
})
.mpPickerStyle(.navigationLink)
`
I wanted a Multiple option picker, but could not find the reason this was not working. So I CMD + Clicked on the MultiPicker to see what Initialiser was being used, turns out the selection property was set to single.
After I commented out the other intialisers except for the Binding<Set<>> one, Xcode finally gave the error that my struct needed to conform to CustomStringConvertible.
Finally, after adding this to the struct like this:
struct CurrencyPair: Hashable, Identifiable, Codable, CustomStringConvertible {
var id: String { description }
var base: String
var quote: String
var enabled: Bool
var description: String {
"\(base)/\(quote)"
}
}
it works perfectly!
Either add to the documentation that a custom struct must conform to CustomStringConvertible, or some kind of extra check to get the correct initialiser. Thanks!!
Does this support Mac Catalyst?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.