Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUM-4151 [SR] Support background color for Tab Bars #1890

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯👌

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