-
Notifications
You must be signed in to change notification settings - Fork 4
/
Accessible.swift
55 lines (45 loc) · 1.59 KB
/
Accessible.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Accessible.swift
// CellViewModel
//
// Created by Anton Poltoratskyi on 02.02.2019.
// Copyright © 2019 Anton Poltoratskyi. All rights reserved.
//
import Foundation
public protocol Accessible {
var accessibilityIdentifier: String? { get }
var accessibilityOptions: AccessibilityDisplayOptions { get }
}
extension Accessible {
public var accessibilityIdentifier: String? {
return nil
}
public var accessibilityOptions: AccessibilityDisplayOptions {
return .none
}
public func accessibilityIdentifier(for indexPath: IndexPath) -> String? {
guard let accessibilityIdentifier = accessibilityIdentifier else {
return nil
}
let options = accessibilityOptions
if options.contains(.section) && options.contains(.row) {
return "\(accessibilityIdentifier)_\(indexPath.section)_\(indexPath.row)"
} else if options.contains(.section) {
return "\(accessibilityIdentifier)_\(indexPath.section)"
} else if options.contains(.row) {
return "\(accessibilityIdentifier)_\(indexPath.row)"
} else {
return accessibilityIdentifier
}
}
public func accessibilityIdentifier(for section: Int) -> String? {
guard let accessibilityIdentifier = accessibilityIdentifier else {
return nil
}
if accessibilityOptions.contains(.section) {
return "\(accessibilityIdentifier)_\(section)"
} else {
return accessibilityIdentifier
}
}
}