Skip to content
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
22 changes: 11 additions & 11 deletions WooCommerce/Classes/Extensions/UIButton+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ extension UIButton {

let normalBackgroundImage = UIImage.renderBackgroundImage(fill: .primaryButtonBackground,
border: .primaryButtonBorder)
.applyTintColorToiOS13(.primaryButtonBackground)
.withTintColor(.primaryButtonBackground)
setBackgroundImage(normalBackgroundImage, for: .normal)

let highlightedBackgroundImage = UIImage.renderBackgroundImage(fill: .primaryButtonDownBackground,
border: .primaryButtonDownBorder)
.applyTintColorToiOS13(.primaryButtonDownBackground)
.withTintColor(.primaryButtonDownBackground)
setBackgroundImage(highlightedBackgroundImage, for: .highlighted)

let disabledBackgroundImage = UIImage.renderBackgroundImage(fill: .buttonDisabledBackground,
border: .buttonDisabledBorder)
.applyTintColorToiOS13(.buttonDisabledBorder) // Use border as tint color since the background is clear
.withTintColor(.buttonDisabledBorder) // Use border as tint color since the background is clear
setBackgroundImage(disabledBackgroundImage, for: .disabled)
}

Expand All @@ -54,17 +54,17 @@ extension UIButton {

let normalBackgroundImage = UIImage.renderBackgroundImage(fill: .secondaryButtonBackground,
border: .secondaryButtonBorder)
.applyTintColorToiOS13(.secondaryButtonBackground)
.withTintColor(.secondaryButtonBackground)
setBackgroundImage(normalBackgroundImage, for: .normal)

let highlightedBackgroundImage = UIImage.renderBackgroundImage(fill: .secondaryButtonDownBackground,
border: .secondaryButtonDownBorder)
.applyTintColorToiOS13(.secondaryButtonDownBackground)
.withTintColor(.secondaryButtonDownBackground)
setBackgroundImage(highlightedBackgroundImage, for: .highlighted)

let disabledBackgroundImage = UIImage.renderBackgroundImage(fill: .buttonDisabledBackground,
border: .buttonDisabledBorder)
.applyTintColorToiOS13(.buttonDisabledBackground)
.withTintColor(.buttonDisabledBackground)
setBackgroundImage(disabledBackgroundImage, for: .disabled)
}

Expand Down Expand Up @@ -110,25 +110,25 @@ extension UIButton {

let normalBackgroundImage = UIImage.renderBackgroundImage(fill: .tertiarySystemBackground,
border: .secondaryButtonBorder)
.applyTintColorToiOS13(.tertiarySystemBackground)
.withTintColor(.tertiarySystemBackground)
setBackgroundImage(normalBackgroundImage, for: .normal)

let highlightedBackgroundImage = UIImage.renderBackgroundImage(fill: .secondaryButtonDownBackground,
border: .secondaryButtonDownBorder)
.applyTintColorToiOS13(.secondaryButtonDownBackground)
.withTintColor(.secondaryButtonDownBackground)
setBackgroundImage(highlightedBackgroundImage, for: .highlighted)

let disabledBackgroundImage = UIImage.renderBackgroundImage(fill: .buttonDisabledBackground,
border: .buttonDisabledBorder)
.applyTintColorToiOS13(.buttonDisabledBackground)
.withTintColor(.buttonDisabledBackground)
setBackgroundImage(disabledBackgroundImage, for: .disabled)
}

/// Applies the Single-Color Icon Button Style: accent/accent dark tint color
///
func applyIconButtonStyle(icon: UIImage) {
let normalImage = icon.applyTintColor(.accent)
let highlightedImage = icon.applyTintColor(.accentDark)
let normalImage = icon.withTintColor(.accent)
let highlightedImage = icon.withTintColor(.accentDark)
setImage(normalImage, for: .normal)
setImage(highlightedImage, for: .highlighted)
tintColor = .accent
Expand Down
16 changes: 0 additions & 16 deletions WooCommerce/Classes/Extensions/UIImage+TintColor.swift

This file was deleted.

4 changes: 2 additions & 2 deletions WooCommerce/Classes/Extensions/UIImage+Woo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension UIImage {
static var cameraImage: UIImage {
return UIImage.gridicon(.camera)
.imageFlippedForRightToLeftLayoutDirection()
.applyTintColor(.placeholderImage)!
.withTintColor(.placeholderImage)
Copy link
Contributor

@iamgabrielma iamgabrielma Nov 17, 2022

Choose a reason for hiding this comment

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

💯

While checking why would we be force-unwrapping this, I saw there's several instances of imageWithTintColor(tintColor)! as well, which has been renamed to withTintColor(_:) and the force-unwrapping can be removed too. Would make sense to fix these as well as part of this PR? Or I can open a new issue otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint here @iamgabrielma
We have some references to the WordPressUI function imageWithTintColor, which returns an optional, hence the force unwrapping. I didn't change those, because I didn't know if by doing so we would get any unexpected change (imageWithTintColor has its own implementation that might differ from Apple's). Because of that, I think creating a new issue to check on those is the right course of action here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha! I opened a new one here: #8151

}

/// Product categories Icon
Expand Down Expand Up @@ -329,7 +329,7 @@ extension UIImage {
static var giftWithTopRightRedDotImage: UIImage {
guard let image = UIImage.gridicon(.gift, size: CGSize(width: 24, height: 24))
// Applies a constant gray color that looks fine in both Light/Dark modes, since we are generating an image with multiple colors.
.applyTintColor(.gray(.shade30))?
.withTintColor(.gray(.shade30))
.imageWithTopRightDot(imageOrigin: CGPoint(x: 0, y: 2),
finalSize: CGSize(width: 26, height: 26)) else {
fatalError()
Expand Down
8 changes: 2 additions & 6 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
0236BCA425087B660043EB43 /* ProductFormRemoteActionUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0236BCA325087B660043EB43 /* ProductFormRemoteActionUseCaseTests.swift */; };
023930612918F36400B2632F /* DomainSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 023930602918F36400B2632F /* DomainSelectorView.swift */; };
02393069291A065000B2632F /* DomainRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02393068291A065000B2632F /* DomainRowView.swift */; };
02396251239948470096F34C /* UIImage+TintColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02396250239948470096F34C /* UIImage+TintColor.swift */; };
023A059A24135F2600E3FC99 /* ReviewsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 023A059824135F2600E3FC99 /* ReviewsViewController.swift */; };
023A059B24135F2600E3FC99 /* ReviewsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 023A059924135F2600E3FC99 /* ReviewsViewController.xib */; };
023D1DD124AB2D05002B03A3 /* ProductListSelectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 023D1DD024AB2D05002B03A3 /* ProductListSelectorViewController.swift */; };
Expand Down Expand Up @@ -463,8 +462,8 @@
035C6DEB273EA12D00F70406 /* SoftwareUpdateTypeProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035C6DEA273EA12D00F70406 /* SoftwareUpdateTypeProperty.swift */; };
035F2308275690970019E1B0 /* CardPresentModalConnectingFailedUpdatePostalCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 035F2307275690970019E1B0 /* CardPresentModalConnectingFailedUpdatePostalCode.swift */; };
0366EAE12909A37800B51755 /* JustInTimeMessageAnnouncementCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0366EAE02909A37800B51755 /* JustInTimeMessageAnnouncementCardViewModel.swift */; };
036CA6F129229C9E00E4DF4F /* IndefiniteCircularProgressViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036CA6F029229C9E00E4DF4F /* IndefiniteCircularProgressViewStyle.swift */; };
036CA6B9291E8D4B00E4DF4F /* CardPresentModalPreparingReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036CA6B8291E8D4B00E4DF4F /* CardPresentModalPreparingReader.swift */; };
036CA6F129229C9E00E4DF4F /* IndefiniteCircularProgressViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036CA6F029229C9E00E4DF4F /* IndefiniteCircularProgressViewStyle.swift */; };
Copy link
Contributor

Choose a reason for hiding this comment

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

It would seem we've inadvertently moved this file in the project structure? I can't see any other changes 🤔

Copy link
Contributor Author

@toupper toupper Nov 17, 2022

Choose a reason for hiding this comment

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

That was automatically done by Xcode when deleting UIImage+TintColor.swift , but please note that the order of the files in that pbxproj field doesn't match the order in the project structure, so I wouldn't worry about it.

