Skip to content

Commit

Permalink
Merge pull request #1890 from DataDog/mariedm/feat/RUM-4151
Browse files Browse the repository at this point in the history
RUM-4151 [SR] Support background color for Tab Bars
  • Loading branch information
mariedm authored Jun 11, 2024
2 parents cbda76b + 5778c80 commit f33ccb7
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public enum Fixture: CaseIterable {
case navigationBarDefaultNonTranslucentBarTint
case navigationBarDefaultTranslucentBackground
case navigationBarDefaultNonTranslucentBackground
case tabbar
case embeddedTabbar
case embeddedTabbarUnselectedTintColor

public func instantiateViewController() -> UIViewController {
switch self {
Expand Down Expand Up @@ -108,6 +111,12 @@ public enum Fixture: CaseIterable {
return vc
case .navigationBarDefaultNonTranslucentBackground:
return UIStoryboard.navigationBars.instantiateViewController(withIdentifier: "Default_Non_Translucent_Background_Navbar")
case .tabbar:
return UIStoryboard.tabbars.instantiateViewController(withIdentifier: "Tabbars")
case .embeddedTabbar:
return UIStoryboard.tabbars.instantiateViewController(withIdentifier: "EmbeddedTabbar")
case .embeddedTabbarUnselectedTintColor:
return UIStoryboard.tabbars.instantiateViewController(withIdentifier: "EmbeddedTabbarUnselectedTintColor")
}
}
}
Expand All @@ -119,4 +128,5 @@ internal extension UIStoryboard {
static var images: UIStoryboard { UIStoryboard(name: "Images", bundle: .module) }
static var unsupportedViews: UIStoryboard { UIStoryboard(name: "UnsupportedViews", bundle: .module) }
static var navigationBars: UIStoryboard { UIStoryboard(name: "NavigationBars", bundle: .module) }
static var tabbars: UIStoryboard { UIStoryboard(name: "Tabbars", bundle: .module) }
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/

import UIKit

public class TabbarViewControllers: UIViewController {

@IBOutlet var tabbars: [UITabBar]!

public override func viewDidLoad() {
for tabbar in tabbars {
// Select the first tabbar's item
// so we can see both a selected and unselected item
tabbar.selectedItem = tabbar.items?.first
}
}
}

public class EmbeddedTabbarController: UITabBarController {
public override func viewDidLoad() {
tabBar.unselectedItemTintColor = nil
}
}

public class EmbeddedTabbarUnselectedTintColorController: UITabBarController {
public override func viewDidLoad() {
tabBar.unselectedItemTintColor = UIColor.green
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ internal extension Fixture {
return "Embedded Navigation Bar Default + Translucent + Background color"
case .navigationBarDefaultNonTranslucentBackground:
return "Embedded Navigation Bar Default + Non Translucent + Background color"
case .tabbar:
return "Tab Bars"
case .embeddedTabbar:
return "Embedded Tab Bar"
case .embeddedTabbarUnselectedTintColor:
return "Embedded Tab Bar Unselected Tint Color"
}
}

var slug: String {
self.menuItemTitle.lowercased().replacingOccurrences(of: " ", with: "")
}
}

internal class MenuViewController: UITableViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ final class SRSnapshotTests: SnapshotTestCase {

try forPrivacyModes([.allow, .mask]) { privacyMode in
let image = try takeSnapshot(with: privacyMode)
let fileNamePrefix = fixture.menuItemTitle.lowercased().replacingOccurrences(of: " ", with: "")
let fileNamePrefix = fixture.slug
DDAssertSnapshotTest(
newImage: image,
snapshotLocation: .folder(named: snapshotsFolderPath, fileNameSuffix: "-\(fileNamePrefix)-\(privacyMode)-privacy"),
Expand All @@ -306,4 +306,45 @@ final class SRSnapshotTests: SnapshotTestCase {
}
}

func testTabBars() throws {

// - Static Tab Bars
show(fixture: .tabbar)

try forPrivacyModes([.allow, .mask]) { privacyMode in
let image = try takeSnapshot(with: privacyMode)
DDAssertSnapshotTest(
newImage: image,
snapshotLocation: .folder(named: snapshotsFolderPath, fileNameSuffix: "-\(privacyMode)-privacy"),
record: recordingMode
)
}

// - Embedded Tab Bar
show(fixture: .embeddedTabbar)

try forPrivacyModes([.allow, .mask]) { privacyMode in
let image = try takeSnapshot(with: privacyMode)
let fileNamePrefix = Fixture.embeddedTabbar.slug
DDAssertSnapshotTest(
newImage: image,
snapshotLocation: .folder(named: snapshotsFolderPath, fileNameSuffix: "-\(fileNamePrefix)-\(privacyMode)-privacy"),
record: recordingMode
)
}

// - Embedded Tab Bar, with unselected item tint color
show(fixture: .embeddedTabbarUnselectedTintColor)

try forPrivacyModes([.allow, .mask]) { privacyMode in
let image = try takeSnapshot(with: privacyMode)
let fileNamePrefix = Fixture.embeddedTabbarUnselectedTintColor.slug
DDAssertSnapshotTest(
newImage: image,
snapshotLocation: .folder(named: snapshotsFolderPath, fileNameSuffix: "-\(fileNamePrefix)-\(privacyMode)-privacy"),
record: recordingMode
)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"c8db9a89ac040c3733ec239bf92a2bfd6253dee4"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"72d50780fb4df2e058dad0e8953e439097fd3eaa"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"a15b968196c3fd0a268bd3e82a37fef10b31009f"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"a0cf5709cf5cb508728fd1d2ad74f6afd2153a27"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"dccf7efc3a8379f8cf0d1ee4d63e00a30206bc04"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"ace6b7b1f9db81e24d7d19d3fa3652e7b6f290dc"}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ internal struct UITabBarRecorder: NodeRecorder {
}

private func inferOccupiedFrame(of tabBar: UITabBar, in context: ViewTreeRecordingContext) -> CGRect {
// TODO: RUMM-2791 Enhance appearance of `UITabBar` and `UINavigationBar` in SR
var occupiedFrame = tabBar.frame
for subview in tabBar.subviews {
let subviewFrame = subview.convert(subview.bounds, to: context.coordinateSpace)
Expand All @@ -35,7 +34,10 @@ internal struct UITabBarRecorder: NodeRecorder {
}

private func inferColor(of tabBar: UITabBar) -> CGColor {
// TODO: RUMM-2791 Enhance appearance of `UITabBar` and `UINavigationBar` in SR
if let color = tabBar.backgroundColor {
return color.cgColor
}

if #available(iOS 13.0, *) {
switch UITraitCollection.current.userInterfaceStyle {
case .light:
Expand Down

0 comments on commit f33ccb7

Please sign in to comment.