Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(iOS): remove @available guard for lower iOS versions #46534

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions packages/react-native/Libraries/Image/RCTAnimatedImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ - (NSUInteger)imageLoopCountWithSource:(CGImageSourceRef)source
NSNumber *gifLoopCount = gifProperties[(__bridge NSString *)kCGImagePropertyGIFLoopCount];
if (gifLoopCount != nil) {
loopCount = gifLoopCount.unsignedIntegerValue;
if (@available(iOS 14.0, *)) {
} else {
// A loop count of 1 means it should animate twice, 2 means, thrice, etc.
if (loopCount != 0) {
loopCount++;
}
}
}
}
return loopCount;
Expand Down
6 changes: 2 additions & 4 deletions packages/react-native/Libraries/Text/RCTTextAttributes.mm
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ - (NSParagraphStyle *)effectiveParagraphStyle
}

if (_lineBreakStrategy != NSLineBreakStrategyNone) {
if (@available(iOS 14.0, *)) {
paragraphStyle.lineBreakStrategy = _lineBreakStrategy;
isParagraphStyleUsed = YES;
}
paragraphStyle.lineBreakStrategy = _lineBreakStrategy;
isParagraphStyleUsed = YES;
}

if (_lineBreakMode != NSLineBreakByWordWrapping) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,11 @@ - (void)setTextContentType:(NSString *)type
@"password" : UITextContentTypePassword,
@"newPassword" : UITextContentTypeNewPassword,
@"oneTimeCode" : UITextContentTypeOneTimeCode,
@"dateTime" : UITextContentTypeDateTime,
@"flightNumber" : UITextContentTypeFlightNumber,
@"shipmentTrackingNumber" : UITextContentTypeShipmentTrackingNumber,
}];

if (@available(iOS 15.0, *)) {
[mutableContentTypeMap addEntriesFromDictionary:@{
@"dateTime" : UITextContentTypeDateTime,
@"flightNumber" : UITextContentTypeFlightNumber,
@"shipmentTrackingNumber" : UITextContentTypeShipmentTrackingNumber,
}];
}

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */
if (@available(iOS 17.0, *)) {
[mutableContentTypeMap addEntriesFromDictionary:@{
Expand Down
26 changes: 11 additions & 15 deletions packages/react-native/React/Base/RCTConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,17 @@ + (NSLocale *)NSLocale:(id)json

+ (NSLineBreakStrategy)NSLineBreakStrategy:(id)json RCT_DYNAMIC
{
if (@available(iOS 14.0, *)) {
static NSDictionary *mapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
mapping = @{
@"none" : @(NSLineBreakStrategyNone),
@"standard" : @(NSLineBreakStrategyStandard),
@"hangul-word" : @(NSLineBreakStrategyHangulWordPriority),
@"push-out" : @(NSLineBreakStrategyPushOut)
};
});
return RCTConvertEnumValue("NSLineBreakStrategy", mapping, @(NSLineBreakStrategyNone), json).integerValue;
} else {
return NSLineBreakStrategyNone;
}
static NSDictionary *mapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
mapping = @{
@"none" : @(NSLineBreakStrategyNone),
@"standard" : @(NSLineBreakStrategyStandard),
@"hangul-word" : @(NSLineBreakStrategyHangulWordPriority),
@"push-out" : @(NSLineBreakStrategyPushOut)
};
});
return RCTConvertEnumValue("NSLineBreakStrategy", mapping, @(NSLineBreakStrategyNone), json).integerValue;
}

