Skip to content

Commit e438bf9

Browse files
authored
Merge pull request #2 from mapierce/feature/ios-13
iOS 13 updates
2 parents df996a5 + 5a396c5 commit e438bf9

5 files changed

Lines changed: 66 additions & 19 deletions

File tree

β€ŽExample/Tests/WaveTabBarPresenterUnitTests.swiftβ€Ž

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ final class WaveTabBarPresenterUnitTests: XCTestCase {
4646
XCTAssertFalse(view.setupCurveCalled)
4747
XCTAssertFalse(view.setupCircleCalled)
4848
XCTAssertFalse(view.setupImageViewCalled)
49-
XCTAssertFalse(view.setupTabBarStylingCalled)
49+
XCTAssertFalse(view.setupTabBarColoringCalled)
50+
XCTAssertFalse(view.setupTabBarBackgroundCalled)
5051
presenter.viewDidAppear(portrait: true)
5152
XCTAssertTrue(view.showTabBarCalled)
5253
XCTAssertTrue(view.setupTabBarTagsCalled)
5354
XCTAssertTrue(view.setupCurveCalled)
5455
XCTAssertTrue(view.setupCircleCalled)
5556
XCTAssertTrue(view.setupImageViewCalled)
56-
XCTAssertTrue(view.setupTabBarStylingCalled)
57+
XCTAssertTrue(view.setupTabBarColoringCalled)
58+
XCTAssertTrue(view.setupTabBarBackgroundCalled)
5759
}
5860

