Skip to content

Commit 0805915

Browse files
authored
refactor(iOS): remove code unused on iOS >= 15.1 (#2862)
## Description Removed code that applies only to iOS versions below 15.1. ## Changes See commits. ## Test code and steps to reproduce CI should build. ## Checklist - [ ] Ensured that CI passes
1 parent 0208e88 commit 0805915

6 files changed

Lines changed: 110 additions & 264 deletions

File tree

ios/RNSConvert.mm

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -195,53 +195,50 @@ + (RNSSearchBarPlacement)RNSScreenSearchBarPlacementFromCppEquivalent:(react::RN
195195
+ (RNSBlurEffectStyle)RNSBlurEffectStyleFromCppEquivalent:(react::RNSScreenStackHeaderConfigBlurEffect)blurEffect
196196
{
197197
using enum react::RNSScreenStackHeaderConfigBlurEffect;
198-
#if !TARGET_OS_TV && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
199-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
200-
if (@available(iOS 13.0, *)) {
201-
switch (blurEffect) {
202-
case None:
203-
return RNSBlurEffectStyleNone;
204-
case ExtraLight:
205-
return RNSBlurEffectStyleExtraLight;
206-
case Light:
207-
return RNSBlurEffectStyleLight;
208-
case Dark:
209-
return RNSBlurEffectStyleDark;
210-
case Regular:
211-
return RNSBlurEffectStyleRegular;
212-
case Prominent:
213-
return RNSBlurEffectStyleProminent;
214-
case SystemUltraThinMaterial:
215-
return RNSBlurEffectStyleSystemUltraThinMaterial;
216-
case SystemThinMaterial:
217-
return RNSBlurEffectStyleSystemThinMaterial;
218-
case SystemMaterial:
219-
return RNSBlurEffectStyleSystemMaterial;
220-
case SystemThickMaterial:
221-
return RNSBlurEffectStyleSystemThickMaterial;
222-
case SystemChromeMaterial:
223-
return RNSBlurEffectStyleSystemChromeMaterial;
224-
case SystemUltraThinMaterialLight:
225-
return RNSBlurEffectStyleSystemUltraThinMaterialLight;
226-
case SystemThinMaterialLight:
227-
return RNSBlurEffectStyleSystemThinMaterialLight;
228-
case SystemMaterialLight:
229-
return RNSBlurEffectStyleSystemMaterialLight;
230-
case SystemThickMaterialLight:
231-
return RNSBlurEffectStyleSystemThickMaterialLight;
232-
case SystemChromeMaterialLight:
233-
return RNSBlurEffectStyleSystemChromeMaterialLight;
234-
case SystemUltraThinMaterialDark:
235-
return RNSBlurEffectStyleSystemUltraThinMaterialDark;
236-
case SystemThinMaterialDark:
237-
return RNSBlurEffectStyleSystemThinMaterialDark;
238-
case SystemMaterialDark:
239-
return RNSBlurEffectStyleSystemMaterialDark;
240-
case SystemThickMaterialDark:
241-
return RNSBlurEffectStyleSystemThickMaterialDark;
242-
case SystemChromeMaterialDark:
243-
return RNSBlurEffectStyleSystemChromeMaterialDark;
244-
}
198+
#if !TARGET_OS_TV
199+
switch (blurEffect) {
200+
case None:
201+
return RNSBlurEffectStyleNone;
202+
case ExtraLight:
203+
return RNSBlurEffectStyleExtraLight;
204+
case Light:
205+
return RNSBlurEffectStyleLight;
206+
case Dark:
207+
return RNSBlurEffectStyleDark;
208+
case Regular:
209+
return RNSBlurEffectStyleRegular;
210+
case Prominent:
211+
return RNSBlurEffectStyleProminent;
212+
case SystemUltraThinMaterial:
213+
return RNSBlurEffectStyleSystemUltraThinMaterial;
214+
case SystemThinMaterial:
215+
return RNSBlurEffectStyleSystemThinMaterial;
216+
case SystemMaterial:
217+
return RNSBlurEffectStyleSystemMaterial;
218+
case SystemThickMaterial:
219+
return RNSBlurEffectStyleSystemThickMaterial;
220+
case SystemChromeMaterial:
221+
return RNSBlurEffectStyleSystemChromeMaterial;
222+
case SystemUltraThinMaterialLight:
223+
return RNSBlurEffectStyleSystemUltraThinMaterialLight;
224+
case SystemThinMaterialLight:
225+
return RNSBlurEffectStyleSystemThinMaterialLight;
226+
case SystemMaterialLight:
227+
return RNSBlurEffectStyleSystemMaterialLight;
228+
case SystemThickMaterialLight:
229+
return RNSBlurEffectStyleSystemThickMaterialLight;
230+
case SystemChromeMaterialLight:
231+
return RNSBlurEffectStyleSystemChromeMaterialLight;
232+
case SystemUltraThinMaterialDark:
233+
return RNSBlurEffectStyleSystemUltraThinMaterialDark;
234+
case SystemThinMaterialDark:
235+
return RNSBlurEffectStyleSystemThinMaterialDark;
236+
case SystemMaterialDark:
237+
return RNSBlurEffectStyleSystemMaterialDark;
238+
case SystemThickMaterialDark:
239+
return RNSBlurEffectStyleSystemThickMaterialDark;
240+
case SystemChromeMaterialDark:
241+
return RNSBlurEffectStyleSystemChromeMaterialDark;
245242
}
246243
#endif
247244

ios/RNSScreen.mm

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,7 @@ - (void)setStackPresentation:(RNSScreenStackPresentation)stackPresentation
245245
{
246246
switch (stackPresentation) {
247247
case RNSScreenStackPresentationModal:
248-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
249-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
250-
if (@available(iOS 13.0, tvOS 13.0, *)) {
251-
_controller.modalPresentationStyle = UIModalPresentationAutomatic;
252-
} else {
253-
_controller.modalPresentationStyle = UIModalPresentationFullScreen;
254-
}
255-
#else
256-
_controller.modalPresentationStyle = UIModalPresentationFullScreen;
257-
#endif
248+
_controller.modalPresentationStyle = UIModalPresentationAutomatic;
258249
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_17_0) && \
259250
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_17_0 && !TARGET_OS_TV
260251
if (@available(iOS 18.0, *)) {
@@ -345,12 +336,7 @@ - (void)setStackAnimation:(RNSScreenStackAnimation)stackAnimation
345336

346337
- (void)setGestureEnabled:(BOOL)gestureEnabled
347338
{
348-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
349-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
350-
if (@available(iOS 13.0, tvOS 13.0, *)) {
351-
_controller.modalInPresentation = !gestureEnabled;
352-
}
353-
#endif
339+
_controller.modalInPresentation = !gestureEnabled;
354340

355341
_gestureEnabled = gestureEnabled;
356342
}
@@ -761,8 +747,6 @@ - (BOOL)presentationControllerShouldDismiss:(UIPresentationController *)presenta
761747
return _gestureEnabled;
762748
}
763749

764-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
765-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
766750
- (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)presentationController
767751
{
768752
// NOTE(kkafar): We should consider depracating the use of gesture cancel here & align
@@ -772,7 +756,6 @@ - (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)pr
772756
[self notifyDismissCancelledWithDismissCount:1];
773757
}
774758
}
775-
#endif
776759

777760
- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
778761
{
@@ -1580,18 +1563,12 @@ - (CGSize)getStatusBarHeightIsModal:(BOOL)isModal
15801563
#if !TARGET_OS_TV && !TARGET_OS_VISION
15811564
CGSize fallbackStatusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
15821565

1583-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
1584-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
1585-
if (@available(iOS 13.0, *)) {
1586-
CGSize primaryStatusBarSize = self.view.window.windowScene.statusBarManager.statusBarFrame.size;
1587-
if (primaryStatusBarSize.height == 0 || primaryStatusBarSize.width == 0)
1588-
return fallbackStatusBarSize;
1589-
1590-
return primaryStatusBarSize;
1591-
} else {
1566+
CGSize primaryStatusBarSize = self.view.window.windowScene.statusBarManager.statusBarFrame.size;
1567+
if (primaryStatusBarSize.height == 0 || primaryStatusBarSize.width == 0) {
15921568
return fallbackStatusBarSize;
15931569
}
1594-
#endif /* Check for iOS 13.0 */
1570+
1571+
return primaryStatusBarSize;
15951572

15961573
#else
15971574
// TVOS does not have status bar.

ios/RNSScreenStack.mm

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,9 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
492492
UIViewController *next = controllers[i];
493493
BOOL lastModal = (i == controllers.count - 1);
494494

495-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
496-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
497-
if (@available(iOS 13.0, tvOS 13.0, *)) {
498-
// Inherit UI style from its parent - solves an issue with incorrect style being applied to some UIKit views
499-
// like date picker or segmented control.
500-
next.overrideUserInterfaceStyle = self->_controller.overrideUserInterfaceStyle;
501-
}
502-
#endif
495+
// Inherit UI style from its parent - solves an issue with incorrect style being applied to some UIKit views
496+
// like date picker or segmented control.
497+
next.overrideUserInterfaceStyle = self->_controller.overrideUserInterfaceStyle;
503498

504499
BOOL shouldAnimate = lastModal && [next isKindOfClass:[RNSScreen class]] &&
505500
((RNSScreen *)next).screenView.stackAnimation != RNSScreenStackAnimationNone;

ios/RNSScreenStackHeaderConfig.mm

Lines changed: 23 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -276,96 +276,9 @@ - (BOOL)shouldBackButtonBeVisibleInNavigationBar:(nullable UINavigationBar *)nav
276276
+ (void)setAnimatedConfig:(UIViewController *)vc withConfig:(RNSScreenStackHeaderConfig *)config
277277
{
278278
UINavigationBar *navbar = ((UINavigationController *)vc.parentViewController).navigationBar;
279-
// It is workaround for loading custom back icon when transitioning from a screen without header to the screen which
280-
// has one. This action fails when navigating to the screen with header for the second time and loads default back
281-
// button. It looks like changing the tint color of navbar triggers an update of the items belonging to it and it
282-
// seems to load the custom back image so we change the tint color's alpha by a very small amount and then set it to
283-
// the one it should have.
284-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_14_0) && \
285-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_0
286-
// it brakes the behavior of `headerRight` in iOS 14, where the bug desribed above seems to be fixed, so we do nothing
287-
// in iOS 14
288-
if (@available(iOS 14.0, *)) {
289-
} else
290-
#endif
291-
{
292-
[navbar setTintColor:[config.color colorWithAlphaComponent:CGColorGetAlpha(config.color.CGColor) - 0.01]];
293-
}
294279
[navbar setTintColor:config.color];
295280

296-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
297-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
298-
if (@available(iOS 13.0, *)) {
299-
// font customized on the navigation item level, so nothing to do here
300-
} else
301-
#endif
302-
{
303-
BOOL hideShadow = config.hideShadow;
304-
305-
if (config.backgroundColor && CGColorGetAlpha(config.backgroundColor.CGColor) == 0.) {
306-
[navbar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
307-
[navbar setBarTintColor:[UIColor clearColor]];
308-
hideShadow = YES;
309-
} else {
310-
[navbar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
311-
[navbar setBarTintColor:config.backgroundColor];
312-
}
313-
[navbar setTranslucent:config.translucent];
314-
[navbar setValue:@(hideShadow ? YES : NO) forKey:@"hidesShadow"];
315-
316-
if (config.titleFontFamily || config.titleFontSize || config.titleFontWeight || config.titleColor) {
317-
NSMutableDictionary *attrs = [NSMutableDictionary new];
318-
319-
if (config.titleColor) {
320-
attrs[NSForegroundColorAttributeName] = config.titleColor;
321-
}
322-
323-
NSString *family = config.titleFontFamily ?: nil;
324-
NSNumber *size = config.titleFontSize ?: @17;
325-
NSString *weight = config.titleFontWeight ?: nil;
326-
if (family || weight) {
327-
attrs[NSFontAttributeName] = [RCTFont updateFont:nil
328-
withFamily:family
329-
size:size
330-
weight:weight
331-
style:nil
332-
variant:nil
333-
scaleMultiplier:1.0];
334-
} else {
335-
attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:[size floatValue]];
336-
}
337-
[navbar setTitleTextAttributes:attrs];
338-
}
339-
340-
#if !TARGET_OS_TV && !TARGET_OS_VISION
341-
if (@available(iOS 11.0, *)) {
342-
if (config.largeTitle &&
343-
(config.largeTitleFontFamily || config.largeTitleFontSize || config.largeTitleFontWeight ||
344-
config.largeTitleColor || config.titleColor)) {
345-
NSMutableDictionary *largeAttrs = [NSMutableDictionary new];
346-
if (config.largeTitleColor || config.titleColor) {
347-
largeAttrs[NSForegroundColorAttributeName] =
348-
config.largeTitleColor ? config.largeTitleColor : config.titleColor;
349-
}
350-
NSString *largeFamily = config.largeTitleFontFamily ?: nil;
351-
NSNumber *largeSize = config.largeTitleFontSize ?: @34;
352-
NSString *largeWeight = config.largeTitleFontWeight ?: nil;
353-
if (largeFamily || largeWeight) {
354-
largeAttrs[NSFontAttributeName] = [RCTFont updateFont:nil
355-
withFamily:largeFamily
356-
size:largeSize
357-
weight:largeWeight
358-
style:nil
359-
variant:nil
360-
scaleMultiplier:1.0];
361-
} else {
362-
largeAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:[largeSize floatValue] weight:UIFontWeightBold];
363-
}
364-
[navbar setLargeTitleTextAttributes:largeAttrs];
365-
}
366-
}
367-
#endif
368-
}
281+
// font customized on the navigation item level, so nothing to do here
369282
}
370283

371284
+ (void)setTitleAttibutes:(NSDictionary *)attrs forButton:(UIBarButtonItem *)button
@@ -476,8 +389,6 @@ + (void)willShowViewController:(UIViewController *)vc
476389
}
477390
}
478391

479-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
480-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
481392
+ (UINavigationBarAppearance *)buildAppearance:(UIViewController *)vc
482393
withConfig:(RNSScreenStackHeaderConfig *)config API_AVAILABLE(ios(13.0))
483394
{
@@ -578,7 +489,6 @@ + (UINavigationBarAppearance *)buildAppearance:(UIViewController *)vc
578489
}
579490
return appearance;
580491
}
581-
#endif // Check for >= iOS 13.0
582492

583493
+ (void)updateViewController:(UIViewController *)vc
584494
withConfig:(RNSScreenStackHeaderConfig *)config
@@ -684,6 +594,7 @@ + (void)updateViewController:(UIViewController *)vc
684594
}
685595
#endif
686596

597+
// TODO: This needs to be removed after min. tvOS deployment target bump
687598
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
688599
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
689600
if (@available(iOS 13.0, tvOS 13.0, *)) {
@@ -717,7 +628,7 @@ + (void)updateViewController:(UIViewController *)vc
717628
}
718629
navitem.scrollEdgeAppearance = scrollEdgeAppearance;
719630
} else
720-
#endif
631+
#endif // Check for iOS / tvOS 13
721632
{
722633
#if !TARGET_OS_TV
723634
// updating backIndicatotImage does not work when called during transition. On iOS pre 13 we need
@@ -1238,35 +1149,28 @@ + (NSMutableDictionary *)blurEffectsForIOSVersion
12381149
@"extraLight" : @(RNSBlurEffectStyleExtraLight),
12391150
@"light" : @(RNSBlurEffectStyleLight),
12401151
@"dark" : @(RNSBlurEffectStyleDark),
1152+
@"regular" : @(RNSBlurEffectStyleRegular),
1153+
@"prominent" : @(RNSBlurEffectStyleProminent),
12411154
}];
12421155

