Last active
January 27, 2022 10:24
-
-
Save bocato/32829b18094533e44fc84290923ce143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct AccessibilityIdentifier: ExpressibleByStringLiteral { // This should be inside you UI Module | |
public let key: String | |
public init(stringLiteral key: String) { | |
self.key = key | |
} | |
} | |
public extension View { // This should be inside you UI Module | |
@ViewBuilder | |
func setAccessibilityIdentifier(_ identifier: AccessibilityIdentifier) -> some View { | |
if #available(iOS 14.0, *) { | |
self.accessibilityIdentifier(identifier.key) | |
} else { | |
self | |
} | |
} | |
} | |
// Then | |
extension AccessibilityIdentifier { | |
static let someIdentifier: Self = "i_am_an_identifier" | |
} | |
// Then | |
struct SomeView: View { | |
var body: some View { | |
Text("Identified") | |
.setAccessibilityIdentifier(.someIdentifier) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment