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

RTL support #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

nickolas-pohilets
Copy link

Hello, I've added support for flipping control for RTL languages, and fixed couple compiler warnings. Let me know if you have any comments.

Could you pls merge in back and bump version in the podspec?

Copy link
Owner

@hsousa hsousa left a comment

Choose a reason for hiding this comment

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

Hi @nickolas-pohilets! Thanks a lot for this addition, and sorry I'm only answering now! 😞

Overall code LGTM, but I don't see any reason to have a property to toggle RTL (it's a system setting and if we support it, we should always respect it). What are your thoughts about removing it?

@nickolas-pohilets
Copy link
Author

I don't have any objections to remove the property - in my code I'm always setting it to YES.
I've added property for backward compatibility with existing code.

Also there is already a property semanticContentAttribute in UIView. Probably using that one would be the better approach.

@hsousa
Copy link
Owner

hsousa commented Nov 12, 2016

Interesting, I didn't know about semanticContentAttribute. 🤔

So maybe besides ditching the property, _shouldFlip should return YES if:

  • [UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft OR
  • self.semanticContentAttribute == UISemanticContentAttributeForceRightToLeft

That would cover automatically flipping the content when a user has the device in a RTL language, but also if someone decides he wants to manually force the direction.

What do you think?

@nickolas-pohilets
Copy link
Author

If self.semanticContentAttribute == UISemanticContentAttributeForceLeftToRight, then _shouldFlip should return NO regardless of [UIApplication sharedApplication].userInterfaceLayoutDirection.

Starting from iOS 10, there is a nice property:
@property (readonly, nonatomic) UIUserInterfaceLayoutDirection effectiveUserInterfaceLayoutDirection which computes layout direction with respect to:

  • self.semanticContentAttribute
  • self.traitCollection. layoutDirection
  • UIApplication.sharedApplication.userInterfaceLayoutDirection

Starting from iOS 9, there is a class method +[UIView userInterfaceLayoutDirectionForSemanticContentAttribute:] that does not take self.traitCollection.layoutDirection into account.

Before iOS 9, semantic content does not exists, so I think just [UIApplication sharedApplication].userInterfaceLayoutDirection can be used.

@hsousa
Copy link
Owner

hsousa commented Nov 13, 2016

Hi again! Wow, thanks a lot for the rich information on this subject! 😍

So it sounds like we should use _shouldFlip internally and inside that decide what to return based on API availability/OS version:

  • effectiveUserInterfaceLayoutDirection on iOS >= 10,
  • userInterfaceLayoutDirectionForSemanticContentAttribute: for iOS >= 9 and
  • [UIApplication sharedApplication].userInterfaceLayoutDirection for iOS < 9.

Or do you think it's also worth it to validate self.traitCollection.layoutDirection on iOS 9?

Thanks for helping out with this and for the great followup!

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

Successfully merging this pull request may close these issues.

2 participants