From 398595e07483fa8f45579de4ca1aee9585e20620 Mon Sep 17 00:00:00 2001 From: Ken Tominaga Date: Wed, 22 Sep 2021 10:35:29 -0700 Subject: [PATCH] Remove iOS 11 version check (#32151) Summary: This pull request aims to remove iOS 11 version check which is no longer needed. The minimum iOS deployment target for React Native is `iOS 11` but we still have iOS 11 version check like below. ``` #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ if (available(iOS 11.0, *)) { ``` > React Native apps may target iOS 11.0 and Android 5.0 (API 21) or newer. ref: https://github.com/facebook/react-native#-requirements ------ If there is a team motivation to remove the deprecated methods and classes before iOS 10, I can continue the work in this pull request or in the continuing pull requests. We have deprecated warnings for these in the project. - `UIUserNotificationSettings` - `UILocalNotification` - `topLayoutGuide` and `bottomLayoutGuide` - `automaticallyAdjustsScrollViewInsets` ## Changelog [iOS] [Changed] - Remove iOS 11 version check Pull Request resolved: https://github.com/facebook/react-native/pull/32151 Reviewed By: sammy-SC Differential Revision: D30877917 Pulled By: yungsters fbshipit-source-id: d903ea5d557beeb65ef87bfce572e4db3532b3c5 --- .../RCTPushNotificationManager.mm | 1 - .../Text/TextInput/RCTBaseTextInputView.m | 14 ++----------- .../TextInput/RCTInputAccessoryViewContent.m | 15 ++++---------- React/Base/RCTConvert.h | 2 +- React/CoreModules/RCTDevLoadingView.mm | 13 +++--------- React/CoreModules/RCTRedBox.mm | 6 +----- .../View/RCTViewComponentView.mm | 6 +----- React/Views/RCTView.m | 7 +------ React/Views/SafeAreaView/RCTSafeAreaView.m | 6 +----- React/Views/ScrollView/RCTScrollView.m | 20 +++++-------------- React/Views/ScrollView/RCTScrollViewManager.m | 7 ------- React/Views/UIView+React.m | 13 ++---------- 12 files changed, 21 insertions(+), 89 deletions(-) diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm index 3924fd64e2387b..57ce100178579c 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm @@ -103,7 +103,6 @@ @implementation RCTPushNotificationManager return formattedLocalNotification; } -API_AVAILABLE(ios(10.0)) static NSDictionary *RCTFormatUNNotification(UNNotification *notification) { NSMutableDictionary *formattedNotification = [NSMutableDictionary dictionary]; diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 9965f9ca2972c0..d75f140c9d2165 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -242,20 +242,10 @@ - (void)setTextContentType:(NSString *)type @"streetAddressLine2": UITextContentTypeStreetAddressLine2, @"sublocality": UITextContentTypeSublocality, @"telephoneNumber": UITextContentTypeTelephoneNumber, + @"username": UITextContentTypeUsername, + @"password": UITextContentTypePassword, }; - #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ - if (@available(iOS 11.0, *)) { - NSDictionary * iOS11extras = @{@"username": UITextContentTypeUsername, - @"password": UITextContentTypePassword}; - - NSMutableDictionary * iOS11baseMap = [contentTypeMap mutableCopy]; - [iOS11baseMap addEntriesFromDictionary:iOS11extras]; - - contentTypeMap = [iOS11baseMap copy]; - } - #endif - #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000 /* __IPHONE_12_0 */ if (@available(iOS 12.0, *)) { NSDictionary * iOS12extras = @{@"newPassword": UITextContentTypeNewPassword, diff --git a/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m b/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m index 35db4d308733c4..22a718631c78dc 100644 --- a/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m +++ b/Libraries/Text/TextInput/RCTInputAccessoryViewContent.m @@ -30,17 +30,10 @@ - (instancetype)init _heightConstraint = [_safeAreaContainer.heightAnchor constraintEqualToConstant:0]; _heightConstraint.active = YES; - if (@available(iOS 11.0, *)) { - [_safeAreaContainer.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor].active = YES; - [_safeAreaContainer.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor].active = YES; - [_safeAreaContainer.leadingAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.leadingAnchor].active = YES; - [_safeAreaContainer.trailingAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.trailingAnchor].active = YES; - } else { - [_safeAreaContainer.bottomAnchor constraintEqualToAnchor:self.bottomAnchor].active = YES; - [_safeAreaContainer.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES; - [_safeAreaContainer.leadingAnchor constraintEqualToAnchor:self.leadingAnchor].active = YES; - [_safeAreaContainer.trailingAnchor constraintEqualToAnchor:self.trailingAnchor].active = YES; - } + [_safeAreaContainer.bottomAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.bottomAnchor].active = YES; + [_safeAreaContainer.topAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.topAnchor].active = YES; + [_safeAreaContainer.leadingAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.leadingAnchor].active = YES; + [_safeAreaContainer.trailingAnchor constraintEqualToAnchor:self.safeAreaLayoutGuide.trailingAnchor].active = YES; } return self; } diff --git a/React/Base/RCTConvert.h b/React/Base/RCTConvert.h index 1137788402b12b..09a380e84dd5bc 100644 --- a/React/Base/RCTConvert.h +++ b/React/Base/RCTConvert.h @@ -74,7 +74,7 @@ typedef NSURL RCTFileURL; #endif #if TARGET_OS_IPHONE -+ (WKDataDetectorTypes)WKDataDetectorTypes:(id)json API_AVAILABLE(ios(10.0)); ++ (WKDataDetectorTypes)WKDataDetectorTypes:(id)json; #endif + (UIViewContentMode)UIViewContentMode:(id)json; diff --git a/React/CoreModules/RCTDevLoadingView.mm b/React/CoreModules/RCTDevLoadingView.mm index 662eaa48c69c83..dd2a30352e7d69 100644 --- a/React/CoreModules/RCTDevLoadingView.mm +++ b/React/CoreModules/RCTDevLoadingView.mm @@ -114,16 +114,9 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:( if (!self->_window && !RCTRunningInTestEnvironment()) { CGSize screenSize = [UIScreen mainScreen].bounds.size; - if (@available(iOS 11.0, *)) { - UIWindow *window = RCTSharedApplication().keyWindow; - self->_window = - [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, window.safeAreaInsets.top + 10)]; - self->_label = - [[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top - 10, screenSize.width, 20)]; - } else { - self->_window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, 20)]; - self->_label = [[UILabel alloc] initWithFrame:self->_window.bounds]; - } + UIWindow *window = RCTSharedApplication().keyWindow; + self->_window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, window.safeAreaInsets.top + 10)]; + self->_label = [[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top - 10, screenSize.width, 20)]; [self->_window addSubview:self->_label]; self->_window.windowLevel = UIWindowLevelStatusBar + 1; diff --git a/React/CoreModules/RCTRedBox.mm b/React/CoreModules/RCTRedBox.mm index 943a7e36e65b66..8a4f6573ed09ef 100644 --- a/React/CoreModules/RCTRedBox.mm +++ b/React/CoreModules/RCTRedBox.mm @@ -201,11 +201,7 @@ - (UIButton *)redBoxButton:(NSString *)title - (NSInteger)bottomSafeViewHeight { - if (@available(iOS 11.0, *)) { - return RCTSharedApplication().delegate.window.safeAreaInsets.bottom; - } else { - return 0; - } + return RCTSharedApplication().delegate.window.safeAreaInsets.bottom; } RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder) diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 3136efccc6b3e0..2b9d5381adb020 100644 --- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -331,11 +331,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & // `accessibilityIgnoresInvertColors` if (oldViewProps.accessibilityIgnoresInvertColors != newViewProps.accessibilityIgnoresInvertColors) { -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ - if (@available(iOS 11.0, *)) { - self.accessibilityIgnoresInvertColors = newViewProps.accessibilityIgnoresInvertColors; - } -#endif + self.accessibilityIgnoresInvertColors = newViewProps.accessibilityIgnoresInvertColors; } // `accessibilityValue` diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index c4b9a25438784f..e2cdef652ad097 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -276,12 +276,7 @@ - (NSString *)accessibilityValue if (bundle) { NSURL *url = [bundle URLForResource:@"Localizable" withExtension:@"strings"]; - if (@available(iOS 11.0, *)) { - rolesAndStatesDescription = [NSDictionary dictionaryWithContentsOfURL:url error:nil]; - } else { - // Fallback on earlier versions - rolesAndStatesDescription = [NSDictionary dictionaryWithContentsOfURL:url]; - } + rolesAndStatesDescription = [NSDictionary dictionaryWithContentsOfURL:url error:nil]; } if (rolesAndStatesDescription == nil) { // Falling back to hardcoded English list. diff --git a/React/Views/SafeAreaView/RCTSafeAreaView.m b/React/Views/SafeAreaView/RCTSafeAreaView.m index d8e1be97b90755..93ca0423a0b8a0 100644 --- a/React/Views/SafeAreaView/RCTSafeAreaView.m +++ b/React/Views/SafeAreaView/RCTSafeAreaView.m @@ -52,13 +52,9 @@ - (BOOL)isSupportedByOS - (UIEdgeInsets)safeAreaInsetsIfSupportedAndEnabled { -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ if (self.isSupportedByOS) { - if (@available(iOS 11.0, *)) { - return self.safeAreaInsets; - } + return self.safeAreaInsets; } -#endif return self.emulateUnlessSupported ? self.emulatedSafeAreaInsets : UIEdgeInsetsZero; } diff --git a/React/Views/ScrollView/RCTScrollView.m b/React/Views/ScrollView/RCTScrollView.m index 5fa44b56bd8d92..eb8f90e1cd9351 100644 --- a/React/Views/ScrollView/RCTScrollView.m +++ b/React/Views/ScrollView/RCTScrollView.m @@ -197,10 +197,8 @@ - (void)setFrame:(CGRect)frame if (CGSizeEqualToSize(contentSize, CGSizeZero)) { self.contentOffset = originalOffset; } else { - if (@available(iOS 11.0, *)) { - if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, self.adjustedContentInset)) { - contentInset = self.adjustedContentInset; - } + if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, self.adjustedContentInset)) { + contentInset = self.adjustedContentInset; } CGSize boundsSize = self.bounds.size; CGFloat xMaxOffset = contentSize.width - boundsSize.width + contentInset.right; @@ -287,17 +285,13 @@ - (instancetype)initWithEventDispatcher:(id)eventDis _scrollView.delegate = self; _scrollView.delaysContentTouches = NO; -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ // `contentInsetAdjustmentBehavior` is only available since iOS 11. // We set the default behavior to "never" so that iOS // doesn't do weird things to UIScrollView insets automatically // and keeps it as an opt-in behavior. if ([_scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) { - if (@available(iOS 11.0, *)) { - _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; - } + _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } -#endif _automaticallyAdjustContentInsets = YES; _contentInset = UIEdgeInsetsZero; @@ -940,19 +934,15 @@ - (void)setAutomaticallyAdjustsScrollIndicatorInsets:(BOOL)automaticallyAdjusts } #endif -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ -- (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBehavior)behavior API_AVAILABLE(ios(11.0)) +- (void)setContentInsetAdjustmentBehavior:(UIScrollViewContentInsetAdjustmentBehavior)behavior { // `contentInsetAdjustmentBehavior` is available since iOS 11. if ([_scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) { CGPoint contentOffset = _scrollView.contentOffset; - if (@available(iOS 11.0, *)) { - _scrollView.contentInsetAdjustmentBehavior = behavior; - } + _scrollView.contentInsetAdjustmentBehavior = behavior; _scrollView.contentOffset = contentOffset; } } -#endif - (void)sendScrollEventWithName:(NSString *)eventName scrollView:(UIScrollView *)scrollView diff --git a/React/Views/ScrollView/RCTScrollViewManager.m b/React/Views/ScrollView/RCTScrollViewManager.m index 41973b0515ceac..bd5573f6a55808 100644 --- a/React/Views/ScrollView/RCTScrollViewManager.m +++ b/React/Views/ScrollView/RCTScrollViewManager.m @@ -36,9 +36,6 @@ @implementation RCTConvert (UIScrollView) UIScrollViewIndicatorStyleDefault, integerValue) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunguarded-availability-new" -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ RCT_ENUM_CONVERTER( UIScrollViewContentInsetAdjustmentBehavior, (@{ @@ -49,8 +46,6 @@ @implementation RCTConvert (UIScrollView) }), UIScrollViewContentInsetAdjustmentNever, integerValue) -#endif -#pragma clang diagnostic pop @end @@ -105,9 +100,7 @@ - (UIView *)view #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 /* __IPHONE_13_0 */ RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustsScrollIndicatorInsets, BOOL) #endif -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ RCT_EXPORT_VIEW_PROPERTY(contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentBehavior) -#endif // overflow is used both in css-layout as well as by react-native. In css-layout // we always want to treat overflow as scroll but depending on what the overflow diff --git a/React/Views/UIView+React.m b/React/Views/UIView+React.m index 60b30d9a111b1f..ffe1e02bfa4589 100644 --- a/React/Views/UIView+React.m +++ b/React/Views/UIView+React.m @@ -47,21 +47,12 @@ - (void)setNativeID:(NSString *)nativeID - (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; + return self.accessibilityIgnoresInvertColors; } - (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 + self.accessibilityIgnoresInvertColors = shouldAccessibilityIgnoresInvertColors; } - (BOOL)isReactRootView