diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 3115b9142..4f5fe0735 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -160,10 +160,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) if ((self = [super initWithFrame:frame])) { [self.panGestureRecognizer addTarget:self action:@selector(handleCustomPan:)]; - // We intentionaly force `UIScrollView`s `semanticContentAttribute` to `LTR` here - // because this attribute affects a position of vertical scrollbar; we don't want this - // scrollbar flip because we also flip it with whole `UIScrollView` flip. - self.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; + if ([self respondsToSelector:@selector(setSemanticContentAttribute:)]) { + // We intentionaly force `UIScrollView`s `semanticContentAttribute` to `LTR` here + // because this attribute affects a position of vertical scrollbar; we don't want this + // scrollbar flip because we also flip it with whole `UIScrollView` flip. + self.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight; + } } return self; } diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index ba7f84342..21d7a71bc 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -128,12 +128,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:unused) { _reactLayoutDirection = layoutDirection; -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0 - self.semanticContentAttribute = - layoutDirection == UIUserInterfaceLayoutDirectionLeftToRight ? - UISemanticContentAttributeForceLeftToRight : - UISemanticContentAttributeForceRightToLeft; -#endif + if ([self respondsToSelector:@selector(setSemanticContentAttribute:)]) { + self.semanticContentAttribute = + layoutDirection == UIUserInterfaceLayoutDirectionLeftToRight ? + UISemanticContentAttributeForceLeftToRight : + UISemanticContentAttributeForceRightToLeft; + } } - (NSString *)accessibilityLabel diff --git a/React/Views/UIView+React.m b/React/Views/UIView+React.m index 84217a805..43502719f 100644 --- a/React/Views/UIView+React.m +++ b/React/Views/UIView+React.m @@ -89,23 +89,23 @@ - (UIUserInterfaceLayoutDirection)reactLayoutDirection { -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0 - return [UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute]; -#else - return [objc_getAssociatedObject(self, @selector(reactLayoutDirection)) integerValue]; -#endif + if ([self respondsToSelector:@selector(semanticContentAttribute)]) { + return [UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute]; + } else { + return [objc_getAssociatedObject(self, @selector(reactLayoutDirection)) integerValue]; + } } - (void)setReactLayoutDirection:(UIUserInterfaceLayoutDirection)layoutDirection { -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0 - self.semanticContentAttribute = - layoutDirection == UIUserInterfaceLayoutDirectionLeftToRight ? - UISemanticContentAttributeForceLeftToRight : - UISemanticContentAttributeForceRightToLeft; -#else - objc_setAssociatedObject(self, @selector(reactLayoutDirection), @(layoutDirection), OBJC_ASSOCIATION_RETAIN_NONATOMIC); -#endif + if ([self respondsToSelector:@selector(setSemanticContentAttribute:)]) { + self.semanticContentAttribute = + layoutDirection == UIUserInterfaceLayoutDirectionLeftToRight ? + UISemanticContentAttributeForceLeftToRight : + UISemanticContentAttributeForceRightToLeft; + } else { + objc_setAssociatedObject(self, @selector(reactLayoutDirection), @(layoutDirection), OBJC_ASSOCIATION_RETAIN_NONATOMIC); + } } - (NSInteger)reactZIndex