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

Refactor: Remove flipInsetsForRightToLeftLayoutDirection #23811

Merged
merged 2 commits into from
Nov 15, 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
23 changes: 0 additions & 23 deletions WordPress/Classes/Extensions/UIEdgeInsets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,10 @@ extension UIEdgeInsets {
guard UIApplication.shared.userInterfaceLayoutDirection == .rightToLeft else {
return self
}

return flippedForRightToLeftLayoutDirection()
}

func flippedForRightToLeftLayoutDirection() -> UIEdgeInsets {
return UIEdgeInsets(top: top, left: right, bottom: bottom, right: left)
}
}

extension UIButton {

@objc func flipInsetsForRightToLeftLayoutDirection() {
guard userInterfaceLayoutDirection() == .rightToLeft else {
return
}
contentEdgeInsets = contentEdgeInsets.flippedForRightToLeftLayoutDirection()
imageEdgeInsets = imageEdgeInsets.flippedForRightToLeftLayoutDirection()
titleEdgeInsets = titleEdgeInsets.flippedForRightToLeftLayoutDirection()
}
}

// Hack: Since UIEdgeInsets is a struct in ObjC, you can't have methods on it.
// You can't also export top level functions from Swift.
// 🙄
@objc(InsetsHelper)
class _InsetsHelper: NSObject {
@objc static func flipForRightToLeftLayoutDirection(_ insets: UIEdgeInsets) -> UIEdgeInsets {
return insets.flippedForRightToLeftLayoutDirection()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ private extension CommentContentTableViewCell {
replyButton?.setTitleColor(Style.reactionButtonTextColor, for: .normal)
replyButton?.setImage(Style.replyIconImage, for: .normal)
replyButton?.addTarget(self, action: #selector(replyButtonTapped), for: .touchUpInside)
replyButton?.flipInsetsForRightToLeftLayoutDirection()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This had no effect because the buttons are vertical.
The layout is a bit broken. I reported it here #23812.

Screenshot 2024-11-14 at 4 19 13 PM

replyButton?.adjustsImageSizeForAccessibilityContentSizeCategory = true
adjustImageAndTitleEdgeInsets(for: replyButton)
replyButton?.sizeToFit()
Expand All @@ -397,7 +396,6 @@ private extension CommentContentTableViewCell {
likeButton?.titleLabel?.adjustsFontForContentSizeCategory = true
likeButton?.setTitleColor(Style.reactionButtonTextColor, for: .normal)
likeButton?.addTarget(self, action: #selector(likeButtonTapped), for: .touchUpInside)
likeButton?.flipInsetsForRightToLeftLayoutDirection()
likeButton?.adjustsImageSizeForAccessibilityContentSizeCategory = true
adjustImageAndTitleEdgeInsets(for: likeButton)
updateLikeButton(liked: false, numberOfLikes: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class JetpackButton: CircularImageButton {
imageEdgeInsets = Appearance.iconInsets
contentEdgeInsets = Appearance.contentInsets
imageView?.contentMode = .scaleAspectFit
flipInsetsForRightToLeftLayoutDirection()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't have screenshots, but it should be OK.
I'm planning to remove the remaining usages of JetpackButton next week together with sone of the Jetpack migration code.

setImageBackgroundColor(imageBackgroundColor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class ReaderDetailToolbar: UIView, NibLoadable {

applyStyles()

adjustInsetsForTextDirection()

prepareActionButtonsForVoiceOver()
}

Expand Down Expand Up @@ -376,17 +374,6 @@ class ReaderDetailToolbar: UIView, NibLoadable {
configureActionButtonStyle(saveForLaterButton)
}

private func adjustInsetsForTextDirection() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change also had no effect because these button are vertical.

Screenshot 2024-11-14 at 4 18 50 PM

let buttonsToAdjust: [UIButton] = [
likeButton,
commentButton,
saveForLaterButton,
reblogButton]
for button in buttonsToAdjust {
button.flipInsetsForRightToLeftLayoutDirection()
}
}

fileprivate func configureButtonTitles() {
let commentTitle = Constants.commentButtonTitle

Expand Down