Skip to content

Conversation

@iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Nov 11, 2022

Description

By updating the minimum release version to iOS 15 recently, we've seen some deprecation warnings. This PR fixes the case for 'contentEdgeInsets' was deprecated in iOS 15.0: This property is ignored when using UIButtonConfiguration, for some cases.

Changes

  1. Updated the following classes to use UIButton.Configuration contentInsets
  • UIButton+Helpers
  • CustomerNoteTableViewCell
  • EmptyStateViewController
  • FilteredOrdersHeaderBar
  • SurveySubmittedViewController
  • VerticalButton
  1. Added titleLabel to subview for ButtonActivityIndicator due to an edge case encountered while testing: Using the new configuration approach made the app crash (and test fail) when we went through the card present payment flow if the titleLabel required to use multiline (pe: small screens, different languages, bigger system accessibility fonts, ... ). This is because we are calling pinSubViewsToAllEdgeMargins(_:) while label and button do not share the same ancestor for that specific case, getting this error:
'Unable to activate constraint with anchors <NSLayoutXAxisAnchor:0x600003f55700 "UILayoutGuide:0x600001334460'UIViewLayoutMarginsGuide'.leading"> and <NSLayoutXAxisAnchor:0x600003f55740 "UILabel:0x155d4f9a0.leading"> because they have no common ancestor.  
Does the constraint or its anchors reference items in different view hierarchies?  That's illegal.'

Testing instructions

Go to the following views and confirm that buttons appear correctly:

  1. Go to Orders > Filter
  2. Orders > For different Orders confirm that primary ("Mark Order as Completed") and secondary buttons ( "Issue Refund") appear correctly, as well as the "Add Customer Note" button
  3. Menu > Reviews > Confirm that spam, trash, approve, and reply buttons
  4. Menu > Settings > Send Feedback > Confirm the "Contact us here" button after feedback is sent

Screenshots

UIButton+Helpers CustomerNoteTableViewCell FilteredOrdersHeaderBar
SurveySubmittedViewController VerticalButton

@iamgabrielma iamgabrielma added type: enhancement A request for an enhancement. status: draft This is a draft, still need more work but can be reviewed and commented if asked. iOS 15 Specific to iOS 15 labels Nov 11, 2022
@iamgabrielma iamgabrielma added this to the 11.3 milestone Nov 11, 2022
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 11, 2022

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr8094-db0bd1d on your iPhone

If you need access to App Center, please ask a maintainer to add you.

By using UIButton.Configuration, calls to pinSubviewToAllEdgeMargins() make the app crash, as is illegal to activate constraints with anchors in different view hierarchies. By commenting this out temporarily, while buttons doesn’t look great if they have multiple lines, we avoid the app crash.
@iamgabrielma iamgabrielma removed the status: draft This is a draft, still need more work but can be reviewed and commented if asked. label Nov 16, 2022
Copy link
Contributor

@ealeksandrov ealeksandrov left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @iamgabrielma!
I've checked all impacted button types and it looks good!

The only misplaced button is "add customer" - it's missing padding between the image and the text label, but I see it's already fixed in #8129.

Added titleLabel to subview for ButtonActivityIndicator

There is a new subviews.contains check in the enableMultipleLines() helper. Shouldn't it already prevent the crash in ButtonActivityIndicator? Can you help me reproduce the issue that requires adding custom initializer?

static let defaultBorderWidth = CGFloat(1.0)
static let defaultEdgeInsets = UIEdgeInsets(top: 12, left: 22, bottom: 12, right: 22)
static let defaultVerticalInsets = CGFloat(12)
static let defaultHorizontalInsets = CGFloat(22)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since now it's a single value instead of UIEdgeInsets type, should we rename both constants to something like Inset or Padding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely! That reads much better. Changed on a6df43f along with the other nits 🙇

contactUsButton.applyLinkButtonStyle()
contactUsButton.titleLabel?.applyCalloutStyle()
contactUsButton.contentEdgeInsets = .zero
var contactUsconfiguration = UIButton.Configuration.plain()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
var contactUsconfiguration = UIButton.Configuration.plain()
var contactUsConfiguration = UIButton.Configuration.plain()

enum Settings {
static let cornerRadius = CGFloat(10)
static let edgeInsets = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 0)
static let horizontalEdgeInsets = CGFloat(5)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same as above, renaming single value to Inset or Padding can improve readability

@iamgabrielma
Copy link
Contributor Author

There is a new subviews.contains check in the enableMultipleLines() helper. Shouldn't it already prevent the crash in ButtonActivityIndicator? Can you help me reproduce the issue that requires adding custom initializer?

Thanks for the review! You're right, it does prevent the crash at this point 🤔 However, views that use ButtonActivityIndicator as button (like ButtonTableViewCell) will still not have their label added to the parent view, which I think could cause problems in the future and these don't have to be necessarily catch on compile time but when is already out there.

Would you say is best to remove the initializer from ButtonActivityIndicator? I have no strong opinion about it.

@iamgabrielma iamgabrielma modified the milestones: 11.3, 11.4 Nov 18, 2022
Copy link
Contributor

@ealeksandrov ealeksandrov left a comment

Choose a reason for hiding this comment

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

However, views that use ButtonActivityIndicator as button (like ButtonTableViewCell) will still not have their label added to the parent view, which I think could cause problems in the future and these don't have to be necessarily catch on compile time but when is already out there.

The question is: what problems can arise from that? The code we're discussing is about pinning the button's frame to the text. So breaking it can lead to the text overflow out of the button's bounds. I don't see any cases of that and wasn't able to reproduce it in IssueRefundViewController with ButtonActivityIndicator.

On other hand, manipulating with UIButton view hierarchy can bite us back. It's not defined in the documentation, so Apple is free to change it in any updates. And the titleLabel is read-only:

Although this property is read-only, its own properties are read/write. Use these properties primarily to configure the text of the button.

So I'm leaning towards removing custom init and keeping an eye on custom buttons to make sure our helpers don't break. When we find broken buttons, then we can work on case-by-case basis, fixing those helpers/subclasses/views.

What do you think?

@peril-woocommerce
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 2 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

@iamgabrielma
Copy link
Contributor Author

So I'm leaning towards removing custom init and keeping an eye on custom buttons to make sure our helpers don't break. When we find broken buttons, then we can work on case-by-case basis, fixing those helpers/subclasses/views.

Thanks for the explanation, that makes sense 🙇 Init removed on db0bd1d

Copy link
Contributor

@ealeksandrov ealeksandrov left a comment

Choose a reason for hiding this comment

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

Thank you for the significant refactoring! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iOS 15 Specific to iOS 15 type: enhancement A request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants