From 58a6a40eac9afb5c4de78a63418cc48ea97da1a4 Mon Sep 17 00:00:00 2001 From: Kevin Gozali Date: Wed, 15 Jan 2020 09:21:20 -0800 Subject: [PATCH] Re-land [RN] iOS - deprecate iOS 9 support by removing runtime checks for 10.0+ Summary: Re-landing the reverted change: This removes all callsites that rely on runtime checks to detect the target deployment version. We no longer need to check for iOS 10+ in a few places. Note: for this to compile, the hosting app needs to target iOS 10.0+. Changelog: [iOS] [Deprecated] - Deprecate iOS 9 Reviewed By: sammy-SC Differential Revision: D19411136 fbshipit-source-id: ec0a957dc57819f0ee7d138c858209cabe3e5102 --- Libraries/LinkingIOS/RCTLinkingManager.mm | 56 ++------ .../RCTPushNotificationManager.mm | 33 ++--- .../Text/TextInput/RCTBaseTextInputView.m | 121 +++++++++--------- React/Base/RCTConvert.m | 11 +- .../RCTPullToRefreshViewComponentView.mm | 4 +- 5 files changed, 87 insertions(+), 138 deletions(-) diff --git a/Libraries/LinkingIOS/RCTLinkingManager.mm b/Libraries/LinkingIOS/RCTLinkingManager.mm index 85b9aa7a0bd0ec..2ad1c627e991db 100644 --- a/Libraries/LinkingIOS/RCTLinkingManager.mm +++ b/Libraries/LinkingIOS/RCTLinkingManager.mm @@ -99,30 +99,8 @@ - (void)handleOpenURLNotification:(NSNotification *)notification resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - if (@available(iOS 10.0, *)) { - [RCTSharedApplication() openURL:URL options:@{} completionHandler:^(BOOL success) { - if (success) { - resolve(@YES); - } else { - #if TARGET_OS_SIMULATOR - // Simulator-specific code - if([URL.absoluteString hasPrefix:@"tel:"]){ - RCTLogWarn(@"Unable to open the Phone app in the simulator for telephone URLs. URL: %@", URL); - resolve(@NO); - } else { - reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); - } - #else - // Device-specific code - reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); - #endif - } - }]; - } else { -#if !TARGET_OS_UIKITFORMAC - // Note: this branch will never be taken on UIKitForMac - BOOL opened = [RCTSharedApplication() openURL:URL]; - if (opened) { + [RCTSharedApplication() openURL:URL options:@{} completionHandler:^(BOOL success) { + if (success) { resolve(@YES); } else { #if TARGET_OS_SIMULATOR @@ -138,9 +116,7 @@ - (void)handleOpenURLNotification:(NSNotification *)notification reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); #endif } -#endif - } - + }]; } RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL @@ -193,25 +169,13 @@ - (void)handleOpenURLNotification:(NSNotification *)notification reject:(__unused RCTPromiseRejectBlock)reject) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; - if (@available(iOS 10.0, *)) { - [RCTSharedApplication() openURL:url options:@{} completionHandler:^(BOOL success) { - if (success) { - resolve(nil); - } else { - reject(RCTErrorUnspecified, @"Unable to open app settings", nil); - } - }]; - } else { -#if !TARGET_OS_UIKITFORMAC - // Note: This branch will never be taken on UIKitForMac - BOOL opened = [RCTSharedApplication() openURL:url]; - if (opened) { - resolve(nil); - } else { - reject(RCTErrorUnspecified, @"Unable to open app settings", nil); - } -#endif - } + [RCTSharedApplication() openURL:url options:@{} completionHandler:^(BOOL success) { + if (success) { + resolve(nil); + } else { + reject(RCTErrorUnspecified, @"Unable to open app settings", nil); + } + }]; } RCT_EXPORT_METHOD(sendIntent:(NSString *)action diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm index c6465bd7189f64..b2ba94d497bef0 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm @@ -472,36 +472,27 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification RCT_EXPORT_METHOD(removeAllDeliveredNotifications) { - // TODO: T56867629 - if (@available(iOS 10.0, tvOS 10.0, *)) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center removeAllDeliveredNotifications]; - } + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center removeAllDeliveredNotifications]; } RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSArray *)identifiers) { - // TODO: T56867629 - if (@available(iOS 10.0, tvOS 10.0, *)) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center removeDeliveredNotificationsWithIdentifiers:identifiers]; - } + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center removeDeliveredNotificationsWithIdentifiers:identifiers]; } RCT_EXPORT_METHOD(getDeliveredNotifications:(RCTResponseSenderBlock)callback) { - // TODO: T56867629 - if (@available(iOS 10.0, tvOS 10.0, *)) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center getDeliveredNotificationsWithCompletionHandler:^(NSArray *_Nonnull notifications) { - NSMutableArray *formattedNotifications = [NSMutableArray new]; + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center getDeliveredNotificationsWithCompletionHandler:^(NSArray *_Nonnull notifications) { + NSMutableArray *formattedNotifications = [NSMutableArray new]; - for (UNNotification *notification in notifications) { - [formattedNotifications addObject:RCTFormatUNNotification(notification)]; - } - callback(@[formattedNotifications]); - }]; - } + for (UNNotification *notification in notifications) { + [formattedNotifications addObject:RCTFormatUNNotification(notification)]; + } + callback(@[formattedNotifications]); + }]; } #else //TARGET_OS_TV / TARGET_OS_UIKITFORMAC diff --git a/Libraries/Text/TextInput/RCTBaseTextInputView.m b/Libraries/Text/TextInput/RCTBaseTextInputView.m index 5a15e8fe641e1a..c61279893f0ad0 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -194,68 +194,65 @@ - (void)setSelection:(RCTTextSelection *)selection - (void)setTextContentType:(NSString *)type { - #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 - if (@available(iOS 10.0, *)) { - - static dispatch_once_t onceToken; - static NSDictionary *contentTypeMap; - - dispatch_once(&onceToken, ^{ - contentTypeMap = @{@"none": @"", - @"URL": UITextContentTypeURL, - @"addressCity": UITextContentTypeAddressCity, - @"addressCityAndState":UITextContentTypeAddressCityAndState, - @"addressState": UITextContentTypeAddressState, - @"countryName": UITextContentTypeCountryName, - @"creditCardNumber": UITextContentTypeCreditCardNumber, - @"emailAddress": UITextContentTypeEmailAddress, - @"familyName": UITextContentTypeFamilyName, - @"fullStreetAddress": UITextContentTypeFullStreetAddress, - @"givenName": UITextContentTypeGivenName, - @"jobTitle": UITextContentTypeJobTitle, - @"location": UITextContentTypeLocation, - @"middleName": UITextContentTypeMiddleName, - @"name": UITextContentTypeName, - @"namePrefix": UITextContentTypeNamePrefix, - @"nameSuffix": UITextContentTypeNameSuffix, - @"nickname": UITextContentTypeNickname, - @"organizationName": UITextContentTypeOrganizationName, - @"postalCode": UITextContentTypePostalCode, - @"streetAddressLine1": UITextContentTypeStreetAddressLine1, - @"streetAddressLine2": UITextContentTypeStreetAddressLine2, - @"sublocality": UITextContentTypeSublocality, - @"telephoneNumber": UITextContentTypeTelephoneNumber, - }; - - #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ - if (@available(iOS 11.0, tvOS 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, tvOS 12.0, *)) { - NSDictionary * iOS12extras = @{@"newPassword": UITextContentTypeNewPassword, - @"oneTimeCode": UITextContentTypeOneTimeCode}; - - NSMutableDictionary * iOS12baseMap = [contentTypeMap mutableCopy]; - [iOS12baseMap addEntriesFromDictionary:iOS12extras]; - - contentTypeMap = [iOS12baseMap copy]; - } - #endif - }); - - // Setting textContentType to an empty string will disable any - // default behaviour, like the autofill bar for password inputs - self.backedTextInputView.textContentType = contentTypeMap[type] ?: type; - } + #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) + static dispatch_once_t onceToken; + static NSDictionary *contentTypeMap; + + dispatch_once(&onceToken, ^{ + contentTypeMap = @{@"none": @"", + @"URL": UITextContentTypeURL, + @"addressCity": UITextContentTypeAddressCity, + @"addressCityAndState":UITextContentTypeAddressCityAndState, + @"addressState": UITextContentTypeAddressState, + @"countryName": UITextContentTypeCountryName, + @"creditCardNumber": UITextContentTypeCreditCardNumber, + @"emailAddress": UITextContentTypeEmailAddress, + @"familyName": UITextContentTypeFamilyName, + @"fullStreetAddress": UITextContentTypeFullStreetAddress, + @"givenName": UITextContentTypeGivenName, + @"jobTitle": UITextContentTypeJobTitle, + @"location": UITextContentTypeLocation, + @"middleName": UITextContentTypeMiddleName, + @"name": UITextContentTypeName, + @"namePrefix": UITextContentTypeNamePrefix, + @"nameSuffix": UITextContentTypeNameSuffix, + @"nickname": UITextContentTypeNickname, + @"organizationName": UITextContentTypeOrganizationName, + @"postalCode": UITextContentTypePostalCode, + @"streetAddressLine1": UITextContentTypeStreetAddressLine1, + @"streetAddressLine2": UITextContentTypeStreetAddressLine2, + @"sublocality": UITextContentTypeSublocality, + @"telephoneNumber": UITextContentTypeTelephoneNumber, + }; + + #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ + if (@available(iOS 11.0, tvOS 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, tvOS 12.0, *)) { + NSDictionary * iOS12extras = @{@"newPassword": UITextContentTypeNewPassword, + @"oneTimeCode": UITextContentTypeOneTimeCode}; + + NSMutableDictionary * iOS12baseMap = [contentTypeMap mutableCopy]; + [iOS12baseMap addEntriesFromDictionary:iOS12extras]; + + contentTypeMap = [iOS12baseMap copy]; + } + #endif + }); + + // Setting textContentType to an empty string will disable any + // default behaviour, like the autofill bar for password inputs + self.backedTextInputView.textContentType = contentTypeMap[type] ?: type; #endif } diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index b728ed23820822..25ec3266b7eb05 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -363,13 +363,10 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC // Added for Android compatibility @"numeric": @(UIKeyboardTypeDecimalPad), }]; - // TODO: T56867629 - if (@available(iOS 10.0, tvOS 10.0, *)) { - temporaryMapping[@"ascii-capable-number-pad"] = @(UIKeyboardTypeASCIICapableNumberPad); - } + temporaryMapping[@"ascii-capable-number-pad"] = @(UIKeyboardTypeASCIICapableNumberPad); mapping = temporaryMapping; }); - + UIKeyboardType type = RCTConvertEnumValue("UIKeyboardType", mapping, @(UIKeyboardTypeDefault), json).integerValue; return type; } @@ -445,7 +442,7 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC @"default": @(UIBarStyleDefault), @"black": @(UIBarStyleBlack), @"blackOpaque": @(UIBarStyleBlackOpaque), - @"blackTranslucent": @(UIBarStyleBlackTranslucent), + @"blackTranslucent": @(UIBarStyleBlackTranslucent), }), UIBarStyleDefault, integerValue) #endif @@ -788,7 +785,7 @@ + (UIImage *)UIImage:(id)json // This check is added here instead of being inside RCTImageFromLocalAssetURL, since // we don't want breaking changes to RCTImageFromLocalAssetURL, which is called in a lot of places // This is a deprecated method, and hence has the least impact on existing code. Basically, - // instead of crashing the app, it tries one more location for the image. + // instead of crashing the app, it tries one more location for the image. if (!image) { image = RCTImageFromLocalBundleAssetURL(URL); } diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm index d0c1da31f25c3d..f8db5e3da23777 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm @@ -132,7 +132,7 @@ - (void)_attach return; } - if (@available(iOS 10.0, macOS 13.0, *)) { + if (@available(macOS 13.0, *)) { _scrollViewComponentView.scrollView.refreshControl = _refreshControl; } } @@ -146,7 +146,7 @@ - (void)_detach // iOS requires to end refreshing before unmounting. [_refreshControl endRefreshing]; - if (@available(iOS 10.0, macOS 13.0, *)) { + if (@available(macOS 13.0, *)) { _scrollViewComponentView.scrollView.refreshControl = nil; } _scrollViewComponentView = nil;