From 5f8b44fd227e20fc51bc16de80d6582adf78fc7b Mon Sep 17 00:00:00 2001 From: Ziqi Chen Date: Thu, 28 Jun 2018 11:56:53 -0700 Subject: [PATCH] added check for iOS 11 on ignore inverted colors Summary: Added Check for iOS 11 before setting property for `accessibilityIgnoreInvertColor` Builds on top of https://our.intern.facebook.com/intern/diff/D8549084/ Reviewed By: shergin Differential Revision: D8599698 fbshipit-source-id: c5cc26b4c1c20fb9cca5bfe7143fa9dcb217a2d7 --- React/Views/RCTViewManager.m | 1 + React/Views/UIView+React.h | 6 ++++++ React/Views/UIView+React.m | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 626e923d35e5db..ede084d1a5fb8b 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -112,6 +112,7 @@ - (RCTShadowView *)shadowView RCT_REMAP_VIEW_PROPERTY(accessibilityTraits, reactAccessibilityElement.accessibilityTraits, UIAccessibilityTraits) RCT_REMAP_VIEW_PROPERTY(accessibilityViewIsModal, reactAccessibilityElement.accessibilityViewIsModal, BOOL) RCT_REMAP_VIEW_PROPERTY(accessibilityElementsHidden, reactAccessibilityElement.accessibilityElementsHidden, BOOL) +RCT_REMAP_VIEW_PROPERTY(accessibilityIgnoresInvertColors, reactAccessibilityElement.shouldAccessibilityIgnoresInvertColors, BOOL) RCT_REMAP_VIEW_PROPERTY(onAccessibilityAction, reactAccessibilityElement.onAccessibilityAction, RCTDirectEventBlock) RCT_REMAP_VIEW_PROPERTY(onAccessibilityTap, reactAccessibilityElement.onAccessibilityTap, RCTDirectEventBlock) RCT_REMAP_VIEW_PROPERTY(onMagicTap, reactAccessibilityElement.onMagicTap, RCTDirectEventBlock) diff --git a/React/Views/UIView+React.h b/React/Views/UIView+React.h index 94de7aae753130..3d0ac2c5af7a57 100644 --- a/React/Views/UIView+React.h +++ b/React/Views/UIView+React.h @@ -27,6 +27,12 @@ */ @property (nonatomic, copy) NSString *nativeID; +/** + * Determines whether or not a view should ignore inverted colors or not. Used to set + * UIView property accessibilityIgnoresInvertColors in iOS 11+. + */ +@property (nonatomic, assign) BOOL shouldAccessibilityIgnoresInvertColors; + /** * Layout direction of the view. * Internally backed to `semanticContentAttribute` property. diff --git a/React/Views/UIView+React.m b/React/Views/UIView+React.m index 22d14f82c4a334..613083b4c44027 100644 --- a/React/Views/UIView+React.m +++ b/React/Views/UIView+React.m @@ -35,6 +35,25 @@ - (void)setNativeID:(NSNumber *)nativeID objc_setAssociatedObject(self, @selector(nativeID), nativeID, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } +- (BOOL)shouldAccessibilityIgnoresInvertColors +{ +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ + if (@available(iOS 11.0, *)) { + return self.accessibilityIgnoresInvertColors; + } +#endif + return NO; +} + +- (void)setShouldAccessibilityIgnoresInvertColors:(BOOL)shouldAccessibilityIgnoresInvertColors +{ +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ + if (@available(iOS 11.0, *)) { + self.accessibilityIgnoresInvertColors = shouldAccessibilityIgnoresInvertColors; + } +#endif +} + - (BOOL)isReactRootView { return RCTIsReactRootView(self.reactTag);