Skip to content

Commit

Permalink
Added identifier(_:AccessibilityID) convenience modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelHolec committed Nov 21, 2023
1 parent 98b7247 commit b76e0db
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/Orbit/Support/Environment Keys/Identifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public extension View {
/// Binds a view’s identity to the given proxy value.
///
/// This Orbit override adds the custom `IDPreferenceKey` preference and `identifier` environment value on top of native identity.
/// This `identifier` is a necessary property of components that are used in some Orbit components or modifiers.
/// The `identifier` is a required property of components that are used in some Orbit components or modifiers.
func identifier<ID: Hashable>(_ id: ID) -> some View {
self
.environment(\.identifier, id)
Expand All @@ -27,6 +27,16 @@ public extension View {
[IDPreference(id: id, bounds: bounds)]
}
}

/// Binds a view’s identity to the given accessibility identifier, acting both as the `id` and `accessibilityIdentifier` at the same time.
///
/// This Orbit override adds the custom `IDPreferenceKey` preference and `identifier` environment value on top of native identity.
/// The `identifier` is a required property of components that are used in some Orbit components or modifiers.
func identifier(_ accessibilityID: AccessibilityID) -> some View {
self
.identifier(accessibilityID as AnyHashable)
.accessibility(accessibilityID)
}
}

public struct IDPreferenceKey: PreferenceKey {
Expand Down

0 comments on commit b76e0db

Please sign in to comment.