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

Adds Bundle utility #304

Merged
merged 1 commit into from
Jul 1, 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
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 {
mohssenfathi marked this conversation as resolved.
Show resolved Hide resolved

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