Add View.tag API support #584
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements the
View.tag(_:includeOptional:)API to enable tagging views for selection in containers likePickerandTabView.Closes #583
Changes
Adds
Sources/OpenSwiftUICore/View/Tag.swiftwith complete implementation:Public API
View.tag(_:includeOptional:): Sets unique tag values on views for identification in selectable containersView._untagged(): Marks views as auxiliary content that should not be wrapped by containersInternal Components
TagValueTraitKey<V>: Trait key for storing tag values with support for both tagged and untagged statesIsAuxiliaryContentTraitKey: Trait key for marking auxiliary/untagged contentViewTraitCollectionextensions: Methods for reading and writing tag valuestagValue(for:)- Get tag value regardless of auxiliary statustag(for:)- Get tag value (returns nil for auxiliary content)setTagIfUnset(for:value:)- Set tag only if not already setsetTag(for:value:)- Unconditionally set tag valueBindingextensions: Tag-based binding projectionsselecting(_:)- Create boolean binding for tag selectionprojectingTagIndex(viewList:)- Project binding to tag index in view listTagIndexProjection: Internal projection class for efficient tag-to-index mappingAPI Overview
Example Usage
Implementation Details
includeOptionalparameter