RTL support
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?
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.
Interesting, I didn't know about semanticContentAttribute. 🤔
So maybe besides ditching the property, _shouldFlip should return YES if:
-
[UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeftOR -
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?
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.
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:
-
effectiveUserInterfaceLayoutDirectionon iOS >= 10, -
userInterfaceLayoutDirectionForSemanticContentAttribute:for iOS >= 9 and -
[UIApplication sharedApplication].userInterfaceLayoutDirectionfor 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!