1243-
if (@available(iOS 10.0, *)) {
1244-
[blurEffects addEntriesFromDictionary:@{
1245-
@"regular" : @(RNSBlurEffectStyleRegular),
1246-
@"prominent" : @(RNSBlurEffectStyleProminent),
1247-
}];
1248-
}
1249-
#if !TARGET_OS_TV && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
1250-
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
1251-
if (@available(iOS 13.0, *)) {
1252-
[blurEffects addEntriesFromDictionary:@{
1253-
@"systemUltraThinMaterial" : @(RNSBlurEffectStyleSystemUltraThinMaterial),
1254-
@"systemThinMaterial" : @(RNSBlurEffectStyleSystemThinMaterial),
1255-
@"systemMaterial" : @(RNSBlurEffectStyleSystemMaterial),
1256-
@"systemThickMaterial" : @(RNSBlurEffectStyleSystemThickMaterial),
1257-
@"systemChromeMaterial" : @(RNSBlurEffectStyleSystemChromeMaterial),
1258-
@"systemUltraThinMaterialLight" : @(RNSBlurEffectStyleSystemUltraThinMaterialLight),
1259-
@"systemThinMaterialLight" : @(RNSBlurEffectStyleSystemThinMaterialLight),
1260-
@"systemMaterialLight" : @(RNSBlurEffectStyleSystemMaterialLight),
1261-
@"systemThickMaterialLight" : @(RNSBlurEffectStyleSystemThickMaterialLight),
1262-
@"systemChromeMaterialLight" : @(RNSBlurEffectStyleSystemChromeMaterialLight),
1263-
@"systemUltraThinMaterialDark" : @(RNSBlurEffectStyleSystemUltraThinMaterialDark),
1264-
@"systemThinMaterialDark" : @(RNSBlurEffectStyleSystemThinMaterialDark),
1265-
@"systemMaterialDark" : @(RNSBlurEffectStyleSystemMaterialDark),
1266-
@"systemThickMaterialDark" : @(RNSBlurEffectStyleSystemThickMaterialDark),
1267-
@"systemChromeMaterialDark" : @(RNSBlurEffectStyleSystemChromeMaterialDark),
1268-
}];
1269-
}
1156+
#if !TARGET_OS_TV
1157+
[blurEffects addEntriesFromDictionary:@{
1158+
@"systemUltraThinMaterial" : @(RNSBlurEffectStyleSystemUltraThinMaterial),
1159+
@"systemThinMaterial" : @(RNSBlurEffectStyleSystemThinMaterial),
1160+
@"systemMaterial" : @(RNSBlurEffectStyleSystemMaterial),
1161+
@"systemThickMaterial" : @(RNSBlurEffectStyleSystemThickMaterial),
1162+
@"systemChromeMaterial" : @(RNSBlurEffectStyleSystemChromeMaterial),
1163+
@"systemUltraThinMaterialLight" : @(RNSBlurEffectStyleSystemUltraThinMaterialLight),
1164+
@"systemThinMaterialLight" : @(RNSBlurEffectStyleSystemThinMaterialLight),
1165+
@"systemMaterialLight" : @(RNSBlurEffectStyleSystemMaterialLight),
1166+
@"systemThickMaterialLight" : @(RNSBlurEffectStyleSystemThickMaterialLight),
1167+
@"systemChromeMaterialLight" : @(RNSBlurEffectStyleSystemChromeMaterialLight),
1168+
@"systemUltraThinMaterialDark" : @(RNSBlurEffectStyleSystemUltraThinMaterialDark),
1169+
@"systemThinMaterialDark" : @(RNSBlurEffectStyleSystemThinMaterialDark),
1170+
@"systemMaterialDark" : @(RNSBlurEffectStyleSystemMaterialDark),
1171+
@"systemThickMaterialDark" : @(RNSBlurEffectStyleSystemThickMaterialDark),
1172+
@"systemChromeMaterialDark" : @(RNSBlurEffectStyleSystemChromeMaterialDark),
1173+
}];
12701174
#endif
12711175
return blurEffects;
12721176
}

0 commit comments

Comments
 (0)