MultiPicker icon indicating copy to clipboard operation
MultiPicker copied to clipboard

The "none" text representation for optional selections should be configurable.

Open toastersocks opened this issue 1 year ago • 3 comments

Situation

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.

Solution

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.

Dilemma

I'm not sure if these should be init parameters, or view modifiers though.

Init approach

For

  • This is view content so seems more appropriate to pass into the init

Against

I'm hesitant to add more parameters to the init because:

  • It strays farther from SwiftUI.Picker API
  • and because the init already has two other view parameters in the init (the Label and content views), and the init might get pretty unwieldy with all these ViewBuilder closure parameters.

View Modifier approach

For

  • Don't have to change the init API
  • Can apply the configuration to multiple MultiPickers

Against

But on the other hand:

  • Creating more view modifiers that are only applicable to MultiPicker
  • view modifiers that take view content seems like not purely configuration

toastersocks avatar Mar 08 '24 02:03 toastersocks

This should be generalized as a choice representation style, .custom. that takes a closure that is passed a collection of choices, then the consumer can decide how they want that represented. Whether it's one, none, or multiple, they can do whatever they want.

toastersocks avatar May 06 '24 05:05 toastersocks

Is this related to the issue I met that my app spams the following error after using this Swift Package?:

image

If so, please use Text(verbatim:) instead wherever appropriate.

ShikiSuen avatar Sep 21 '24 19:09 ShikiSuen

@ShikiSuen thanks for reporting this. It looks like you're using NSShowNonLocalizedStrings. Using Text(verbatim:) would prevent library consumers from being able to localize this particular string. To get rid of the message, turn off NSShowNonLocalizedStrings, or add an entry for "(None)" in your Localized.strings or Localized.stringdict file. In the meantime, I'll see if there's a better way for me to do this than what I'm currently doing. Thanks

toastersocks avatar Sep 22 '24 02:09 toastersocks