From 61f0172f48647168d8b2660062027d38ba06e382 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Thu, 11 Feb 2021 15:13:30 -0800 Subject: [PATCH] Use normal UIImages instead of custom LazyImages (#654) This enables dynamic images needed to support dark mode and system symbols --- App/ViewController.swift | 20 ++--- Lock.xcodeproj/project.pbxproj | 10 +-- Lock/AuthButton.swift | 2 +- Lock/AuthCollectionView.swift | 2 +- Lock/AuthStyle.swift | 84 +++++++++---------- Lock/CustomTextField.swift | 4 +- Lock/DatabaseModeSwitcher.swift | 18 ++-- Lock/DatabaseOnlyView.swift | 4 +- Lock/HeaderView.swift | 14 ++-- Lock/InfoBarView.swift | 2 +- Lock/InputField.swift | 20 ++--- Lock/InternationalPhoneInputView.swift | 4 +- Lock/LazyImage.swift | 59 ------------- Lock/Lock.swift | 2 +- Lock/LockViewController.swift | 2 +- Lock/PasswordlessView.swift | 2 +- Lock/PolicyView.swift | 6 +- Lock/PrimaryButton.swift | 4 +- Lock/Resources.swift | 19 ++++- Lock/Style.swift | 12 +-- Lock/UnrecoverableErrorView.swift | 2 +- .../Interactors/DatabaseInteractorSpec.swift | 4 +- LockTests/LazyImageSpec.swift | 64 -------------- LockTests/LockSpec.swift | 6 +- LockTests/Models/AuthStyleSpec.swift | 11 +-- .../Presenters/DatabasePresenterSpec.swift | 2 +- LockTests/StyleSpec.swift | 6 +- README.md | 8 +- 28 files changed, 136 insertions(+), 257 deletions(-) delete mode 100644 Lock/LazyImage.swift delete mode 100644 LockTests/LazyImageSpec.swift diff --git a/App/ViewController.swift b/App/ViewController.swift index b052acd51..727ec8103 100644 --- a/App/ViewController.swift +++ b/App/ViewController.swift @@ -56,7 +56,7 @@ class ViewController: UIViewController { $0.oauth2["slack"] = AuthStyle( name: "Slack", color: UIColor ( red: 0.4118, green: 0.8078, blue: 0.6588, alpha: 1.0 ), - withImage: LazyImage(name: "ic_slack") + withImage: UIImage(named: "ic_slack") ) } }, @@ -204,15 +204,15 @@ func applyDefaultOptions(_ options: inout OptionBuildable) { if #available(iOS 10, *) { options.customSignupFields = [ - CustomTextField(name: "given_name", placeholder: "First Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle), contentType: .givenName), - CustomTextField(name: "family_name", placeholder: "Last Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle), contentType: .familyName), - CustomTextField(name: "nickname", placeholder: "Nick Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle), contentType: .nickname) + CustomTextField(name: "given_name", placeholder: "First Name", icon: UIImage(named: "ic_person", in: Lock.bundle), contentType: .givenName), + CustomTextField(name: "family_name", placeholder: "Last Name", icon: UIImage(named: "ic_person", in: Lock.bundle), contentType: .familyName), + CustomTextField(name: "nickname", placeholder: "Nick Name", icon: UIImage(named: "ic_person", in: Lock.bundle), contentType: .nickname) ] } else { options.customSignupFields = [ - CustomTextField(name: "given_name", placeholder: "First Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle)), - CustomTextField(name: "family_name", placeholder: "Last Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle)), - CustomTextField(name: "nickname", placeholder: "Nick Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle)) + CustomTextField(name: "given_name", placeholder: "First Name", icon: UIImage(named: "ic_person", in: Lock.bundle)), + CustomTextField(name: "family_name", placeholder: "Last Name", icon: UIImage(named: "ic_person", in: Lock.bundle)), + CustomTextField(name: "nickname", placeholder: "Nick Name", icon: UIImage(named: "ic_person", in: Lock.bundle)) ] } } @@ -232,9 +232,9 @@ func applyPhantomStyle(_ style: inout Style) { // Header style.title = "Phantom Inc." style.headerBlur = .extraLight - style.logo = LazyImage(name: "icn_phantom") - style.headerCloseIcon = LazyImage(name: "icn_phantom_exit") - style.headerBackIcon = LazyImage(name: "icn_phantom_back") + style.logo = UIImage(named: "icn_phantom") + style.headerCloseIcon = UIImage(named: "icn_phantom_exit") + style.headerBackIcon = UIImage(named: "icn_phantom_back") style.primaryColor = UIColor ( red: 0.6784, green: 0.5412, blue: 0.7333, alpha: 1.0 ) // Social diff --git a/Lock.xcodeproj/project.pbxproj b/Lock.xcodeproj/project.pbxproj index 76adaed2a..545bbf1e6 100644 --- a/Lock.xcodeproj/project.pbxproj +++ b/Lock.xcodeproj/project.pbxproj @@ -124,8 +124,6 @@ 5F814FD71D1A72A6003670A4 /* OHHTTPStubs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F814FD31D1A7294003670A4 /* OHHTTPStubs.framework */; }; 5F9231D51D5B6C5E00D92580 /* AuthCollectionViewSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F9231D41D5B6C5E00D92580 /* AuthCollectionViewSpec.swift */; }; 5F92C68D1D50E47100CCE6C0 /* AuthStyleSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F92C68C1D50E47100CCE6C0 /* AuthStyleSpec.swift */; }; - 5F92C68F1D50EAC200CCE6C0 /* LazyImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F92C68E1D50EAC200CCE6C0 /* LazyImage.swift */; }; - 5F92C6911D510AFE00CCE6C0 /* LazyImageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F92C6901D510AFE00CCE6C0 /* LazyImageSpec.swift */; }; 5F99AA761D1A7FA100D27842 /* Auth0.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F814FD21D1A7294003670A4 /* Auth0.framework */; }; 5F99AA7A1D1B031500D27842 /* Lock.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5F99AA791D1B031500D27842 /* Lock.xcassets */; }; 5F99AA821D1B0A3900D27842 /* i18n.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F99AA811D1B0A3900D27842 /* i18n.swift */; }; @@ -363,8 +361,6 @@ 5F9231D41D5B6C5E00D92580 /* AuthCollectionViewSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthCollectionViewSpec.swift; sourceTree = ""; }; 5F92C68A1D4FE90F00CCE6C0 /* Auth0OAuth2InteractorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Auth0OAuth2InteractorSpec.swift; sourceTree = ""; }; 5F92C68C1D50E47100CCE6C0 /* AuthStyleSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AuthStyleSpec.swift; sourceTree = ""; }; - 5F92C68E1D50EAC200CCE6C0 /* LazyImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LazyImage.swift; path = Lock/LazyImage.swift; sourceTree = SOURCE_ROOT; }; - 5F92C6901D510AFE00CCE6C0 /* LazyImageSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LazyImageSpec.swift; sourceTree = ""; }; 5F99AA791D1B031500D27842 /* Lock.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Lock.xcassets; sourceTree = ""; }; 5F99AA811D1B0A3900D27842 /* i18n.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = i18n.swift; path = Lock/i18n.swift; sourceTree = SOURCE_ROOT; }; 5F99AA831D1B0BCE00D27842 /* Lock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Lock.swift; sourceTree = ""; }; @@ -682,7 +678,6 @@ 5FBE5CC31D3E67320038536D /* Validators.swift */, 5F99AA811D1B0A3900D27842 /* i18n.swift */, 5FDC876C1D46DAF200D28596 /* Queue.swift */, - 5F92C68E1D50EAC200CCE6C0 /* LazyImage.swift */, 5F1456591D5130E80085DF9C /* Colors.swift */, 5F390E861D638A6D00FC549C /* Logger.swift */, 5FF0B2271E1726C400A73257 /* CredentialAuth.swift */, @@ -818,7 +813,6 @@ 5FA2504F1D48E2A200C544FA /* OptionsSpec.swift */, 5B1FD96E1E4E2E670055C1AC /* PasswordlessActivitySpec.swift */, 5FA250511D48F08200C544FA /* LockSpec.swift */, - 5F92C6901D510AFE00CCE6C0 /* LazyImageSpec.swift */, 5F390E8C1D63B99300FC549C /* LoggerSpec.swift */, 5B0CF2DB1DE9B3D300F82BF4 /* Validators */, 5B0CF2DA1DE9B3C400F82BF4 /* Errors */, @@ -1221,7 +1215,6 @@ 5F70F1E11D790500004698DA /* Connections.swift in Sources */, 5B568F821E4B6506004B3D98 /* PasswordlessAuthenticatableError.swift in Sources */, 5B3440C51E7C09A1009F8BF7 /* PasswordlessRouter.swift in Sources */, - 5F92C68F1D50EAC200CCE6C0 /* LazyImage.swift in Sources */, 5F2496BA1D665AE900A1C6E2 /* CredentialAuthError.swift in Sources */, 5B9A54461E4B2CB4004B5454 /* PasswordlessAuthenticatable.swift in Sources */, 5B55F3CB1E242A2E00B75CF5 /* UnrecoverableErrorPresenter.swift in Sources */, @@ -1300,7 +1293,6 @@ 5FBE5CC81D3EA0EA0038536D /* Mocks.swift in Sources */, 5B3874D41E97C13D00244326 /* CountryCodesSpec.swift in Sources */, 5F57DFCE1D4FBE5A00C54DA8 /* AuthPresenterSpec.swift in Sources */, - 5F92C6911D510AFE00CCE6C0 /* LazyImageSpec.swift in Sources */, 5BCED4C71DD1FEAA00E2CE8A /* EnterpriseDomainPresenterSpec.swift in Sources */, 5B0CF2D91DE9B1DB00F82BF4 /* CredentialAuthErrorSpec.swift in Sources */, 5FF0B22A1E1864FE00A73257 /* StyleSpec.swift in Sources */, @@ -1514,6 +1506,7 @@ SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_WORKSPACE = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1568,6 +1561,7 @@ SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; + VALIDATE_WORKSPACE = YES; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; diff --git a/Lock/AuthButton.swift b/Lock/AuthButton.swift index ef0aafbd9..76472dce9 100644 --- a/Lock/AuthButton.swift +++ b/Lock/AuthButton.swift @@ -153,7 +153,7 @@ public class AuthButton: UIView { dimension(dimension: button.heightAnchor, greaterThanOrEqual: 50) button.translatesAutoresizingMaskIntoConstraints = false - iconView.image = self.icon ?? image(named: "ic_auth_auth0", compatibleWithTraitCollection: self.traitCollection) + iconView.image = self.icon ?? UIImage(named: "ic_auth_auth0", in: bundleForLock(), compatibleWith: self.traitCollection) iconView.contentMode = .center iconView.tintColor = self.titleColor diff --git a/Lock/AuthCollectionView.swift b/Lock/AuthCollectionView.swift index 72feb3f31..c61e84790 100644 --- a/Lock/AuthCollectionView.swift +++ b/Lock/AuthCollectionView.swift @@ -149,7 +149,7 @@ func oauth2Buttons(forConnections connections: [OAuth2Connection], customStyle: button.highlightedColor = style.highlightedColor button.borderColor = style.borderColor button.titleColor = style.foregroundColor - button.icon = style.image.image(compatibleWithTraits: button.traitCollection) + button.icon = style.image button.onPress = { _ in onAction(connection.name) } diff --git a/Lock/AuthStyle.swift b/Lock/AuthStyle.swift index f3f7465c1..df7c2ac11 100644 --- a/Lock/AuthStyle.swift +++ b/Lock/AuthStyle.swift @@ -27,7 +27,7 @@ public struct AuthStyle { /// Name that will be used for titles. e.g. 'Login with Auth0' let name: String - let image: LazyImage + let image: UIImage? let foregroundColor: UIColor let normalColor: UIColor let highlightedColor: UIColor @@ -53,7 +53,7 @@ public struct AuthStyle { - returns: a new style */ - public init(name: String, color: UIColor = UIColor.a0_orange, foregroundColor: UIColor = .white, withImage image: LazyImage = LazyImage(name: "ic_auth_auth0", bundle: bundleForLock())) { + public init(name: String, color: UIColor = UIColor.a0_orange, foregroundColor: UIColor = .white, withImage image: UIImage? = UIImage(named: "ic_auth_auth0", in: bundleForLock())) { self.init(name: name, normalColor: color, highlightedColor: color.a0_darker(0.3), foregroundColor: foregroundColor, withImage: image) } @@ -68,7 +68,7 @@ public struct AuthStyle { - returns: a new style */ - public init(name: String, normalColor: UIColor, highlightedColor: UIColor, foregroundColor: UIColor, withImage image: LazyImage) { + public init(name: String, normalColor: UIColor, highlightedColor: UIColor, foregroundColor: UIColor, withImage image: UIImage?) { self.name = name self.normalColor = normalColor self.highlightedColor = highlightedColor @@ -93,7 +93,7 @@ public struct AuthStyle { color: UIColor = UIColor.a0_orange, foregroundColor: UIColor = .white, borderColor: UIColor = UIColor.a0_orange, // This should be optional in the next major, defaulting to nil - withImage image: LazyImage = LazyImage(name: "ic_auth_auth0", bundle: bundleForLock())) { + withImage image: UIImage? = UIImage(named: "ic_auth_auth0", in: bundleForLock())) { self.name = name self.normalColor = color self.foregroundColor = foregroundColor @@ -117,7 +117,7 @@ public extension AuthStyle { return AuthStyle( name: "Amazon".i18n(key: "com.auth0.lock.strategy.localized.amazon", comment: "Amazon"), color: .a0_fromRGB("#ff9900"), - withImage: LazyImage(name: "ic_auth_amazon", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_amazon", in: bundleForLock()) ) } @@ -126,7 +126,7 @@ public extension AuthStyle { return AuthStyle( name: "AOL".i18n(key: "com.auth0.lock.strategy.localized.aol", comment: "AOL"), color: .a0_fromRGB("#ff0b00"), - withImage: LazyImage(name: "ic_auth_aol", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_aol", in: bundleForLock()) ) } @@ -138,7 +138,7 @@ public extension AuthStyle { normalColor: normalColor, highlightedColor: normalColor.a0_lighter(0.3), foregroundColor: .white, - withImage: LazyImage(name: "ic_auth_apple", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_apple", in: bundleForLock()) ) } @@ -147,7 +147,7 @@ public extension AuthStyle { return AuthStyle( name: "百度".i18n(key: "com.auth0.lock.strategy.localized.baidu", comment: "Baidu"), color: .a0_fromRGB("#2529d8"), - withImage: LazyImage(name: "ic_auth_baidu", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_baidu", in: bundleForLock()) ) } @@ -156,7 +156,7 @@ public extension AuthStyle { return AuthStyle( name: "Bitbucket".i18n(key: "com.auth0.lock.strategy.localized.bitbucket", comment: "Bitbucket"), color: .a0_fromRGB("#205081"), - withImage: LazyImage(name: "ic_auth_bitbucket", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_bitbucket", in: bundleForLock()) ) } @@ -165,7 +165,7 @@ public extension AuthStyle { return AuthStyle( name: "Dropbox".i18n(key: "com.auth0.lock.strategy.localized.dropbox", comment: "Dropbox"), color: .a0_fromRGB("#0064d2"), - withImage: LazyImage(name: "ic_auth_dropbox", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_dropbox", in: bundleForLock()) ) } @@ -174,7 +174,7 @@ public extension AuthStyle { return AuthStyle( name: "Dwolla".i18n(key: "com.auth0.lock.strategy.localized.dwolla", comment: "Dwolla"), color: .a0_fromRGB("#F5891F"), - withImage: LazyImage(name: "ic_auth_dwolla", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_dwolla", in: bundleForLock()) ) } @@ -183,7 +183,7 @@ public extension AuthStyle { return AuthStyle( name: "Ebay".i18n(key: "com.auth0.lock.strategy.localized.ebay", comment: "Ebay"), color: .a0_fromRGB("#007ee5"), - withImage: LazyImage(name: "ic_auth_ebay", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_ebay", in: bundleForLock()) ) } @@ -192,7 +192,7 @@ public extension AuthStyle { return AuthStyle( name: "Evernote".i18n(key: "com.auth0.lock.strategy.localized.evernote", comment: "Evernote"), color: .a0_fromRGB("#2dbe60"), - withImage: LazyImage(name: "ic_auth_evernote", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_evernote", in: bundleForLock()) ) } @@ -201,7 +201,7 @@ public extension AuthStyle { return AuthStyle( name: "Evernote (sandbox)".i18n(key: "com.auth0.lock.strategy.localized.evernote_sandbox", comment: "EvernoteSandbox"), color: .a0_fromRGB("#2dbe60"), - withImage: LazyImage(name: "ic_auth_evernote", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_evernote", in: bundleForLock()) ) } @@ -210,7 +210,7 @@ public extension AuthStyle { return AuthStyle( name: "Exact".i18n(key: "com.auth0.lock.strategy.localized.exact", comment: "Exact"), color: .a0_fromRGB("#ED1C24"), - withImage: LazyImage(name: "ic_auth_exact", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_exact", in: bundleForLock()) ) } @@ -219,7 +219,7 @@ public extension AuthStyle { return AuthStyle( name: "Facebook".i18n(key: "com.auth0.lock.strategy.localized.facebook", comment: "Facebook"), color: .a0_fromRGB("#3b5998"), - withImage: LazyImage(name: "ic_auth_facebook", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_facebook", in: bundleForLock()) ) } @@ -228,7 +228,7 @@ public extension AuthStyle { return AuthStyle( name: "Fitbit".i18n(key: "com.auth0.lock.strategy.localized.fitbit", comment: "Fitbit"), color: .a0_fromRGB("#4cc2c4"), - withImage: LazyImage(name: "ic_auth_fitbit", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_fitbit", in: bundleForLock()) ) } @@ -237,7 +237,7 @@ public extension AuthStyle { return AuthStyle( name: "GitHub".i18n(key: "com.auth0.lock.strategy.localized.github", comment: "GitHub"), color: .a0_fromRGB("#333333"), - withImage: LazyImage(name: "ic_auth_github", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_github", in: bundleForLock()) ) } @@ -248,7 +248,7 @@ public extension AuthStyle { color: .a0_fromRGB("#ffffff"), foregroundColor: .a0_fromRGB("#333333"), borderColor: .a0_fromRGB("#dee0e2"), - withImage: LazyImage(name: "ic_auth_google", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_google", in: bundleForLock()) ) } @@ -257,7 +257,7 @@ public extension AuthStyle { return AuthStyle( name: "Instagram".i18n(key: "com.auth0.lock.strategy.localized.instagram", comment: "Instagram"), color: .a0_fromRGB("#3f729b"), - withImage: LazyImage(name: "ic_auth_instagram", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_instagram", in: bundleForLock()) ) } @@ -266,7 +266,7 @@ public extension AuthStyle { return AuthStyle( name: "LinkedIn".i18n(key: "com.auth0.lock.strategy.localized.linkedin", comment: "LinkedIn"), color: .a0_fromRGB("#0077b5"), - withImage: LazyImage(name: "ic_auth_linkedin", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_linkedin", in: bundleForLock()) ) } @@ -275,7 +275,7 @@ public extension AuthStyle { return AuthStyle( name: "miiCard".i18n(key: "com.auth0.lock.strategy.localized.miicard", comment: "miiCard"), color: .a0_fromRGB("#35A6FE"), - withImage: LazyImage(name: "ic_auth_miicard", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_miicard", in: bundleForLock()) ) } @@ -284,7 +284,7 @@ public extension AuthStyle { return AuthStyle( name: "PayPal".i18n(key: "com.auth0.lock.strategy.localized.paypal", comment: "PayPal"), color: .a0_fromRGB("#009cde"), - withImage: LazyImage(name: "ic_auth_paypal", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_paypal", in: bundleForLock()) ) } @@ -293,7 +293,7 @@ public extension AuthStyle { return AuthStyle( name: "PayPal (sandbox)".i18n(key: "com.auth0.lock.strategy.localized.paypal_sandbox", comment: "PaypalSandbox"), color: .a0_fromRGB("#009cde"), - withImage: LazyImage(name: "ic_auth_paypal", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_paypal", in: bundleForLock()) ) } @@ -302,7 +302,7 @@ public extension AuthStyle { return AuthStyle( name: "Planning Center".i18n(key: "com.auth0.lock.strategy.localized.planning_center", comment: "PlanningCenter"), color: .a0_fromRGB("#4e4e4e"), - withImage: LazyImage(name: "ic_auth_planningcenter", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_planningcenter", in: bundleForLock()) ) } @@ -311,7 +311,7 @@ public extension AuthStyle { return AuthStyle( name: "人人".i18n(key: "com.auth0.lock.strategy.localized.renren", comment: "RenRen"), color: .a0_fromRGB("#0056B5"), - withImage: LazyImage(name: "ic_auth_renren", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_renren", in: bundleForLock()) ) } @@ -320,7 +320,7 @@ public extension AuthStyle { return AuthStyle( name: "Salesforce".i18n(key: "com.auth0.lock.strategy.localized.salesforce", comment: "Salesforce"), color: .a0_fromRGB("#1798c1"), - withImage: LazyImage(name: "ic_auth_salesforce", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_salesforce", in: bundleForLock()) ) } @@ -329,7 +329,7 @@ public extension AuthStyle { return AuthStyle( name: "Salesforce Community".i18n(key: "com.auth0.lock.strategy.localized.salesforce_community", comment: "SalesforceCommunity"), color: .a0_fromRGB("#1798c1"), - withImage: LazyImage(name: "ic_auth_salesforce", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_salesforce", in: bundleForLock()) ) } @@ -338,7 +338,7 @@ public extension AuthStyle { return AuthStyle( name: "Salesforce (sandbox)".i18n(key: "com.auth0.lock.strategy.localized.salesforce_sandbox", comment: "SalesforceSandbox"), color: .a0_fromRGB("#1798c1"), - withImage: LazyImage(name: "ic_auth_salesforce", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_salesforce", in: bundleForLock()) ) } @@ -347,7 +347,7 @@ public extension AuthStyle { return AuthStyle( name: "Shopify".i18n(key: "com.auth0.lock.strategy.localized.shopify", comment: "Shopify"), color: .a0_fromRGB("#96bf48"), - withImage: LazyImage(name: "ic_auth_shopify", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_shopify", in: bundleForLock()) ) } @@ -356,7 +356,7 @@ public extension AuthStyle { return AuthStyle( name: "SoundCloud".i18n(key: "com.auth0.lock.strategy.localized.soundcloud", comment: "SoundCloud"), color: .a0_fromRGB("#ff8800"), - withImage: LazyImage(name: "ic_auth_soundcloud", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_soundcloud", in: bundleForLock()) ) } @@ -365,7 +365,7 @@ public extension AuthStyle { return AuthStyle( name: "The City".i18n(key: "com.auth0.lock.strategy.localized.the_city", comment: "TheCity"), color: .a0_fromRGB("#767571"), - withImage: LazyImage(name: "ic_auth_thecity", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_thecity", in: bundleForLock()) ) } @@ -374,7 +374,7 @@ public extension AuthStyle { return AuthStyle( name: "The City (sandbox)".i18n(key: "com.auth0.lock.strategy.localized.the_city_sandbox", comment: "TheCitySandbox"), color: .a0_fromRGB("#767571"), - withImage: LazyImage(name: "ic_auth_thecity", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_thecity", in: bundleForLock()) ) } @@ -383,7 +383,7 @@ public extension AuthStyle { return AuthStyle( name: "Basecamp".i18n(key: "com.auth0.lock.strategy.localized.thirty_seven_signals", comment: "Basecamp"), color: .a0_fromRGB("#6AC071"), - withImage: LazyImage(name: "ic_auth_thirtysevensignals", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_thirtysevensignals", in: bundleForLock()) ) } @@ -392,7 +392,7 @@ public extension AuthStyle { return AuthStyle( name: "Twitter".i18n(key: "com.auth0.lock.strategy.localized.twitter", comment: "Twitter"), color: .a0_fromRGB("#55acee"), - withImage: LazyImage(name: "ic_auth_twitter", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_twitter", in: bundleForLock()) ) } @@ -401,7 +401,7 @@ public extension AuthStyle { return AuthStyle( name: "VKontakte".i18n(key: "com.auth0.lock.strategy.localized.vkontakte", comment: "VKontakte"), color: .a0_fromRGB("#45668e"), - withImage: LazyImage(name: "ic_auth_vk", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_vk", in: bundleForLock()) ) } @@ -410,7 +410,7 @@ public extension AuthStyle { return AuthStyle( name: "Microsoft Account".i18n(key: "com.auth0.lock.strategy.localized.microsoft", comment: "Microsoft"), color: .a0_fromRGB("#00a1f1"), - withImage: LazyImage(name: "ic_auth_microsoft", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_microsoft", in: bundleForLock()) ) } @@ -419,7 +419,7 @@ public extension AuthStyle { return AuthStyle( name: "WordPress".i18n(key: "com.auth0.lock.strategy.localized.wordpress", comment: "WordPress"), color: .a0_fromRGB("#21759b"), - withImage: LazyImage(name: "ic_auth_wordpress", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_wordpress", in: bundleForLock()) ) } @@ -428,7 +428,7 @@ public extension AuthStyle { return AuthStyle( name: "Yahoo!".i18n(key: "com.auth0.lock.strategy.localized.yahoo", comment: "Yahoo"), color: .a0_fromRGB("#410093"), - withImage: LazyImage(name: "ic_auth_yahoo", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_yahoo", in: bundleForLock()) ) } @@ -437,7 +437,7 @@ public extension AuthStyle { return AuthStyle( name: "Yammer".i18n(key: "com.auth0.lock.strategy.localized.yammer", comment: "Yammer"), color: .a0_fromRGB("#0072c6"), - withImage: LazyImage(name: "ic_auth_yammer", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_yammer", in: bundleForLock()) ) } @@ -446,7 +446,7 @@ public extension AuthStyle { return AuthStyle( name: "Yandex".i18n(key: "com.auth0.lock.strategy.localized.yandex", comment: "Yandex"), color: .a0_fromRGB("#ffcc00"), - withImage: LazyImage(name: "ic_auth_yandex", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_yandex", in: bundleForLock()) ) } @@ -455,7 +455,7 @@ public extension AuthStyle { return AuthStyle( name: "新浪微博".i18n(key: "com.auth0.lock.strategy.localized.weibo", comment: "Weibo"), color: .a0_fromRGB("#DD4B39"), - withImage: LazyImage(name: "ic_auth_weibo", bundle: bundleForLock()) + withImage: UIImage(named: "ic_auth_weibo", in: bundleForLock()) ) } } diff --git a/Lock/CustomTextField.swift b/Lock/CustomTextField.swift index b032da4d1..5deff04c1 100644 --- a/Lock/CustomTextField.swift +++ b/Lock/CustomTextField.swift @@ -29,7 +29,7 @@ public struct CustomTextField { let placeholder: String let defaultValue: String? let storage: UserStorage - let icon: LazyImage? + let icon: UIImage? let keyboardType: UIKeyboardType let autocorrectionType: UITextAutocorrectionType let autocapitalizationType: UITextAutocapitalizationType @@ -38,7 +38,7 @@ public struct CustomTextField { let contentType: UITextContentType? let validation: (String?) -> Error? - public init(name: String, placeholder: String, defaultValue: String? = nil, storage: UserStorage = .userMetadata, icon: LazyImage? = nil, keyboardType: UIKeyboardType = .default, autocorrectionType: UITextAutocorrectionType = .default, autocapitalizationType: UITextAutocapitalizationType = .none, secure: Bool = false, hidden: Bool = false, contentType: UITextContentType? = nil, validation: @escaping (String?) -> Error? = nonEmpty) { + public init(name: String, placeholder: String, defaultValue: String? = nil, storage: UserStorage = .userMetadata, icon: UIImage? = nil, keyboardType: UIKeyboardType = .default, autocorrectionType: UITextAutocorrectionType = .default, autocapitalizationType: UITextAutocapitalizationType = .none, secure: Bool = false, hidden: Bool = false, contentType: UITextContentType? = nil, validation: @escaping (String?) -> Error? = nonEmpty) { self.name = name self.placeholder = placeholder self.defaultValue = defaultValue diff --git a/Lock/DatabaseModeSwitcher.swift b/Lock/DatabaseModeSwitcher.swift index 51e6b0766..ef1428767 100644 --- a/Lock/DatabaseModeSwitcher.swift +++ b/Lock/DatabaseModeSwitcher.swift @@ -84,15 +84,15 @@ class DatabaseModeSwitcher: UIView { dimension(dimension: segmented.heightAnchor, withValue: 50) segmented.translatesAutoresizingMaskIntoConstraints = false - segmented.setDividerImage(image(named: "ic_switcher_left", compatibleWithTraitCollection: self.traitCollection), forLeftSegmentState: .selected, rightSegmentState: .normal, barMetrics: .default) - segmented.setDividerImage(image(named: "ic_switcher_right", compatibleWithTraitCollection: self.traitCollection), forLeftSegmentState: .normal, rightSegmentState: .selected, barMetrics: .default) - segmented.setDividerImage(image(named: "ic_switcher_both", compatibleWithTraitCollection: self.traitCollection), forLeftSegmentState: .selected, rightSegmentState: .selected, barMetrics: .default) - segmented.setDividerImage(image(named: "ic_switcher_both", compatibleWithTraitCollection: self.traitCollection), forLeftSegmentState: .highlighted, rightSegmentState: .selected, barMetrics: .default) - segmented.setDividerImage(image(named: "ic_switcher_both", compatibleWithTraitCollection: self.traitCollection), forLeftSegmentState: .selected, rightSegmentState: .highlighted, barMetrics: .default) - segmented.setDividerImage(image(named: "ic_switcher_none", compatibleWithTraitCollection: self.traitCollection), forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default) - segmented.setBackgroundImage(image(named: "ic_switcher_selected", compatibleWithTraitCollection: self.traitCollection), for: .selected, barMetrics: .default) - segmented.setBackgroundImage(image(named: "ic_switcher_selected", compatibleWithTraitCollection: self.traitCollection), for: .highlighted, barMetrics: .default) - segmented.setBackgroundImage(image(named: "ic_switcher_normal", compatibleWithTraitCollection: self.traitCollection), for: .normal, barMetrics: .default) + segmented.setDividerImage(UIImage(named: "ic_switcher_left", in: bundleForLock(), compatibleWith: self.traitCollection), forLeftSegmentState: .selected, rightSegmentState: .normal, barMetrics: .default) + segmented.setDividerImage(UIImage(named: "ic_switcher_right", in: bundleForLock(), compatibleWith: self.traitCollection), forLeftSegmentState: .normal, rightSegmentState: .selected, barMetrics: .default) + segmented.setDividerImage(UIImage(named: "ic_switcher_both", in: bundleForLock(), compatibleWith: self.traitCollection), forLeftSegmentState: .selected, rightSegmentState: .selected, barMetrics: .default) + segmented.setDividerImage(UIImage(named: "ic_switcher_both", in: bundleForLock(), compatibleWith: self.traitCollection), forLeftSegmentState: .highlighted, rightSegmentState: .selected, barMetrics: .default) + segmented.setDividerImage(UIImage(named: "ic_switcher_both", in: bundleForLock(), compatibleWith: self.traitCollection), forLeftSegmentState: .selected, rightSegmentState: .highlighted, barMetrics: .default) + segmented.setDividerImage(UIImage(named: "ic_switcher_none", in: bundleForLock(), compatibleWith: self.traitCollection), forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default) + segmented.setBackgroundImage(UIImage(named: "ic_switcher_selected", in: bundleForLock(), compatibleWith: self.traitCollection), for: .selected, barMetrics: .default) + segmented.setBackgroundImage(UIImage(named: "ic_switcher_selected", in: bundleForLock(), compatibleWith: self.traitCollection), for: .highlighted, barMetrics: .default) + segmented.setBackgroundImage(UIImage(named: "ic_switcher_normal", in: bundleForLock(), compatibleWith: self.traitCollection), for: .normal, barMetrics: .default) segmented.setTitleTextAttributes([ NSAttributedString.attributedKeyColor: Style.Auth0.tabTextColor, NSAttributedString.attributedFont: mediumSystemFont(size: 15) diff --git a/Lock/DatabaseOnlyView.swift b/Lock/DatabaseOnlyView.swift index fda23f561..67799df67 100644 --- a/Lock/DatabaseOnlyView.swift +++ b/Lock/DatabaseOnlyView.swift @@ -120,7 +120,7 @@ class DatabaseOnlyView: UIView, DatabaseView { self.showPasswordButton = form.passwordField.addFieldButton(withIcon: "ic_show_password_hidden", color: Style.Auth0.inputIconColor) self.showPasswordButton?.onPress = { [unowned self] button in passwordInput.isSecureTextEntry = !passwordInput.isSecureTextEntry - button.icon = LazyImage(name: passwordInput.isSecureTextEntry ? "ic_show_password_hidden" : "ic_show_password_visible", bundle: Lock.bundle).image(compatibleWithTraits: self.traitCollection) + button.icon = UIImage(named: passwordInput.isSecureTextEntry ? "ic_show_password_hidden" : "ic_show_password_visible", in: Lock.bundle, compatibleWith: self.traitCollection) } } } @@ -171,7 +171,7 @@ class DatabaseOnlyView: UIView, DatabaseView { self.showPasswordButton = form.passwordField.addFieldButton(withIcon: "ic_show_password_hidden", color: Style.Auth0.inputIconColor) self.showPasswordButton?.onPress = { [unowned self] button in passwordInput.isSecureTextEntry = !passwordInput.isSecureTextEntry - button.icon = LazyImage(name: passwordInput.isSecureTextEntry ? "ic_show_password_hidden" : "ic_show_password_visible", bundle: Lock.bundle).image(compatibleWithTraits: self.traitCollection) + button.icon = UIImage(named: passwordInput.isSecureTextEntry ? "ic_show_password_hidden" : "ic_show_password_visible", in: Lock.bundle, compatibleWith: self.traitCollection) } } } diff --git a/Lock/HeaderView.swift b/Lock/HeaderView.swift index f6a4fc968..97b85fdcf 100644 --- a/Lock/HeaderView.swift +++ b/Lock/HeaderView.swift @@ -165,10 +165,10 @@ public class HeaderView: UIView { self.applyBackground() self.apply(style: Style.Auth0) titleView.font = regularSystemFont(size: 20) - logoView.image = image(named: "ic_auth0", compatibleWithTraitCollection: self.traitCollection) - closeButton.setBackgroundImage(image(named: "ic_close", compatibleWithTraitCollection: self.traitCollection)?.withRenderingMode(.alwaysOriginal), for: .normal) + logoView.image = UIImage(named: "ic_auth0", in: bundleForLock(), compatibleWith: self.traitCollection) + closeButton.setBackgroundImage(UIImage(named: "ic_close", in: bundleForLock(), compatibleWith: self.traitCollection)?.withRenderingMode(.alwaysOriginal), for: .normal) closeButton.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside) - backButton.setBackgroundImage(image(named: "ic_back", compatibleWithTraitCollection: self.traitCollection)?.withRenderingMode(.alwaysOriginal), for: .normal) + backButton.setBackgroundImage(UIImage(named: "ic_back", in: bundleForLock(), compatibleWith: self.traitCollection)?.withRenderingMode(.alwaysOriginal), for: .normal) backButton.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside) self.titleView = titleView @@ -228,7 +228,7 @@ public class HeaderView: UIView { constraintEqual(anchor: maskView.centerXAnchor, toAnchor: self.centerXAnchor) maskView.contentMode = .scaleToFill - maskView.image = image(named: "ic_auth0", compatibleWithTraitCollection: self.traitCollection)?.withRenderingMode(.alwaysTemplate) + maskView.image = UIImage(named: "ic_auth0", in: bundleForLock(), compatibleWith: self.traitCollection)?.withRenderingMode(.alwaysTemplate) maskView.tintColor = self.maskColor self.maskImageView = maskView @@ -247,10 +247,10 @@ extension HeaderView: Stylable { } self.title = style.hideTitle ? nil : style.title self.titleColor = style.titleColor - self.logo = style.logo.image(compatibleWithTraits: self.traitCollection) + self.logo = style.logo self.maskImage = style.headerMask - self.backButton?.setBackgroundImage(style.headerBackIcon.image(compatibleWithTraits: self.traitCollection)?.withRenderingMode(.alwaysOriginal), for: .normal) - self.closeButton?.setBackgroundImage(style.headerCloseIcon.image(compatibleWithTraits: self.traitCollection)?.withRenderingMode(.alwaysOriginal), for: .normal) + self.backButton?.setBackgroundImage(style.headerBackIcon?.withRenderingMode(.alwaysOriginal), for: .normal) + self.closeButton?.setBackgroundImage(style.headerCloseIcon?.withRenderingMode(.alwaysOriginal), for: .normal) } } diff --git a/Lock/InfoBarView.swift b/Lock/InfoBarView.swift index 4cf1acb86..cee493e68 100644 --- a/Lock/InfoBarView.swift +++ b/Lock/InfoBarView.swift @@ -103,7 +103,7 @@ class InfoBarView: UIView { static var ssoInfoBar: InfoBarView { let ssoBar = InfoBarView() ssoBar.title = "SINGLE SIGN-ON ENABLED".i18n(key: "com.auth0.lock.enterprise.sso.title", comment: "SSO Header") - ssoBar.icon = image(named: "ic_lock_full") + ssoBar.icon = UIImage(named: "ic_lock_full", in: bundleForLock()) return ssoBar } } diff --git a/Lock/InputField.swift b/Lock/InputField.swift index 4139067f6..6b0d3cce9 100644 --- a/Lock/InputField.swift +++ b/Lock/InputField.swift @@ -63,7 +63,7 @@ class InputField: UIView, Stylable { self.textField?.textContentType = type.contentType } if let icon = type.icon { - self.iconView?.image = icon.image(compatibleWithTraits: self.traitCollection) + self.iconView?.image = icon } else if let textField = self.textField, let container = self.containerView { self.iconContainer?.removeFromSuperview() textFieldLeftAnchor = constraintEqual(anchor: textField.leftAnchor, toAnchor: container.leftAnchor, constant: 16) @@ -218,7 +218,7 @@ class InputField: UIView, Stylable { guard let container = self.containerView, let textField = self.textField else { return nil } let button = IconButton() - button.icon = LazyImage(name: name, bundle: Lock.bundle).image(compatibleWithTraits: self.traitCollection) + button.icon = UIImage(named: name, in: Lock.bundle, compatibleWith: self.traitCollection) button.color = color container.addSubview(button) @@ -280,7 +280,7 @@ class InputField: UIView, Stylable { case password case phone case oneTimePassword - case custom(name: String, placeholder: String, defaultValue: String?, storage: UserStorage, icon: LazyImage?, keyboardType: UIKeyboardType, autocorrectionType: UITextAutocorrectionType, autocapitalizationType: UITextAutocapitalizationType, secure: Bool, hidden: Bool, contentType: UITextContentType?) + case custom(name: String, placeholder: String, defaultValue: String?, storage: UserStorage, icon: UIImage?, keyboardType: UIKeyboardType, autocorrectionType: UITextAutocorrectionType, autocapitalizationType: UITextAutocapitalizationType, secure: Bool, hidden: Bool, contentType: UITextContentType?) var placeholder: String? { switch self { @@ -330,20 +330,20 @@ class InputField: UIView, Stylable { } } - var icon: LazyImage? { + var icon: UIImage? { switch self { case .email: - return lazyImage(named: "ic_mail") + return UIImage(named: "ic_mail", in: bundleForLock()) case .username: - return lazyImage(named: "ic_person") + return UIImage(named: "ic_person", in: bundleForLock()) case .emailOrUsername: - return lazyImage(named: "ic_mail") + return UIImage(named: "ic_mail", in: bundleForLock()) case .password: - return lazyImage(named: "ic_lock") + return UIImage(named: "ic_lock", in: bundleForLock()) case .phone: - return lazyImage(named: "ic_phone") + return UIImage(named: "ic_phone", in: bundleForLock()) case .oneTimePassword: - return lazyImage(named: "ic_lock") + return UIImage(named: "ic_lock", in: bundleForLock()) case .custom(_, _, _, _, let icon, _, _, _, _, _, _): return icon } diff --git a/Lock/InternationalPhoneInputView.swift b/Lock/InternationalPhoneInputView.swift index 4dbee0917..3073f0852 100644 --- a/Lock/InternationalPhoneInputView.swift +++ b/Lock/InternationalPhoneInputView.swift @@ -192,8 +192,8 @@ class InternationalPhoneInputView: UIView, Form, Stylable { stackView.distribution = .equalSpacing stackView.spacing = 10 - iconView.image = lazyImage(named: "ic_globe").image() - actionIconView.image = lazyImage(named: "ic_chevron_right").image() + iconView.image = UIImage(named: "ic_globe", in: bundleForLock(), compatibleWith: self.traitCollection) + actionIconView.image = UIImage(named: "ic_chevron_right", in: bundleForLock(), compatibleWith: self.traitCollection) countryLabel.textColor = Style.Auth0.inputPlaceholderTextColor codeLabel.textColor = Style.Auth0.inputPlaceholderTextColor diff --git a/Lock/LazyImage.swift b/Lock/LazyImage.swift deleted file mode 100644 index b1b974946..000000000 --- a/Lock/LazyImage.swift +++ /dev/null @@ -1,59 +0,0 @@ -// LazyImage.swift -// -// Copyright (c) 2016 Auth0 (http://auth0.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import Foundation -import UIKit - -/** - * Convenience struct to hold an image reference to a `NSBundle` without loading the `UIImage`. - * Used to tell Lock to load an image from a specific bundle, e.g. when customising the Header logo. - */ -public struct LazyImage: Equatable { - let bundle: Bundle - let name: String - - /** - Creates a LazyImage with a name and an optional Bundle. - For images outside Lock's bundle you should specify the Bundle like - - ``` - let image = LazyImage(name: "image_name") - ``` - - - parameter name: name of the image to load from a bundle - - parameter bundle: bundle from where to load the image. By default is application main bundle - - - returns: a newly created `LazyImage` - */ - public init(name: String, bundle: Bundle = Bundle.main) { - self.name = name - self.bundle = bundle - } - - func image(compatibleWithTraits traits: UITraitCollection? = nil) -> UIImage? { - return UIImage(named: self.name, in: self.bundle, compatibleWith: traits) - } -} - -public func == (lhs: LazyImage, rhs: LazyImage) -> Bool { - return lhs.name == rhs.name && lhs.bundle == rhs.bundle -} diff --git a/Lock/Lock.swift b/Lock/Lock.swift index 5fd832b39..b4ebf9aca 100644 --- a/Lock/Lock.swift +++ b/Lock/Lock.swift @@ -186,7 +186,7 @@ public class Lock: NSObject { .style { $0.title = "Auth0 Inc." $0.primaryColor = .orange - $0.logo = LazyImage(name: "icn_auth0") + $0.logo = UIImage(named: "icn_auth0") } ``` diff --git a/Lock/LockViewController.swift b/Lock/LockViewController.swift index 7722556d4..7489fc8da 100644 --- a/Lock/LockViewController.swift +++ b/Lock/LockViewController.swift @@ -73,7 +73,7 @@ public class LockViewController: UIViewController { root.backgroundColor = style.backgroundColor self.view = root - if let backgroundImage = style.backgroundImage?.image(compatibleWithTraits: self.traitCollection) { + if let backgroundImage = style.backgroundImage { let bgImageView = UIImageView(image: backgroundImage) self.view.addSubview(bgImageView) } diff --git a/Lock/PasswordlessView.swift b/Lock/PasswordlessView.swift index bd1e06f19..a9cf0dc68 100644 --- a/Lock/PasswordlessView.swift +++ b/Lock/PasswordlessView.swift @@ -177,7 +177,7 @@ class PasswordlessView: UIView, View { imageView.clipsToBounds = true imageView.contentMode = .scaleAspectFit - imageView.image = LazyImage(name: "ic_email_sent", bundle: bundleForLock()).image(compatibleWithTraits: self.traitCollection) + imageView.image = UIImage(named: "ic_email_sent", in: bundleForLock(), compatibleWith: self.traitCollection) if let countryCode = countryCode, let identifier = identifier { displayIdentifier = countryCode.phoneCode + identifier diff --git a/Lock/PolicyView.swift b/Lock/PolicyView.swift index afbf2cf9a..6175c70b6 100644 --- a/Lock/PolicyView.swift +++ b/Lock/PolicyView.swift @@ -112,11 +112,11 @@ class RuleView: UIView { var icon: UIImage? { switch self { case .ok: - return image(named: "ic_pwd_policy_ok") + return UIImage(named: "ic_pwd_policy_ok", in: bundleForLock()) case .error: - return image(named: "ic_pwd_policy_error") + return UIImage(named: "ic_pwd_policy_error", in: bundleForLock()) case .none: - return image(named: "ic_pwd_policy_none") + return UIImage(named: "ic_pwd_policy_none", in: bundleForLock()) } } diff --git a/Lock/PrimaryButton.swift b/Lock/PrimaryButton.swift index 9e5cc1639..349e2afd0 100644 --- a/Lock/PrimaryButton.swift +++ b/Lock/PrimaryButton.swift @@ -110,14 +110,14 @@ class PrimaryButton: UIView, Stylable { button.setAttributedTitle(nil, for: .normal) button.setAttributedTitle(nil, for: .disabled) guard let title = title, !self.hideTitle else { - button.setImage(image(named: "ic_submit", compatibleWithTraitCollection: self.traitCollection), for: .normal) + button.setImage(UIImage(named: "ic_submit", in: bundleForLock(), compatibleWith: self.traitCollection), for: .normal) button.setImage(UIImage(), for: .disabled) return } let font = mediumSystemFont(size: 16) let attachment = NSTextAttachment() - attachment.image = image(named: "ic_chevron_right", compatibleWithTraitCollection: self.traitCollection) + attachment.image = UIImage(named: "ic_chevron_right", in: bundleForLock(), compatibleWith: self.traitCollection) attachment.bounds = CGRect(x: 0.0, y: font.descender / 2.0, width: attachment.image!.size.width, height: attachment.image!.size.height) let attributedText = NSMutableAttributedString(string: "\(title) ") diff --git a/Lock/Resources.swift b/Lock/Resources.swift index aaa9ebf86..67a3302a3 100644 --- a/Lock/Resources.swift +++ b/Lock/Resources.swift @@ -31,10 +31,23 @@ public func bundleForLock() -> Bundle { #endif } -func lazyImage(named name: String) -> LazyImage { return LazyImage(name: name, bundle: bundleForLock()) } +@available(*, deprecated, renamed: "UIImage") +public typealias LazyImage = UIImage -func image(named name: String, compatibleWithTraitCollection traitCollection: UITraitCollection? = nil) -> UIImage? { - return UIImage(named: name, in: bundleForLock(), compatibleWith: traitCollection) +extension UIImage { + public convenience init?(named name: String, in bundle: Bundle) { + self.init(named: name, in: bundle, compatibleWith: nil) + } + + @available(*, deprecated, renamed: "init(named:)") + public convenience init?(name: String) { + self.init(named: name) + } + + @available(*, deprecated, renamed: "init(named:in:)") + public convenience init?(name: String, bundle: Bundle) { + self.init(named: name, in: bundle, compatibleWith: nil) + } } func image(withColor color: UIColor) -> UIImage? { diff --git a/Lock/Style.swift b/Lock/Style.swift index 9680d2e22..95dfd06a6 100644 --- a/Lock/Style.swift +++ b/Lock/Style.swift @@ -38,7 +38,7 @@ public struct Style { public var backgroundColor = UIColor.white /// Lock background image - public var backgroundImage: LazyImage? + public var backgroundImage: UIImage? /// Lock disabled component color public var disabledColor = UIColor(red: 0.8902, green: 0.898, blue: 0.9059, alpha: 1.0) @@ -56,10 +56,10 @@ public struct Style { public var headerBlur: A0BlurEffectStyle = .light /// Header close button image - public var headerCloseIcon: LazyImage = lazyImage(named: "ic_close") + public var headerCloseIcon: UIImage? = UIImage(named: "ic_close", in: bundleForLock()) /// Header back button image - public var headerBackIcon: LazyImage = lazyImage(named: "ic_back") + public var headerBackIcon: UIImage? = UIImage(named: "ic_back", in: bundleForLock()) /// Header title color public var titleColor = UIColor.black @@ -78,7 +78,7 @@ public struct Style { public var hideButtonTitle = false /// Header logo image - public var logo: LazyImage = lazyImage(named: "ic_auth0") + public var logo: UIImage? = UIImage(named: "ic_auth0", in: bundleForLock()) /// OAuth2 custom connection styles by mapping a connection name with an `AuthStyle` public var oauth2: [String: AuthStyle] = [:] @@ -150,8 +150,8 @@ public struct Style { public var modalPopup = true var headerMask: UIImage? { - let image = self.logo.image(compatibleWithTraits: nil) - if Style.Auth0.logo == self.logo { + let image = self.logo + if Style.Auth0.logo == image { return image?.withRenderingMode(.alwaysTemplate) } return image diff --git a/Lock/UnrecoverableErrorView.swift b/Lock/UnrecoverableErrorView.swift index 4700e0493..c9e799292 100644 --- a/Lock/UnrecoverableErrorView.swift +++ b/Lock/UnrecoverableErrorView.swift @@ -70,7 +70,7 @@ class UnrecoverableErrorView: UIView, View { constraintEqual(anchor: actionButton.topAnchor, toAnchor: messageLabel.bottomAnchor, constant: 10) actionButton.translatesAutoresizingMaskIntoConstraints = false - imageView.image = LazyImage(name: "ic_connection_error", bundle: bundleForLock()).image(compatibleWithTraits: self.traitCollection) + imageView.image = UIImage(named: "ic_connection_error", in: bundleForLock(), compatibleWith: self.traitCollection) titleLabel.textAlignment = .center titleLabel.font = lightSystemFont(size: 22) titleLabel.numberOfLines = 1 diff --git a/LockTests/Interactors/DatabaseInteractorSpec.swift b/LockTests/Interactors/DatabaseInteractorSpec.swift index d0f9261f4..e4d70b196 100644 --- a/LockTests/Interactors/DatabaseInteractorSpec.swift +++ b/LockTests/Interactors/DatabaseInteractorSpec.swift @@ -350,7 +350,7 @@ class DatabaseInteractorSpec: QuickSpec { beforeEach { var options = LockOptions() - options.customSignupFields = [CustomTextField(name: "first_name", placeholder: "First Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle))] + options.customSignupFields = [CustomTextField(name: "first_name", placeholder: "First Name", icon: UIImage(named: "ic_person", in: Lock.bundle))] database = DatabaseInteractor(connection: DatabaseConnection(name: connection, requiresUsername: true), authentication: authentication, webAuthentication: webAuthentication, user: user, options: options, dispatcher: ObserverStore()) } @@ -374,7 +374,7 @@ class DatabaseInteractorSpec: QuickSpec { it("should raise error for custom validation") { var options = LockOptions() let error = NSError(domain: "com.auth0", code: -99999, userInfo: [:]) - options.customSignupFields = [CustomTextField(name: "first_name", placeholder: "First Name", icon: LazyImage(name: "ic_person", bundle: Lock.bundle), validation: { _ in return error })] + options.customSignupFields = [CustomTextField(name: "first_name", placeholder: "First Name", icon: UIImage(named: "ic_person", in: Lock.bundle), validation: { _ in return error })] database = DatabaseInteractor(connection: DatabaseConnection(name: connection, requiresUsername: true), authentication: authentication, webAuthentication: webAuthentication, user: user, options: options, dispatcher: ObserverStore()) expect{ try database.update(.custom(name: "first_name", storage: .userMetadata), value: nil) }.to(throwError(error)) } diff --git a/LockTests/LazyImageSpec.swift b/LockTests/LazyImageSpec.swift deleted file mode 100644 index a06613a9e..000000000 --- a/LockTests/LazyImageSpec.swift +++ /dev/null @@ -1,64 +0,0 @@ -// LazyImageSpec.swift -// -// Copyright (c) 2016 Auth0 (http://auth0.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -import Foundation -import Quick -import Nimble - -@testable import Lock - -class LazyImageSpec: QuickSpec { - - override func spec() { - - describe("init") { - - it("should use name only") { - let image = LazyImage(name: "image") - expect(image.name) == "image" - expect(image.bundle) == Bundle.main - } - - it("should use name and bundle") { - let image = LazyImage(name: "image", bundle: Lock.bundle) - expect(image.name) == "image" - expect(image.bundle) == Lock.bundle - } - - } - - describe("image(compatibleWithTraits:)") { - it("should load image") { - let image = LazyImage(name: "ic_auth0", bundle: Lock.bundle) - expect(image.image(compatibleWithTraits: nil)).toNot(beNil()) - } - - it("should return nil when image cannot be found") { - let image = LazyImage(name: "ic_not_found_image") - expect(image.image(compatibleWithTraits: nil)).to(beNil()) - } - - } - - } - -} diff --git a/LockTests/LockSpec.swift b/LockTests/LockSpec.swift index ebe624d34..bb48bc051 100644 --- a/LockTests/LockSpec.swift +++ b/LockTests/LockSpec.swift @@ -212,7 +212,7 @@ class LockSpec: QuickSpec { _ = lock.withStyle { $0.title = "Test Title" $0.primaryColor = UIColor.green - $0.logo = LazyImage(name: "icn_auth0") + $0.logo = UIImage(named: "ic_auth0", in: Lock.bundle) } } @@ -224,8 +224,8 @@ class LockSpec: QuickSpec { expect(lock.style.primaryColor).to(equal(UIColor.green)) } - it("logo should be match custom LazyImage") { - expect(lock.style.logo).to(equal(LazyImage(name: "icn_auth0"))) + it("logo should be match custom UIImage") { + expect(lock.style.logo).to(equal(UIImage(named: "ic_auth0", in: Lock.bundle))) } } diff --git a/LockTests/Models/AuthStyleSpec.swift b/LockTests/Models/AuthStyleSpec.swift index b0794317d..12ffafcf4 100644 --- a/LockTests/Models/AuthStyleSpec.swift +++ b/LockTests/Models/AuthStyleSpec.swift @@ -58,8 +58,7 @@ class AuthStyleSpecSharedExamplesConfiguration: QuickConfiguration { } it("should have icon") { - expect(style.image.name) == iconName - expect(style.image.bundle) == Lock.bundle + expect(style.image) == UIImage(named: iconName, in: Lock.bundle) } } } @@ -78,7 +77,7 @@ class AuthStyleSpec: QuickSpec { } it("should have default image") { - expect(strategy.image.name) == "ic_auth_auth0" + expect(strategy.image) == UIImage(named: "ic_auth_auth0", in: Lock.bundle) } it("should have default color") { @@ -97,10 +96,6 @@ class AuthStyleSpec: QuickSpec { expect(strategy.borderColor).to(beNil()) } - it("should have main bundle") { - expect(strategy.image.bundle) == bundleForLock() - } - } describe("titles") { @@ -255,5 +250,5 @@ extension AuthStyle: Equatable, CustomStringConvertible { } public func ==(lhs: AuthStyle, rhs: AuthStyle) -> Bool { - return lhs.name == rhs.name && lhs.normalColor == rhs.normalColor && lhs.highlightedColor == rhs.highlightedColor && lhs.foregroundColor == rhs.foregroundColor && lhs.image.name == rhs.image.name + return lhs.name == rhs.name && lhs.normalColor == rhs.normalColor && lhs.highlightedColor == rhs.highlightedColor && lhs.foregroundColor == rhs.foregroundColor && lhs.image == rhs.image } diff --git a/LockTests/Presenters/DatabasePresenterSpec.swift b/LockTests/Presenters/DatabasePresenterSpec.swift index a674f2195..de1213381 100644 --- a/LockTests/Presenters/DatabasePresenterSpec.swift +++ b/LockTests/Presenters/DatabasePresenterSpec.swift @@ -565,7 +565,7 @@ class DatabasePresenterSpec: QuickSpec { it("should custom field") { let name = "Auth0" - let input = mockInput(.custom(name: "first_name", placeholder: "Name", defaultValue: nil, storage: .userMetadata, icon: LazyImage(name: "ic_auth0", bundle: Lock.bundle), keyboardType: .default, autocorrectionType: .no, autocapitalizationType: .none, secure: false, hidden: false, contentType: nil), value: name) + let input = mockInput(.custom(name: "first_name", placeholder: "Name", defaultValue: nil, storage: .userMetadata, icon: UIImage(named: "ic_auth0", in: Lock.bundle), keyboardType: .default, autocorrectionType: .no, autocapitalizationType: .none, secure: false, hidden: false, contentType: nil), value: name) view.form?.onValueChange(input) expect(interactor.custom["first_name"]) == name } diff --git a/LockTests/StyleSpec.swift b/LockTests/StyleSpec.swift index dd2c35b0a..4fcfc95cb 100644 --- a/LockTests/StyleSpec.swift +++ b/LockTests/StyleSpec.swift @@ -55,7 +55,7 @@ class StyleSpec: QuickSpec { } it("should have logo") { - expect(style.logo) == lazyImage(named: "ic_auth0") + expect(style.logo) == UIImage(named: "ic_auth0", in: Lock.bundle) } it("should have social seperator text color") { @@ -131,11 +131,11 @@ class StyleSpec: QuickSpec { } it("should have header close button image") { - expect(style.headerCloseIcon) == lazyImage(named: "ic_close") + expect(style.headerCloseIcon) == UIImage(named: "ic_close", in: Lock.bundle) } it("should have header back button image") { - expect(style.headerBackIcon) == lazyImage(named: "ic_back") + expect(style.headerBackIcon) == UIImage(named: "ic_back", in: Lock.bundle) } it("should have modal popup true") { diff --git a/README.md b/README.md index 35f2cfacc..d631638a2 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ iPad presentation is show in a modal popup, this can be disabled to use full scr ```swift .withStyle { $0.title = "Company LLC" - $0.logo = LazyImage(name: "company_logo") + $0.logo = UIImage(named: "company_logo") $0.primaryColor = UIColor(red: 0.6784, green: 0.5412, blue: 0.7333, alpha: 1.0) } ``` @@ -254,7 +254,7 @@ iPad presentation is show in a modal popup, this can be disabled to use full scr $0.oauth2["slack"] = AuthStyle( name: "Slack", color: UIColor(red: 0.4118, green: 0.8078, blue: 0.6588, alpha: 1.0), - withImage: LazyImage(name: "ic_slack") + withImage: UIImage(named: "ic_slack") ) } ``` @@ -468,8 +468,8 @@ When signing up, your app may need to assign values to the user's profile that a ```swift .withOptions { $0.customSignupFields = [ - CustomTextField(name: "first_name", placeholder: "First Name", storage: .rootAttribute, icon: LazyImage(name: "ic_person", bundle: Lock.bundle), contentType: .givenName), - CustomTextField(name: "last_name", placeholder: "Last Name", storage: .rootAttribute, icon: LazyImage(name: "ic_person", bundle: Lock.bundle), contentType: .familyName), + CustomTextField(name: "first_name", placeholder: "First Name", storage: .rootAttribute, icon: UIImage(named: "ic_person", bundle: Lock.bundle), contentType: .givenName), + CustomTextField(name: "last_name", placeholder: "Last Name", storage: .rootAttribute, icon: UIImage(named: "ic_person", bundle: Lock.bundle), contentType: .familyName), CustomTextField(name: "referral_code", placeholder: "Referral Code", defaultValue: referralCode, hidden: true) ] }