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

Implementations of trailingToSuperview and leadingToSuperview only work correct only for Left-to-Right languages / layout. #95

Open
therohansanap opened this issue Apr 24, 2021 · 2 comments

Comments

@therohansanap
Copy link

What layout do I expect?

I want my signupButton to have it's trailing edge 20 points before safeAreaLayoutGuide.centerXAnchor. Similarly, I want my loginButton to have its leading edge 20 points after safeAreaLayoutGuide.centerXAnchor. Below image displays the layout in desired state:
LTR
Left-to-Right Layout 👆🏾
RTL-correct
Right-to-Left Layout 👆🏾

What does my code looks like?

let signupButton = UIButton(type: .system)
signupButton.setTitle("Signup", for: .normal)
view.addSubview(signupButton)
signupButton.bottomToSuperview(offset: -50)
signupButton.trailingToSuperview(view.safeAreaLayoutGuide.centerXAnchor, offset: 20)

let loginButton = UIButton(type: .system)
loginButton.setTitle("Login", for: .normal)
view.addSubview(loginButton)
loginButton.bottomToSuperview(offset: -50)
loginButton.leadingToSuperview(view.safeAreaLayoutGuide.centerXAnchor, offset: 20)

What output do I get with above code?

Below are the screenshots of my output:
LTR
Left-to-Right Layout 👆🏾
RTL-bug
Right-to-Left Layout 👆🏾

The problem

It looks like the way superview methods are implemented, they work correct only for Left-to-Right language / layout direction.

@petrkahanek
Copy link

petrkahanek commented Mar 6, 2023

Well, I have been using ternary operator in order to pass proper values for RTL (myRandomImageView.leadingToSuperview(offset: isRTL ? -11 : 11)). But now I realized it's not the best approach as it can be fixed in the future. So the layout would get "broken" for RTL languages again. So better is to go with leading(to:) / trailing(to:) methods.

@sonmezvolkan
Copy link

Hi @petrkahanek

I created a pull request for this issue

#108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants