Skip to content

Commit 8be36ec

Browse files
authored
Merge pull request #18 from teambition/feature/swift-5
feature: support siwft 5
2 parents 190c28e + d7bbac7 commit 8be36ec

File tree

9 files changed

+82
-99
lines changed

9 files changed

+82
-99
lines changed

DropdownMenu.xcodeproj/project.pbxproj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,24 @@
161161
ACE6DB6B1CF74183005C6667 = {
162162
CreatedOnToolsVersion = 7.3.1;
163163
DevelopmentTeam = 7NLBE99QC4;
164-
LastSwiftMigration = 1000;
164+
LastSwiftMigration = 1020;
165165
ProvisioningStyle = Automatic;
166166
};
167167
ACE6DB751CF74183005C6667 = {
168168
CreatedOnToolsVersion = 7.3.1;
169169
DevelopmentTeam = 7NLBE99QC4;
170+
LastSwiftMigration = 1020;
170171
ProvisioningStyle = Automatic;
171172
};
172173
};
173174
};
174175
buildConfigurationList = ACE6DB661CF74183005C6667 /* Build configuration list for PBXProject "DropdownMenu" */;
175176
compatibilityVersion = "Xcode 3.2";
176-
developmentRegion = English;
177+
developmentRegion = en;
177178
hasScannedForEncodings = 0;
178179
knownRegions = (
179180
en,
181+
Base,
180182
);
181183
mainGroup = ACE6DB621CF74183005C6667;
182184
productRefGroup = ACE6DB6D1CF74183005C6667 /* Products */;
@@ -369,7 +371,7 @@
369371
PRODUCT_NAME = "$(TARGET_NAME)";
370372
SKIP_INSTALL = YES;
371373
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
372-
SWIFT_VERSION = 4.2;
374+
SWIFT_VERSION = 5.0;
373375
};
374376
name = Debug;
375377
};
@@ -390,7 +392,7 @@
390392
PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenu;
391393
PRODUCT_NAME = "$(TARGET_NAME)";
392394
SKIP_INSTALL = YES;
393-
SWIFT_VERSION = 4.2;
395+
SWIFT_VERSION = 5.0;
394396
};
395397
name = Release;
396398
};
@@ -403,7 +405,7 @@
403405
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
404406
PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuTests;
405407
PRODUCT_NAME = "$(TARGET_NAME)";
406-
SWIFT_VERSION = 4.2;
408+
SWIFT_VERSION = 5.0;
407409
};
408410
name = Debug;
409411
};
@@ -416,7 +418,7 @@
416418
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
417419
PRODUCT_BUNDLE_IDENTIFIER = com.teambition.DropdownMenuTests;
418420
PRODUCT_NAME = "$(TARGET_NAME)";
419-
SWIFT_VERSION = 4.2;
421+
SWIFT_VERSION = 5.0;
420422
};
421423
name = Release;
422424
};
Binary file not shown.

DropdownMenu.xcworkspace/xcuserdata/wangwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 5 deletions
This file was deleted.

DropdownMenu.xcworkspace/xcuserdata/zhangxiaolian.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 0 additions & 23 deletions
This file was deleted.

