Skip to content

Commit 43670e9

Browse files
committed
Merge branch 'develop'
2 parents 3be3761 + f32ef93 commit 43670e9

File tree

12 files changed

+138
-27
lines changed

12 files changed

+138
-27
lines changed

Example/MYTableViewIndex.xcodeproj/project.pbxproj

+14-1
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,18 @@
228228
isa = PBXProject;
229229
attributes = {
230230
LastSwiftUpdateCheck = 0720;
231-
LastUpgradeCheck = 0900;
231+
LastUpgradeCheck = 0910;
232232
ORGANIZATIONNAME = "Makarov Yury";
233233
TargetAttributes = {
234234
607FACCF1AFB9204008FA782 = {
235235
CreatedOnToolsVersion = 6.3.1;
236+
DevelopmentTeam = WDCQ6B387N;
236237
LastSwiftMigration = 0900;
238+
ProvisioningStyle = Automatic;
237239
};
238240
607FACE41AFB9204008FA782 = {
239241
CreatedOnToolsVersion = 6.3.1;
242+
DevelopmentTeam = WDCQ6B387N;
240243
LastSwiftMigration = 0800;
241244
TestTargetID = 607FACCF1AFB9204008FA782;
242245
};
@@ -525,12 +528,16 @@
525528
buildSettings = {
526529
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
527530
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
531+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
532+
CODE_SIGN_STYLE = Automatic;
533+
DEVELOPMENT_TEAM = WDCQ6B387N;
528534
INFOPLIST_FILE = MYTableViewIndex/Info.plist;
529535
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
530536
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
531537
MODULE_NAME = ExampleApp;
532538
PRODUCT_BUNDLE_IDENTIFIER = "my.MYTableViewIndex-Example";
533539
PRODUCT_NAME = "$(TARGET_NAME)";
540+
PROVISIONING_PROFILE_SPECIFIER = "";
534541
SWIFT_VERSION = 4.0;
535542
};
536543
name = Debug;
@@ -541,12 +548,16 @@
541548
buildSettings = {
542549
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
543550
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
551+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
552+
CODE_SIGN_STYLE = Automatic;
553+
DEVELOPMENT_TEAM = WDCQ6B387N;
544554
INFOPLIST_FILE = MYTableViewIndex/Info.plist;
545555
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
546556
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
547557
MODULE_NAME = ExampleApp;
548558
PRODUCT_BUNDLE_IDENTIFIER = "my.MYTableViewIndex-Example";
549559
PRODUCT_NAME = "$(TARGET_NAME)";
560+
PROVISIONING_PROFILE_SPECIFIER = "";
550561
SWIFT_VERSION = 4.0;
551562
};
552563
name = Release;
@@ -555,6 +566,7 @@
555566
isa = XCBuildConfiguration;
556567
baseConfigurationReference = 5EEB8E8AC054B8E0F15CA367 /* Pods-MYTableViewIndex_Tests.debug.xcconfig */;
557568
buildSettings = {
569+
DEVELOPMENT_TEAM = WDCQ6B387N;
558570
FRAMEWORK_SEARCH_PATHS = (
559571
"$(SDKROOT)/Developer/Library/Frameworks",
560572
"$(inherited)",
@@ -575,6 +587,7 @@
575587
isa = XCBuildConfiguration;
576588
baseConfigurationReference = 5947C14CE9C89E07B48DE0C1 /* Pods-MYTableViewIndex_Tests.release.xcconfig */;
577589
buildSettings = {
590+
DEVELOPMENT_TEAM = WDCQ6B387N;
578591
FRAMEWORK_SEARCH_PATHS = (
579592
"$(SDKROOT)/Developer/Library/Frameworks",
580593
"$(inherited)",

Example/MYTableViewIndex.xcodeproj/xcshareddata/xcschemes/MYTableViewIndex-Example.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0910"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Example/MYTableViewIndex/CollectionViewController.swift

+12-3
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,21 @@ class CollectionViewController : UICollectionViewController, UICollectionViewDel
6868
if sectionIndex == NSNotFound {
6969
return false
7070
}
71+
guard let collectionView = collectionView else {
72+
return false;
73+
}
7174
let indexPath = IndexPath(row: 0, section: sectionIndex)
72-
guard let attrs = collectionView!.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath) else {
75+
guard let attrs = collectionView.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath) else {
7376
return false
7477
}
75-
let yOffset = min(attrs.frame.origin.y, collectionView!.contentSize.height - collectionView!.frame.height + collectionView!.contentInset.top)
76-
collectionView!.contentOffset = CGPoint(x: 0, y: yOffset - collectionView!.contentInset.top)
78+
var contentInset: UIEdgeInsets
79+
if #available(iOS 11.0, *) {
80+
contentInset = collectionView.adjustedContentInset
81+
} else {
82+
contentInset = collectionView.contentInset
83+
}
84+
let yOffset = min(attrs.frame.origin.y, collectionView.contentSize.height - collectionView.frame.height + contentInset.top)
85+
collectionView.contentOffset = CGPoint(x: 0, y: yOffset - contentInset.top)
7786

7887
return true
7988
}

Example/MYTableViewIndex/Examples.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class LargeFontExample : SearchExample {
150150
override func setupTableIndexController(_ tableIndexController: TableViewIndexController) {
151151
super.setupTableIndexController(tableIndexController)
152152

153-
tableIndexController.tableViewIndex.font = UIFont.boldSystemFont(ofSize: 20.0)
153+
tableIndexController.tableViewIndex.font = UIFont.boldSystemFont(ofSize: 15.0)
154154
}
155155
}
156156

Example/Pods/Pods.xcodeproj/project.pbxproj

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/MYTableViewIndex.xcscheme

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MYTableViewIndex.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'MYTableViewIndex'
3-
s.version = '0.5.0'
3+
s.version = '0.6.0'
44
s.summary = 'A pixel perfect replacement for UITableView section index, written in Swift.'
55

66
s.description = <<-DESC

MYTableViewIndex/Private/BackgroundView.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class BackgroundView : UIView {
2121
}
2222

2323
private func commonInit() {
24-
backgroundColor = UIColor.white.withAlphaComponent(0.9)
24+
if #available(iOS 11.0, *) {} else {
25+
backgroundColor = UIColor.white.withAlphaComponent(0.9)
26+
}
2527
isUserInteractionEnabled = false
2628
}
2729
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// UIScrollView+Helpers.swift
3+
// MYTableViewIndex
4+
//
5+
// Created by Makarov Yury on 02/12/2017.
6+
// Copyright © 2017 Makarov Yury. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIScrollView {
12+
13+
var my_effectiveContentInset: UIEdgeInsets {
14+
get {
15+
if #available(iOS 11.0, *) {
16+
return self.adjustedContentInset
17+
} else {
18+
return self.contentInset
19+
}
20+
}
21+
}
22+
}

