From f11937ef6545962ff0bc6dc0a536306f592b3125 Mon Sep 17 00:00:00 2001 From: Jiawei Lv Date: Tue, 14 Jan 2020 21:41:25 -0800 Subject: [PATCH] Revert D19271321: iOS - deprecate iOS 9 support by removing runtime checks for 10.0+ Differential Revision: D19271321 Original commit changeset: 424ad7e21612 fbshipit-source-id: 2bd9599e8fb31914dbcbc03f732379d6c8103028 --- Libraries/LinkingIOS/RCTLinkingManager.mm | 56 ++++++++-- .../RCTPushNotificationManager.mm | 33 ++++-- .../Text/TextInput/RCTBaseTextInputView.m | 105 +++++++++--------- React/Base/RCTConvert.m | 11 +- .../RCTPullToRefreshViewComponentView.mm | 4 +- 5 files changed, 130 insertions(+), 79 deletions(-) diff --git a/Libraries/LinkingIOS/RCTLinkingManager.mm b/Libraries/LinkingIOS/RCTLinkingManager.mm index 2ad1c627e99..85b9aa7a0bd 100644 --- a/Libraries/LinkingIOS/RCTLinkingManager.mm +++ b/Libraries/LinkingIOS/RCTLinkingManager.mm @@ -99,8 +99,30 @@ RCT_EXPORT_METHOD(openURL:(NSURL *)URL resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { - [RCTSharedApplication() openURL:URL options:@{} completionHandler:^(BOOL success) { - if (success) { + 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) { resolve(@YES); } else { #if TARGET_OS_SIMULATOR @@ -116,7 +138,9 @@ RCT_EXPORT_METHOD(openURL:(NSURL *)URL reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil); #endif } - }]; +#endif + } + } RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL @@ -169,13 +193,25 @@ RCT_EXPORT_METHOD(openSettings:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPromiseRejectBlock)reject) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; - [RCTSharedApplication() openURL:url options:@{} completionHandler:^(BOOL success) { - if (success) { - resolve(nil); - } else { - reject(RCTErrorUnspecified, @"Unable to open app settings", nil); - } - }]; + 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 + } } RCT_EXPORT_METHOD(sendIntent:(NSString *)action diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm index b2ba94d497b..c6465bd7189 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm @@ -472,27 +472,36 @@ RCT_EXPORT_METHOD(getScheduledLocalNotifications:(RCTResponseSenderBlock)callbac RCT_EXPORT_METHOD(removeAllDeliveredNotifications) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center removeAllDeliveredNotifications]; + // TODO: T56867629 + if (@available(iOS 10.0, tvOS 10.0, *)) { + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center removeAllDeliveredNotifications]; + } } RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSArray *)identifiers) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center removeDeliveredNotificationsWithIdentifiers:identifiers]; + // TODO: T56867629 + if (@available(iOS 10.0, tvOS 10.0, *)) { + UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; + [center removeDeliveredNotificationsWithIdentifiers:identifiers]; + } } RCT_EXPORT_METHOD(getDeliveredNotifications:(RCTResponseSenderBlock)callback) { - UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; - [center getDeliveredNotificationsWithCompletionHandler:^(NSArray *_Nonnull notifications) { - NSMutableArray *formattedNotifications = [NSMutableArray new]; + // TODO: T56867629 + if (@available(iOS 10.0, tvOS 10.0, *)) { + 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 c61279893f0..5a15e8fe641 100644 --- a/Libraries/Text/TextInput/RCTBaseTextInputView.m +++ b/Libraries/Text/TextInput/RCTBaseTextInputView.m @@ -194,65 +194,68 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) - (void)setTextContentType:(NSString *)type { - #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) - static dispatch_once_t onceToken; - static NSDictionary *contentTypeMap; + #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0 + if (@available(iOS 10.0, *)) { - 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, - }; + static dispatch_once_t onceToken; + static NSDictionary *contentTypeMap; - #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ - if (@available(iOS 11.0, tvOS 11.0, *)) { - NSDictionary * iOS11extras = @{@"username": UITextContentTypeUsername, - @"password": UITextContentTypePassword}; + 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, + }; - NSMutableDictionary * iOS11baseMap = [contentTypeMap mutableCopy]; - [iOS11baseMap addEntriesFromDictionary:iOS11extras]; + #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */ + if (@available(iOS 11.0, tvOS 11.0, *)) { + NSDictionary * iOS11extras = @{@"username": UITextContentTypeUsername, + @"password": UITextContentTypePassword}; - contentTypeMap = [iOS11baseMap copy]; - } - #endif + NSMutableDictionary * iOS11baseMap = [contentTypeMap mutableCopy]; + [iOS11baseMap addEntriesFromDictionary:iOS11extras]; - #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000 /* __IPHONE_12_0 */ - if (@available(iOS 12.0, tvOS 12.0, *)) { - NSDictionary * iOS12extras = @{@"newPassword": UITextContentTypeNewPassword, - @"oneTimeCode": UITextContentTypeOneTimeCode}; + contentTypeMap = [iOS11baseMap copy]; + } + #endif - NSMutableDictionary * iOS12baseMap = [contentTypeMap mutableCopy]; - [iOS12baseMap addEntriesFromDictionary:iOS12extras]; + #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000 /* __IPHONE_12_0 */ + if (@available(iOS 12.0, tvOS 12.0, *)) { + NSDictionary * iOS12extras = @{@"newPassword": UITextContentTypeNewPassword, + @"oneTimeCode": UITextContentTypeOneTimeCode}; - contentTypeMap = [iOS12baseMap copy]; - } - #endif - }); + NSMutableDictionary * iOS12baseMap = [contentTypeMap mutableCopy]; + [iOS12baseMap addEntriesFromDictionary:iOS12extras]; - // Setting textContentType to an empty string will disable any - // default behaviour, like the autofill bar for password inputs - self.backedTextInputView.textContentType = contentTypeMap[type] ?: type; + 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 25ec3266b7e..b728ed23820 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -363,10 +363,13 @@ RCT_ENUM_CONVERTER(UITextFieldViewMode, (@{ // Added for Android compatibility @"numeric": @(UIKeyboardTypeDecimalPad), }]; - temporaryMapping[@"ascii-capable-number-pad"] = @(UIKeyboardTypeASCIICapableNumberPad); + // TODO: T56867629 + if (@available(iOS 10.0, tvOS 10.0, *)) { + temporaryMapping[@"ascii-capable-number-pad"] = @(UIKeyboardTypeASCIICapableNumberPad); + } mapping = temporaryMapping; }); - + UIKeyboardType type = RCTConvertEnumValue("UIKeyboardType", mapping, @(UIKeyboardTypeDefault), json).integerValue; return type; } @@ -442,7 +445,7 @@ RCT_ENUM_CONVERTER(UIBarStyle, (@{ @"default": @(UIBarStyleDefault), @"black": @(UIBarStyleBlack), @"blackOpaque": @(UIBarStyleBlackOpaque), - @"blackTranslucent": @(UIBarStyleBlackTranslucent), + @"blackTranslucent": @(UIBarStyleBlackTranslucent), }), UIBarStyleDefault, integerValue) #endif @@ -785,7 +788,7 @@ RCT_ENUM_CONVERTER(RCTAnimationType, (@{ // 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 f8db5e3da23..d0c1da31f25 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTPullToRefreshViewComponentView.mm @@ -132,7 +132,7 @@ using namespace facebook::react; return; } - if (@available(macOS 13.0, *)) { + if (@available(iOS 10.0, macOS 13.0, *)) { _scrollViewComponentView.scrollView.refreshControl = _refreshControl; } } @@ -146,7 +146,7 @@ using namespace facebook::react; // iOS requires to end refreshing before unmounting. [_refreshControl endRefreshing]; - if (@available(macOS 13.0, *)) { + if (@available(iOS 10.0, macOS 13.0, *)) { _scrollViewComponentView.scrollView.refreshControl = nil; } _scrollViewComponentView = nil;