Skip to content

Commit

Permalink
Merge pull request #304 from mohssenfathi/bundle-utility
Browse files Browse the repository at this point in the history
Adds Bundle utility
  • Loading branch information
mohssenfathi authored Jul 1, 2024
2 parents cdb6394 + 60faf70 commit 5d6cf94
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/UberAuth/Button/LoginButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public final class LoginButton: UberButton {
override public var image: UIImage? {
UIImage(
named: "uber_logo_white",
in: .module,
in: .resource(for: LoginButton.self),
compatibleWith: nil
)?.withRenderingMode(.alwaysTemplate)
}
Expand Down Expand Up @@ -145,14 +145,14 @@ public final class LoginButton: UberButton {
case .loggedIn:
return NSLocalizedString(
"Sign Out",
bundle: .module,
bundle: .resource(for: LoginButton.self),
comment: "Login Button Sign Out Description"
)
.uppercased()
case .loggedOut:
return NSLocalizedString(
"Sign In",
bundle: .module,
bundle: .resource(for: LoginButton.self),
comment: "Login Button Sign In Description"
)
.uppercased()
Expand Down
19 changes: 19 additions & 0 deletions Sources/UberAuth/Utilities/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright © Uber Technologies, Inc. All rights reserved.
//


import Foundation

extension Bundle {

static func resource(for targetClass: AnyClass?) -> Bundle {
#if SWIFT_PACKAGE
return .module
#endif
if let targetClass {
return Bundle(for: targetClass)
}
return .main
}
}
6 changes: 3 additions & 3 deletions Sources/UberCore/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ extension UIColor {

static let uberButtonBackground: UIColor = UIColor(
named: "UberButtonBackground",
in: .module,
in: .resource(for: UberButton.self),
compatibleWith: nil
) ?? UIColor.darkText

static let uberButtonHighlightedBackground: UIColor = UIColor(
named: "UberButtonHighlightedBackground",
in: .module,
in: .resource(for: UberButton.self),
compatibleWith: nil
) ?? UIColor.darkText

static let uberButtonForeground: UIColor = UIColor(
named: "UberButtonForeground",
in: .module,
in: .resource(for: UberButton.self),
compatibleWith: nil
) ?? UIColor.lightText
}
19 changes: 19 additions & 0 deletions Sources/UberCore/Utilities/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright © Uber Technologies, Inc. All rights reserved.
//


import Foundation

extension Bundle {

static func resource(for targetClass: AnyClass?) -> Bundle {
#if SWIFT_PACKAGE
return .module
#endif
if let targetClass {
return Bundle(for: targetClass)
}
return .main
}
}
2 changes: 1 addition & 1 deletion Sources/UberRides/RideRequestButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public class RideRequestButton: UberButton_DEPRECATED {

// get image from media directory
private func getImage(name: String) -> UIImage {
let image = UIImage(named: name, in: Bundle.module, compatibleWith: nil)
let image = UIImage(named: name, in: .resource(for: RideRequestButton.self), compatibleWith: nil)
return image!
}
}
Expand Down
19 changes: 19 additions & 0 deletions Sources/UberRides/RidesCore/Utilities/Bundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Copyright © Uber Technologies, Inc. All rights reserved.
//


import Foundation

extension Bundle {

static func resource(for targetClass: AnyClass?) -> Bundle {
#if SWIFT_PACKAGE
return .module
#endif
if let targetClass {
return Bundle(for: targetClass)
}
return .main
}
}

0 comments on commit 5d6cf94

Please sign in to comment.