5961
func testViewDidRotate() {
@@ -76,6 +78,12 @@ final class WaveTabBarPresenterUnitTests: XCTestCase {
7678
XCTAssertTrue(view.moveCircleCalled)
7779
}
7880

81+
func testViewWillLayoutSubviews() {
82+
XCTAssertFalse(view.setupTabBarColoringCalled)
83+
presenter.viewWillLayoutSubviews()
84+
XCTAssertTrue(view.setupTabBarColoringCalled)
85+
}
86+
7987
func testMoveCircleCompleteDown() {
8088
XCTAssertFalse(view.updateImageViewCalled)
8189
XCTAssertFalse(view.updateCircleCenterCalled)
@@ -106,7 +114,8 @@ private class WaveTabBarControllerMock: WaveTabBarProtocol {
106114
var setupCurveCalled = false
107115
var setupCircleCalled = false
108116
var updateCircleSizeCalled = false
109-
var setupTabBarStylingCalled = false
117+
var setupTabBarColoringCalled = false
118+
var setupTabBarBackgroundCalled = false
110119
var setupImageViewCalled = false
111120
var updateImageViewSizeCalled = false
112121
var updateImageViewCalled = false
@@ -138,8 +147,12 @@ private class WaveTabBarControllerMock: WaveTabBarProtocol {
138147
updateCircleSizeCalled = true
139148
}
140149

141-
func setupTabBarStyling() {
142-
setupTabBarStylingCalled = true
150+
func setupTabBarColoring() {
151+
setupTabBarColoringCalled = true
152+
}
153+
154+
func setupTabBarBackground() {
155+
setupTabBarBackgroundCalled = true
143156
}
144157

145158
func setupImageView(_ center: Float) {

β€ŽWaveTab/Classes/Implementation/Wave Tab Bar Controller/WaveTabBarController.swiftβ€Ž

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ open class WaveTabBarController: UITabBarController, WaveTabBarProtocol {
6969
}
7070
}
7171

72+
open override func viewWillLayoutSubviews() {
73+
presenter.viewWillLayoutSubviews()
74+
}
75+
7276
// MARK: - WaveTabBarProtocol functions
7377

7478
func showTabBar(_ show: Bool, animated: Bool, over duration: TimeInterval) {
@@ -110,23 +114,34 @@ open class WaveTabBarController: UITabBarController, WaveTabBarProtocol {
110114
circle.layer.cornerRadius = CGFloat(radius) / 2
111115
}
112116

113-
func setupTabBarStyling() {
117+
func setupTabBarColoring() {
114118
let backgroundColor: UIColor
115-
if let color = tabBar.barTintColor {
116-
backgroundColor = color
117-
} else {
118-
switch tabBar.barStyle {
119-
case .black, .blackTranslucent: backgroundColor = Constants.blackBackgroundColor
120-
case .default: backgroundColor = Constants.whiteBackgroundColor
121-
@unknown default: backgroundColor = Constants.whiteBackgroundColor
119+
if #available(iOS 13.0, *) {
120+
switch traitCollection.userInterfaceStyle {
121+
case .light: backgroundColor = Constants.whiteBackgroundColor
122+
case .dark: backgroundColor = Constants.blackBackgroundColor
123+
case .unspecified: backgroundColor = getColorFromTabBarStyle()
124+
@unknown default: backgroundColor = getColorFromTabBarStyle()
122125
}
126+
} else {
127+
backgroundColor = getColorFromTabBarStyle()
123128
}
124129
waveSubLayer.fillColor = backgroundColor.cgColor
125130
circle?.backgroundColor = backgroundColor
126-
tabBar.backgroundColor = .clear
127-
tabBar.tintColor = UIColor.clear
128-
tabBar.backgroundImage = UIImage()
129-
tabBar.shadowImage = UIImage()
131+
}
132+
133+
func setupTabBarBackground() {
134+
tabBar.tintColor = .clear
135+
if #available(iOS 13.0, *) {
136+
let barAppearance = UIBarAppearance()
137+
barAppearance.configureWithTransparentBackground()
138+
let tabBarAppearance = UITabBarAppearance(barAppearance: barAppearance)
139+
tabBar.standardAppearance = tabBarAppearance
140+
} else {
141+
tabBar.backgroundColor = .clear
142+
tabBar.backgroundImage = UIImage()
143+
tabBar.shadowImage = UIImage()
144+
}
130145
}
131146

132147
func setupImageView(_ center: Float) {
@@ -192,4 +207,14 @@ open class WaveTabBarController: UITabBarController, WaveTabBarProtocol {
192207
circle.alpha = down ? Constants.emptyAlpha : Constants.fullAlpha
193208
}
194209

210+
// MARK: - Private functions
211+
212+
private func getColorFromTabBarStyle() -> UIColor {
213+
switch tabBar.barStyle {
214+
case .black, .blackTranslucent: return Constants.blackBackgroundColor
215+
case .default: return Constants.whiteBackgroundColor
216+
@unknown default: return Constants.whiteBackgroundColor
217+
}
218+
}
219+
195220
}

β€ŽWaveTab/Classes/Implementation/Wave Tab Bar Controller/WaveTabBarPresenter.swiftβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ protocol WaveTabBarPresenter: class {
1919

2020
func tabBarDidSelectItem(with tag: Int)
2121

22+
func viewWillLayoutSubviews()
23+
2224
func moveCircleComplete(down movingDown: Bool)
2325

2426
}

β€ŽWaveTab/Classes/Implementation/Wave Tab Bar Controller/WaveTabBarPresenterBase.swiftβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class WaveTabBarPresenterBase: WaveTabBarPresenter {
4444
view.setupCurve(isPortrait ? Constants.bigRadius : Constants.smallRadius)
4545
view.setupCircle(isPortrait ? Constants.bigCircle : Constants.smallCircle)
4646
view.setupImageView((isPortrait ? Constants.bigCircle : Constants.smallCircle) / 2)
47-
view.setupTabBarStyling()
47+
view.setupTabBarColoring()
48+
view.setupTabBarBackground()
4849
}
4950

5051
func viewDidRotate(portrait portraitOrientation: Bool, at index: Int) {
@@ -68,6 +69,10 @@ class WaveTabBarPresenterBase: WaveTabBarPresenter {
6869
down: true)
6970
}
7071

72+
func viewWillLayoutSubviews() {
73+
view.setupTabBarColoring()
74+
}
75+
7176
func moveCircleComplete(down movingDown: Bool) {
7277
view.updateImageView()
7378
view.updateCircleCenter()

β€ŽWaveTab/Classes/Implementation/Wave Tab Bar Controller/WaveTabBarProtocol.swiftβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ protocol WaveTabBarProtocol: class {
2121

2222
func updateCircleSize(_ radius: Float)
2323

24-
func setupTabBarStyling()
24+
func setupTabBarColoring()
25+
26+
func setupTabBarBackground()
2527

2628
func setupImageView(_ center: Float)
2729

0 commit comments

Comments
Β (0)