DropdownMenu/DropUpMenu.swift

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,24 @@ public extension DropUpMenuDelegate {
3333
private let screenRect = UIScreen.main.bounds
3434

3535
open class DropUpMenu: UIView {
36-
fileprivate var items: [DropdownItem] = []
37-
fileprivate var selectedRow: Int
38-
open var tableView: UITableView!
39-
fileprivate var barCoverView: UIView!
40-
fileprivate var isShow = false
41-
fileprivate var addedWindow: UIWindow?
42-
fileprivate var windowRootView: UIView?
43-
fileprivate lazy var tapGestureRecognizer: UITapGestureRecognizer = {
36+
private var items: [DropdownItem] = []
37+
private var selectedRow: Int
38+
open lazy var tableView: UITableView = {
39+
let tableView = UITableView(frame: CGRect.zero, style: .grouped)
40+
tableView.estimatedSectionHeaderHeight = 0
41+
tableView.estimatedSectionFooterHeight = 0
42+
return tableView
43+
}()
44+
private lazy var barCoverView: UIView = {
45+
let barCoverView = UIView()
46+
barCoverView.backgroundColor = UIColor.clear
47+
barCoverView.translatesAutoresizingMaskIntoConstraints = false
48+
return barCoverView
49+
}()
50+
private var isShow = false
51+
private var addedWindow: UIWindow?
52+
private var windowRootView: UIView?
53+
private lazy var tapGestureRecognizer: UITapGestureRecognizer = {
4454
return UITapGestureRecognizer(target: self, action: #selector(self.hideMenu))
4555
}()
4656

@@ -86,10 +96,10 @@ open class DropUpMenu: UIView {
8696

8797
clipsToBounds = true
8898
setupGestureView()
89-
initTableView()
99+
setupTableView()
90100
}
91101

92-
fileprivate func setupGestureView() {
102+
private func setupGestureView() {
93103
let gestureView = UIView()
94104
gestureView.backgroundColor = UIColor.clear
95105
addSubview(gestureView)
@@ -102,16 +112,13 @@ open class DropUpMenu: UIView {
102112
gestureView.addGestureRecognizer(tapGestureRecognizer)
103113
}
104114

105-
fileprivate func initTableView() {
106-
tableView = UITableView(frame: CGRect.zero, style: .grouped)
107-
tableView?.delegate = self
108-
tableView?.dataSource = self
109-
tableView.estimatedSectionHeaderHeight = 0
110-
tableView.estimatedSectionFooterHeight = 0
115+
private func setupTableView() {
116+
tableView.delegate = self
117+
tableView.dataSource = self
111118
addSubview(tableView)
112119
}
113120

114-
fileprivate func layoutTableView() {
121+
private func layoutTableView() {
115122
tableViewHeight = CGFloat(items.count) * rowHeight
116123
let maxHeight = UIScreen.main.bounds.height - bottomOffsetY
117124
if tableViewHeight > maxHeight {
@@ -125,7 +132,7 @@ open class DropUpMenu: UIView {
125132
NSLayoutConstraint.activate([NSLayoutConstraint.init(item: tableView, attribute: .right, relatedBy: .equal, toItem: self, attribute: .right, multiplier: 1.0, constant: 0)])
126133
}
127134

128-
fileprivate func setupBottomSeperatorView() {
135+
private func setupBottomSeperatorView() {
129136
let seperatorView = UIView()
130137
seperatorView.backgroundColor = tableViewSeperatorColor
131138
addSubview(seperatorView)
@@ -136,10 +143,7 @@ open class DropUpMenu: UIView {
136143
NSLayoutConstraint.activate([NSLayoutConstraint.init(item: seperatorView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 0.5)])
137144
}
138145

139-
fileprivate func setupBottomCoverView(on view: UIView) {
140-
barCoverView = UIView()
141-
barCoverView.backgroundColor = UIColor.clear
142-
barCoverView.translatesAutoresizingMaskIntoConstraints = false
146+
private func setupBottomCoverView(on view: UIView) {
143147
view.addSubview(barCoverView)
144148
NSLayoutConstraint.activate([NSLayoutConstraint.init(item: barCoverView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1.0, constant: 0)])
145149
NSLayoutConstraint.activate([NSLayoutConstraint.init(item: barCoverView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: bottomOffsetY)])

DropdownMenu/DropdownMenu.swift

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,28 @@ public extension DropdownMenuDelegate {
3333
}
3434

3535
open class DropdownMenu: UIView {
36-
fileprivate weak var navigationController: UINavigationController!
36+
private weak var navigationController: UINavigationController!
3737

38-
fileprivate var sections: [DropdownSection] = []
39-
fileprivate var selectedIndexPath: IndexPath
38+
private var sections: [DropdownSection] = []
39+
private var selectedIndexPath: IndexPath
4040

41-
open var tableView: UITableView!
42-
fileprivate var barCoverView: UIView?
41+
open var tableView: UITableView = {
42+
let tableView = UITableView(frame: CGRect.zero, style: .grouped)
43+
tableView.estimatedSectionFooterHeight = 0
44+
tableView.estimatedSectionHeaderHeight = 0
45+
return tableView
46+
}()
47+
private var barCoverView: UIView?
4348
open var isShow = false
44-
fileprivate var addedWindow: UIWindow?
45-
fileprivate var windowRootView: UIView?
46-
fileprivate var topConstraint: NSLayoutConstraint?
47-
fileprivate var navigationBarCoverViewHeightConstraint: NSLayoutConstraint?
48-
fileprivate var tableViewHeightConstraint: NSLayoutConstraint?
49-
fileprivate let iPhoneXPortraitTopOffset: CGFloat = 88.0
50-
fileprivate let portraitTopOffset: CGFloat = 64.0
51-
fileprivate let landscapeTopOffset: CGFloat = 32.0
52-
fileprivate var topLayoutConstraintConstant: CGFloat {
49+
private var addedWindow: UIWindow?
50+
private var windowRootView: UIView?
51+
private var topConstraint: NSLayoutConstraint?
52+
private var navigationBarCoverViewHeightConstraint: NSLayoutConstraint?
53+
private var tableViewHeightConstraint: NSLayoutConstraint?
54+
private let iPhoneXPortraitTopOffset: CGFloat = 88.0
55+
private let portraitTopOffset: CGFloat = 64.0
56+
private let landscapeTopOffset: CGFloat = 32.0
57+
private var topLayoutConstraintConstant: CGFloat {
5358
var offset: CGFloat = 0
5459
if !navigationController.isNavigationBarHidden {
5560
offset = navigationController.navigationBar.frame.height + navigationController.navigationBar.frame.origin.y
@@ -108,7 +113,7 @@ open class DropdownMenu: UIView {
108113

109114
clipsToBounds = true
110115
setupGestureView()
111-
initTableView()
116+
setupTableView()
112117

113118
NotificationCenter.default.addObserver(self, selector: #selector(self.updateForOrientationChange(_:)), name: UIApplication.willChangeStatusBarOrientationNotification, object: nil)
114119
}
@@ -123,7 +128,7 @@ open class DropdownMenu: UIView {
123128

124129
clipsToBounds = true
125130
setupGestureView()
126-
initTableView()
131+
setupTableView()
127132

128133
NotificationCenter.default.addObserver(self, selector: #selector(self.updateForOrientationChange(_:)), name: UIApplication.willChangeStatusBarOrientationNotification, object: nil)
129134
}
@@ -186,7 +191,7 @@ open class DropdownMenu: UIView {
186191
}
187192
}
188193

189-
fileprivate func setupGestureView() {
194+
private func setupGestureView() {
190195
let gestureView = UIView()
191196
gestureView.backgroundColor = UIColor.clear
192197
addSubview(gestureView)
@@ -199,17 +204,14 @@ open class DropdownMenu: UIView {
199204
gestureView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hideMenu)))
200205
}
201206

202-
fileprivate func initTableView() {
203-
tableView = UITableView(frame: CGRect.zero, style: .grouped)
207+
private func setupTableView() {
204208
tableView.separatorStyle = separatorStyle
205209
tableView.delegate = self
206210
tableView.dataSource = self
207-
tableView.estimatedSectionFooterHeight = 0
208-
tableView.estimatedSectionHeaderHeight = 0
209211
addSubview(tableView)
210212
}
211213

212-
fileprivate func layoutTableView() {
214+
private func layoutTableView() {
213215
tableView.translatesAutoresizingMaskIntoConstraints = false
214216

215217
updateTableViewHeight()
@@ -222,7 +224,7 @@ open class DropdownMenu: UIView {
222224
self.tableViewHeightConstraint = tableViewHeightConstraint
223225
}
224226

225-
fileprivate func updateTableViewHeight() {
227+
private func updateTableViewHeight() {
226228
tableViewHeight = tableviewHeight()
227229

228230
let maxHeight = navigationController.view.frame.height - topLayoutConstraintConstant - defaultBottonMargin
@@ -236,7 +238,7 @@ open class DropdownMenu: UIView {
236238
}
237239
}
238240

239-
fileprivate func updateForSectionsChange(_ animations: (() -> Void)? = nil) {
241+
private func updateForSectionsChange(_ animations: (() -> Void)? = nil) {
240242
updateTableViewHeight()
241243
tableViewHeightConstraint?.constant = tableViewHeight
242244
UIView.animate(withDuration: 0.3) { [weak self] in
@@ -248,7 +250,7 @@ open class DropdownMenu: UIView {
248250
}
249251
}
250252

251-
fileprivate func setupTopSeperatorView() {
253+
private func setupTopSeperatorView() {
252254
let seperatorView = UIView()
253255
seperatorView.backgroundColor = tableViewSeperatorColor
254256
addSubview(seperatorView)
@@ -259,7 +261,7 @@ open class DropdownMenu: UIView {
259261
NSLayoutConstraint.activate([NSLayoutConstraint.init(item: seperatorView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 0.5)])
260262
}
261263

262-
fileprivate func setupNavigationBarCoverView(on view: UIView) {
264+
private func setupNavigationBarCoverView(on view: UIView) {
263265
barCoverView = UIView()
264266
barCoverView?.backgroundColor = UIColor.clear
265267
view.addSubview(barCoverView!)
@@ -273,7 +275,7 @@ open class DropdownMenu: UIView {
273275
barCoverView?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hideMenu)))
274276
}
275277

276-
fileprivate func tableviewHeight() -> CGFloat {
278+
private func tableviewHeight() -> CGFloat {
277279
var height: CGFloat = 0
278280
sections.enumerated().forEach {
279281
if displaySectionHeader {

DropdownMenu/SectionHeader.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
//
88

99
open class SectionHeader: UIView {
10-
var titleLabel: UILabel!
10+
var titleLabel: UILabel = {
11+
let titleLabel = UILabel()
12+
titleLabel.translatesAutoresizingMaskIntoConstraints = false
13+
return titleLabel
14+
}()
15+
1116
var style: SectionHeaderStyle = SectionHeaderStyle()
1217

1318
convenience init(style: SectionHeaderStyle) {
@@ -25,8 +30,6 @@ open class SectionHeader: UIView {
2530
}
2631

2732
func commonInit() {
28-
titleLabel = UILabel()
29-
titleLabel.translatesAutoresizingMaskIntoConstraints = false
3033
titleLabel.font = style.font
3134
titleLabel.textColor = style.textColor
3235
backgroundColor = style.backgroundColor

0 commit comments

Comments
 (0)