036F6EA6281847D5006D84F8 /* PaymentCaptureOrchestratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 036F6EA5281847D5006D84F8 /* PaymentCaptureOrchestratorTests.swift */; };
0371C3682875E47B00277E2C /* FeatureAnnouncementCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0371C3672875E47B00277E2C /* FeatureAnnouncementCardViewModel.swift */; };
0371C36A2876DBCA00277E2C /* FeatureAnnouncementCardViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0371C3692876DBCA00277E2C /* FeatureAnnouncementCardViewModelTests.swift */; };
Expand Down Expand Up @@ -2103,7 +2102,6 @@
0236BCA325087B660043EB43 /* ProductFormRemoteActionUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductFormRemoteActionUseCaseTests.swift; sourceTree = "<group>"; };
023930602918F36400B2632F /* DomainSelectorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainSelectorView.swift; sourceTree = "<group>"; };
02393068291A065000B2632F /* DomainRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainRowView.swift; sourceTree = "<group>"; };
02396250239948470096F34C /* UIImage+TintColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+TintColor.swift"; sourceTree = "<group>"; };
023A059824135F2600E3FC99 /* ReviewsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewsViewController.swift; sourceTree = "<group>"; };
023A059924135F2600E3FC99 /* ReviewsViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ReviewsViewController.xib; sourceTree = "<group>"; };
023D1DD024AB2D05002B03A3 /* ProductListSelectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductListSelectorViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2433,8 +2431,8 @@
035C6DEA273EA12D00F70406 /* SoftwareUpdateTypeProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoftwareUpdateTypeProperty.swift; sourceTree = "<group>"; };
035F2307275690970019E1B0 /* CardPresentModalConnectingFailedUpdatePostalCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalConnectingFailedUpdatePostalCode.swift; sourceTree = "<group>"; };
0366EAE02909A37800B51755 /* JustInTimeMessageAnnouncementCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustInTimeMessageAnnouncementCardViewModel.swift; sourceTree = "<group>"; };
036CA6F029229C9E00E4DF4F /* IndefiniteCircularProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndefiniteCircularProgressViewStyle.swift; sourceTree = "<group>"; };
036CA6B8291E8D4B00E4DF4F /* CardPresentModalPreparingReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalPreparingReader.swift; sourceTree = "<group>"; };
036CA6F029229C9E00E4DF4F /* IndefiniteCircularProgressViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IndefiniteCircularProgressViewStyle.swift; sourceTree = "<group>"; };
036F6EA5281847D5006D84F8 /* PaymentCaptureOrchestratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentCaptureOrchestratorTests.swift; sourceTree = "<group>"; };
0371C3672875E47B00277E2C /* FeatureAnnouncementCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureAnnouncementCardViewModel.swift; sourceTree = "<group>"; };
0371C3692876DBCA00277E2C /* FeatureAnnouncementCardViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureAnnouncementCardViewModelTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7827,7 +7825,6 @@
039D948E276113490044EF38 /* UIView+SuperviewConstraints.swift */,
D88CA757237D1C27005D2F44 /* Ghost+Woo.swift */,
02784A02238B8BC800BDD6A8 /* UIView+Border.swift */,
02396250239948470096F34C /* UIImage+TintColor.swift */,
F997174323DC065900592D8E /* XLPagerStrip+AccessibilityIdentifier.swift */,
0215320A24231D5A003F2BBD /* UIStackView+Subviews.swift */,
029BFD4E24597D4B00FDDEEC /* UIButton+TitleAndImage.swift */,
Expand Down Expand Up @@ -10395,7 +10392,6 @@
45D1CF4723BAC89A00945A36 /* ProductTaxStatusListSelectorCommand.swift in Sources */,
453DBF9023882814006762A5 /* ProductImagesFlowLayout.swift in Sources */,
024DF30E23742A70006658FE /* AztecBoldFormatBarCommand.swift in Sources */,
02396251239948470096F34C /* UIImage+TintColor.swift in Sources */,
DEE6437826D8DAD900888A75 /* InProgressView.swift in Sources */,
0290E275238E4F8100B5C466 /* PaginatedListSelectorViewController.swift in Sources */,
B958A7D628B5310100823EEF /* URLOpener.swift in Sources */,
Expand Down