HCSStarRatingView icon indicating copy to clipboard operation
HCSStarRatingView copied to clipboard

RTL support

Open nickolas-pohilets opened this issue 9 years ago • 4 comments

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?

nickolas-pohilets avatar Aug 19 '16 09:08 nickolas-pohilets

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.

nickolas-pohilets avatar Nov 07 '16 14:11 nickolas-pohilets

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?

hsousa avatar Nov 12 '16 09:11 hsousa

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.

nickolas-pohilets avatar Nov 13 '16 14:11 nickolas-pohilets

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!

hsousa avatar Nov 13 '16 20:11 hsousa