MYTableViewIndex/Public/Items/SearchItem.swift

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ open class SearchItem : UIView {
1616
override public init(frame: CGRect) {
1717
super.init(frame: frame)
1818
backgroundColor = UIColor.clear
19+
accessibilityLabel = NSLocalizedString("Search", comment: "Accessibility title for search icon")
1920
}
2021

2122
required public init?(coder aDecoder: NSCoder) {

MYTableViewIndex/Public/TableViewIndex.swift

+60-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ open class TableViewIndex : UIControl {
2222
/// Delegate for the table index object. See TableViewIndexDelegate protocol for details.
2323
@IBOutlet public weak var delegate: TableViewIndexDelegate?
2424

25-
/// Background view is displayed below the index items and can customized with any UIView.
25+
/// Background view is displayed below the index items and can be customized with any UIView.
2626
/// If not set or set to nil, creates a default view which mimics the system index appearance.
2727
public var backgroundView: UIView! {
2828
didSet {
@@ -117,6 +117,11 @@ open class TableViewIndex : UIControl {
117117

118118
isExclusiveTouch = true
119119
isMultipleTouchEnabled = false
120+
isAccessibilityElement = true
121+
accessibilityTraits = UIAccessibilityTraitAdjustable
122+
accessibilityLabel = NSLocalizedString("Table index", comment: "Accessibility title for the section index control")
123+
124+
updateAccessibilityValue()
120125
}
121126

122127
// MARK: - Updates
@@ -155,6 +160,41 @@ open class TableViewIndex : UIControl {
155160
item.applyAttributes(style)
156161
}
157162
}
163+
164+
private func selectIndex(_ index: Int) {
165+
guard index != currentIndex else { return }
166+
167+
currentIndex = index
168+
169+
updateAccessibilityValue()
170+
171+
if let delegate = self.delegate
172+
, delegate.responds(to: #selector(TableViewIndexDelegate.tableViewIndex(_:didSelect:at:))) {
173+
174+
let shouldProduceFeedback = delegate.tableViewIndex!(self, didSelect: items[index], at: index)
175+
if shouldProduceFeedback {
176+
notifyFeedbackGenerator()
177+
}
178+
}
179+
}
180+
181+
private func updateAccessibilityValue() {
182+
guard currentIndex >= 0 && currentIndex < items.count else { return }
183+
184+
let currentItem = items[currentIndex]
185+
186+
let titleText: String
187+
if let labelText = currentItem.accessibilityLabel {
188+
titleText = labelText
189+
} else if let labelText = (currentItem as? UILabel)?.text {
190+
titleText = labelText
191+
} else {
192+
titleText = String.localizedStringWithFormat(NSLocalizedString("Section %d", comment: "Accessibility title for a numbered section"), currentIndex + 1)
193+
}
194+
195+
let selectedText = NSLocalizedString("Selected", comment: "Accessibility title for the selected state")
196+
accessibilityValue = "\(titleText), \(selectedText)"
197+
}
158198

159199
// MARK: - Layout
160200

@@ -236,7 +276,7 @@ open class TableViewIndex : UIControl {
236276
// MARK: - Touches
237277

238278
private var currentTouch: UITouch?
239-
private var currentIndex: Int?
279+
private var currentIndex: Int = 0
240280

241281
override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
242282
if let touch = touches.first , bounds.contains(touch.location(in: self)) {
@@ -284,21 +324,12 @@ open class TableViewIndex : UIControl {
284324
if idx == currentIndex {
285325
return
286326
}
287-
currentIndex = idx
288-
289-
if let delegate = self.delegate
290-
, delegate.responds(to: #selector(TableViewIndexDelegate.tableViewIndex(_:didSelect:at:))) {
291-
292-
let shouldProduceFeedback = delegate.tableViewIndex!(self, didSelect: items[idx], at: idx)
293-
if shouldProduceFeedback {
294-
notifyFeedbackGenerator()
295-
}
296-
}
327+
328+
selectIndex(idx)
297329
}
298330

299331
private func finalizeTouch() {
300332
currentTouch = nil
301-
currentIndex = nil
302333
isHighlighted = false
303334
cleanupFeedbackGenerator()
304335
}
@@ -332,6 +363,22 @@ open class TableViewIndex : UIControl {
332363
feedbackGeneratorInstance = nil
333364
}
334365
}
366+
367+
// MARK: - Accessibility support
368+
369+
open override func accessibilityIncrement() {
370+
let newIndex = currentIndex - 1
371+
if newIndex >= 0 {
372+
selectIndex(newIndex)
373+
}
374+
}
375+
376+
open override func accessibilityDecrement() {
377+
let newIndex = currentIndex + 1
378+
if newIndex < items.count {
379+
selectIndex(newIndex)
380+
}
381+
}
335382
}
336383

337384
// MARK: - Protocols

MYTableViewIndex/Public/TableViewIndexController.swift

+17-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class TableViewIndexController : NSObject {
2222

2323
private enum ObservedKeyPaths: String {
2424
case contentInset
25+
case adjustedContentInset
2526
case bounds
2627
case center
2728
}
@@ -48,9 +49,16 @@ public class TableViewIndexController : NSObject {
4849
guard let scrollView = scrollView else {
4950
return
5051
}
52+
var insetKeypath: String
53+
if #available(iOS 11.0, *) {
54+
insetKeypath = ObservedKeyPaths.adjustedContentInset.rawValue
55+
} else {
56+
insetKeypath = ObservedKeyPaths.contentInset.rawValue
57+
}
58+
5159
let keyPaths = [ObservedKeyPaths.bounds.rawValue,
5260
ObservedKeyPaths.center.rawValue,
53-
ObservedKeyPaths.contentInset.rawValue]
61+
insetKeypath]
5462

5563
observer = KeyValueObserver(object: scrollView, keyPaths: keyPaths, handler: {[weak self] keyPath in
5664
self?.layout()
@@ -85,8 +93,13 @@ public class TableViewIndexController : NSObject {
8593

8694
let convertedFrame = parentView.convert(frame, from: nil)
8795

88-
var inset = scrollView.contentInset
89-
inset.bottom = (scrollView.frame.maxY - convertedFrame.minY)
96+
var safeAreaInsets = UIEdgeInsets()
97+
if #available(iOS 11.0, *) {
98+
safeAreaInsets = parentView.safeAreaInsets
99+
}
100+
101+
var inset = scrollView.my_effectiveContentInset
102+
inset.bottom = max(scrollView.frame.maxY - convertedFrame.minY, safeAreaInsets.bottom)
90103

91104
UIView.animate(withDuration: duration, animations: {
92105
UIView.setAnimationCurve(UIViewAnimationCurve(rawValue: curve)!)
@@ -106,7 +119,7 @@ public class TableViewIndexController : NSObject {
106119
guard let scrollView = scrollView else {
107120
return
108121
}
109-
layout(with: scrollView.contentInset)
122+
layout(with: scrollView.my_effectiveContentInset)
110123
}
111124

112125
private func layout(with inset: UIEdgeInsets) {

0 commit comments

Comments
 (0)