-
Notifications
You must be signed in to change notification settings - Fork 121
Fix 'contentEdgeInsets' was deprecated in iOS 15.0 #8094
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
Fix 'contentEdgeInsets' was deprecated in iOS 15.0 #8094
Conversation
You can test the changes from this Pull Request by:
|
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.
By adding the UILabel as subview to the UIButton explicitely we avoid a crash on pinSubviewToAllEdgeMargins(_:) due not sharing a common ancestor.
ealeksandrov
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| 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) |
There was a problem hiding this comment.
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
Thanks for the review! You're right, it does prevent the crash at this point 🤔 However, views that use Would you say is best to remove the initializer from |
ealeksandrov
left a comment
There was a problem hiding this 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?
Generated by 🚫 dangerJS |
Thanks for the explanation, that makes sense 🙇 Init removed on db0bd1d |
ealeksandrov
left a comment
There was a problem hiding this 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! 🚀
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
UIButton.ConfigurationcontentInsetsButtonActivityIndicatordue 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:Testing instructions
Go to the following views and confirm that buttons appear correctly:
Screenshots