RCT_ENUM_CONVERTER(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,7 @@ static void setMultipliers(
: (RCTResponseSenderBlock)onSuccess onError
: (__unused RCTResponseSenderBlock)onError)
{
if (@available(iOS 14.0, *)) {
onSuccess(@[ @(UIAccessibilityPrefersCrossFadeTransitions()) ]);
} else {
onSuccess(@[ @(false) ]);
}
onSuccess(@[ @(UIAccessibilityPrefersCrossFadeTransitions()) ]);
}

RCT_EXPORT_METHOD(getCurrentReduceTransparencyState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,12 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
} else {
newContentOffset.y -= contentDiff;
}

if (@available(iOS 14.0, *)) {
// On iOS when Prefer Cross-Fade Transitions is enabled, the keyboard position
// & height is reported differently (0 instead of Y position value matching height of frame)
// Fixes similar issue we saw with https://github.com/facebook/react-native/pull/34503
if (UIAccessibilityPrefersCrossFadeTransitions() && keyboardEndFrame.size.height == 0) {
newContentOffset.y = 0;
newEdgeInsets.bottom = 0;
}
// On iOS when Prefer Cross-Fade Transitions is enabled, the keyboard position
// & height is reported differently (0 instead of Y position value matching height of frame)
// Fixes similar issue we saw with https://github.com/facebook/react-native/pull/34503
if (UIAccessibilityPrefersCrossFadeTransitions() && keyboardEndFrame.size.height == 0) {
newContentOffset.y = 0;
newEdgeInsets.bottom = 0;
}

[UIView animateWithDuration:duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,11 @@ UITextContentType RCTUITextContentTypeFromString(const std::string &contentType)
@"password" : UITextContentTypePassword,
@"newPassword" : UITextContentTypeNewPassword,
@"oneTimeCode" : UITextContentTypeOneTimeCode,
@"dateTime" : UITextContentTypeDateTime,
@"flightNumber" : UITextContentTypeFlightNumber,
@"shipmentTrackingNumber" : UITextContentTypeShipmentTrackingNumber,
}];

if (@available(iOS 15.0, *)) {
[mutableContentTypeMap addEntriesFromDictionary:@{
@"dateTime" : UITextContentTypeDateTime,
@"flightNumber" : UITextContentTypeFlightNumber,
@"shipmentTrackingNumber" : UITextContentTypeShipmentTrackingNumber,
}];
}

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */
if (@available(iOS 17.0, *)) {
[mutableContentTypeMap addEntriesFromDictionary:@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,22 +357,18 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &

// `accessibilityShowsLargeContentViewer`
if (oldViewProps.accessibilityShowsLargeContentViewer != newViewProps.accessibilityShowsLargeContentViewer) {
if (@available(iOS 13.0, *)) {
if (newViewProps.accessibilityShowsLargeContentViewer) {
self.showsLargeContentViewer = YES;
UILargeContentViewerInteraction *interaction = [[UILargeContentViewerInteraction alloc] init];
[self addInteraction:interaction];
} else {
self.showsLargeContentViewer = NO;
}
if (newViewProps.accessibilityShowsLargeContentViewer) {
self.showsLargeContentViewer = YES;
UILargeContentViewerInteraction *interaction = [[UILargeContentViewerInteraction alloc] init];
[self addInteraction:interaction];
} else {
self.showsLargeContentViewer = NO;
}
}

// `accessibilityLargeContentTitle`
if (oldViewProps.accessibilityLargeContentTitle != newViewProps.accessibilityLargeContentTitle) {
if (@available(iOS 13.0, *)) {
self.largeContentTitle = RCTNSStringFromStringNilIfEmpty(newViewProps.accessibilityLargeContentTitle);
}
}

// `accessibilityTraits`
Expand Down
20 changes: 8 additions & 12 deletions packages/react-native/React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,20 @@ - (void)updateAccessibilityTraitsForRole:(RCTView *)view withDefaultView:(RCTVie

RCT_CUSTOM_VIEW_PROPERTY(accessibilityShowsLargeContentViewer, BOOL, RCTView)
{
if (@available(iOS 13.0, *)) {
BOOL showsLargeContentViewer = json ? [RCTConvert BOOL:json] : defaultView.showsLargeContentViewer;
BOOL showsLargeContentViewer = json ? [RCTConvert BOOL:json] : defaultView.showsLargeContentViewer;

if (showsLargeContentViewer) {
view.showsLargeContentViewer = YES;
UILargeContentViewerInteraction *interaction = [[UILargeContentViewerInteraction alloc] init];
[view addInteraction:interaction];
} else {
view.showsLargeContentViewer = NO;
}
if (showsLargeContentViewer) {
view.showsLargeContentViewer = YES;
UILargeContentViewerInteraction *interaction = [[UILargeContentViewerInteraction alloc] init];
[view addInteraction:interaction];
} else {
view.showsLargeContentViewer = NO;
}
}

RCT_CUSTOM_VIEW_PROPERTY(accessibilityLargeContentTitle, NSString, RCTView)
{
if (@available(iOS 13.0, *)) {
view.largeContentTitle = json ? [RCTConvert NSString:json] : defaultView.largeContentTitle;
}
view.largeContentTitle = json ? [RCTConvert NSString:json] : defaultView.largeContentTitle;
}

RCT_CUSTOM_VIEW_PROPERTY(nativeID, NSString *, RCTView)
Expand Down
14 changes: 6 additions & 8 deletions packages/react-native/React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,12 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
newContentOffset.y -= contentDiff;
}

if (@available(iOS 14.0, *)) {
// On iOS when Prefer Cross-Fade Transitions is enabled, the keyboard position
// & height is reported differently (0 instead of Y position value matching height of frame)
// Fixes similar issue we saw with https://github.com/facebook/react-native/pull/34503
if (UIAccessibilityPrefersCrossFadeTransitions() && endFrame.size.height == 0) {
newContentOffset.y = 0;
newEdgeInsets.bottom = 0;
}
// On iOS when Prefer Cross-Fade Transitions is enabled, the keyboard position
// & height is reported differently (0 instead of Y position value matching height of frame)
// Fixes similar issue we saw with https://github.com/facebook/react-native/pull/34503
if (UIAccessibilityPrefersCrossFadeTransitions() && endFrame.size.height == 0) {
newContentOffset.y = 0;
newEdgeInsets.bottom = 0;
}

[UIView animateWithDuration:duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ inline static NSLineBreakStrategy RCTNSLineBreakStrategyFromLineBreakStrategy(
case facebook::react::LineBreakStrategy::PushOut:
return NSLineBreakStrategyPushOut;
case facebook::react::LineBreakStrategy::HangulWordPriority:
if (@available(iOS 14.0, *)) {
return NSLineBreakStrategyHangulWordPriority;
} else {
return NSLineBreakStrategyNone;
}
return NSLineBreakStrategyHangulWordPriority;
case facebook::react::LineBreakStrategy::Standard:
if (@available(iOS 14.0, *)) {
return NSLineBreakStrategyStandard;
} else {
return NSLineBreakStrategyNone;
}
return NSLineBreakStrategyStandard;
}
}

Expand Down
Loading