Skip to content

Commit b069ff3

Browse files
authored
fix(iOS): check for iOS 13 APIs (#8093)
1 parent d983f79 commit b069ff3

12 files changed

Lines changed: 30 additions & 19 deletions

File tree

‎nativescript-core/application/application.ios.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CADisplayLinkTarget extends NSObject {
8989
}
9090

9191
class IOSApplication implements IOSApplicationDefinition {
92-
private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor;
92+
private _backgroundColor = (majorVersion <= 12 || !UIColor.systemBackgroundColor) ? UIColor.whiteColor : UIColor.systemBackgroundColor;
9393
private _delegate: typeof UIApplicationDelegate;
9494
private _window: UIWindow;
9595
private _observers: Array<NotificationObserver>;
@@ -121,7 +121,6 @@ class IOSApplication implements IOSApplicationDefinition {
121121
}
122122

123123
get systemAppearance(): "light" | "dark" | null {
124-
125124
// userInterfaceStyle is available on UITraitCollection since iOS 12.
126125
if (majorVersion <= 11) {
127126
return null;

‎nativescript-core/ui/activity-indicator/activity-indicator.ios.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const majorVersion = ios.MajorVersion;
99
export class ActivityIndicator extends ActivityIndicatorBase {
1010
nativeViewProtected: UIActivityIndicatorView;
1111

12-
private _activityIndicatorViewStyle = majorVersion <= 12 ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium;
12+
private _activityIndicatorViewStyle = (majorVersion <= 12 || !UIActivityIndicatorViewStyle.Medium) ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium;
1313

1414
createNativeView() {
1515
const viewStyle = this._activityIndicatorViewStyle;

‎nativescript-core/ui/bottom-navigation/bottom-navigation.ios.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ class UITabBarControllerImpl extends UITabBarController {
9393

9494
if (majorVersion >= 13) {
9595
const owner = this._owner.get();
96-
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
96+
if (owner &&
97+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
98+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
9799
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
98100
}
99101
}

‎nativescript-core/ui/core/view/view.ios.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,9 @@ export namespace ios {
10121012

10131013
if (majorVersion >= 13) {
10141014
const owner = this.owner.get();
1015-
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
1015+
if (owner &&
1016+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
1017+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
10161018
owner.notify({ eventName: traitCollectionColorAppearanceChangedEvent, object: owner });
10171019
}
10181020
}

‎nativescript-core/ui/frame/frame.ios.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,9 @@ class UINavigationControllerImpl extends UINavigationController {
540540

541541
if (majorVersion >= 13) {
542542
const owner = this._owner.get();
543-
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
543+
if (owner &&
544+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
545+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
544546
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
545547
}
546548
}

‎nativescript-core/ui/html-view/html-view.ios.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class HtmlView extends HtmlViewBase {
5959
null
6060
);
6161

62-
if (majorVersion >= 13) {
62+
if (majorVersion >= 13 && UIColor.labelColor) {
6363
this.nativeViewProtected.textColor = UIColor.labelColor;
6464
}
6565
}

‎nativescript-core/ui/page/page.ios.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ class UIViewControllerImpl extends UIViewController {
287287

288288
if (majorVersion >= 13) {
289289
const owner = this._owner.get();
290-
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
290+
if (owner &&
291+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
292+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
291293
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
292294
}
293295
}
@@ -298,7 +300,7 @@ export class Page extends PageBase {
298300
nativeViewProtected: UIView;
299301
viewController: UIViewControllerImpl;
300302

301-
private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor;
303+
private _backgroundColor = (majorVersion <= 12 && !UIColor.systemBackgroundColor) ? UIColor.whiteColor : UIColor.systemBackgroundColor;
302304
private _ios: UIViewControllerImpl;
303305
public _presentedViewController: UIViewController; // used when our page present native viewController without going through our abstraction.
304306

‎nativescript-core/ui/tab-view/tab-view.ios.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ class UITabBarControllerImpl extends UITabBarController {
7878

7979
if (majorVersion >= 13) {
8080
const owner = this._owner.get();
81-
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
81+
if (owner &&
82+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
83+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
8284
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
8385
}
8486
}

‎nativescript-core/ui/tabs/tabs.ios.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export * from "./tabs-common";
2424
const majorVersion = iosUtils.MajorVersion;
2525

2626
// Equivalent to dispatch_async(dispatch_get_main_queue(...)) call
27-
const invokeOnRunLoop = (function() {
27+
const invokeOnRunLoop = (function () {
2828
const runloop = CFRunLoopGetMain();
2929

3030
return (action: () => any) => {
@@ -100,7 +100,7 @@ class UIPageViewControllerImpl extends UIPageViewController {
100100

101101
tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner));
102102

103-
if (majorVersion <= 12) {
103+
if (majorVersion <= 12 || !UIColor.labelColor) {
104104
tabBar.tintColor = UIColor.blueColor;
105105
tabBar.barTintColor = UIColor.whiteColor;
106106
tabBar.setTitleColorForState(UIColor.blackColor, MDCTabBarItemState.Normal);
@@ -216,7 +216,9 @@ class UIPageViewControllerImpl extends UIPageViewController {
216216

217217
if (majorVersion >= 13) {
218218
const owner = this._owner.get();
219-
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
219+
if (owner &&
220+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
221+
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
220222
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
221223
}
222224
}
@@ -1087,7 +1089,7 @@ export class Tabs extends TabsBase {
10871089
// HACK: UIPageViewController fix; see https://stackoverflow.com/a/17330606
10881090
invokeOnRunLoop(() => this.viewController.setViewControllersDirectionAnimatedCompletion(controllers, navigationDirection, false, null));
10891091
}
1090-
1092+
10911093
this._canSelectItem = true;
10921094
this._setCanBeLoaded(value);
10931095
this._loadUnloadTabItems(value);

‎nativescript-core/ui/text-base/text-base.ios.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class TextBase extends TextBaseCommon {
153153
this.nativeTextViewProtected.setAttributedTitleForState(attrText, UIControlState.Normal);
154154
}
155155
else {
156-
if (majorVersion >= 13) {
156+
if (majorVersion >= 13 && UIColor.labelColor) {
157157
this.nativeTextViewProtected.textColor = UIColor.labelColor;
158158
}
159159

@@ -205,7 +205,7 @@ export class TextBase extends TextBaseCommon {
205205
if (dict.size > 0 || isTextView) {
206206
if (style.color) {
207207
dict.set(NSForegroundColorAttributeName, style.color.ios);
208-
} else if (majorVersion >= 13) {
208+
} else if (majorVersion >= 13 && UIColor.labelColor) {
209209
dict.set(NSForegroundColorAttributeName, UIColor.labelColor);
210210
}
211211
}

0 commit comments

Comments
 (0)