From 54d3e83bbfdb26281e08d54f32324b734d2e8889 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 3 Feb 2017 15:13:36 -0800 Subject: [PATCH] Fixed crash in RCTScrollView on iOS 8 Reviewed By: javache Differential Revision: D4508906 fbshipit-source-id: 08955f338879f708d35f4784e858a92b542e8661 --- React/Views/RCTScrollView.m | 10 ++++++---- React/Views/RCTView.m | 12 ++++++------ React/Views/UIView+React.m | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 23 deletions(-) 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