fix(iOS): check for iOS 13 APIs (#8093)

This commit is contained in:
Vasil Chimev
2019-11-18 13:39:00 +02:00
committed by GitHub
parent d983f79923
commit b069ff38f3
12 changed files with 30 additions and 19 deletions

View File

@ -89,7 +89,7 @@ class CADisplayLinkTarget extends NSObject {
} }
class IOSApplication implements IOSApplicationDefinition { class IOSApplication implements IOSApplicationDefinition {
private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; private _backgroundColor = (majorVersion <= 12 || !UIColor.systemBackgroundColor) ? UIColor.whiteColor : UIColor.systemBackgroundColor;
private _delegate: typeof UIApplicationDelegate; private _delegate: typeof UIApplicationDelegate;
private _window: UIWindow; private _window: UIWindow;
private _observers: Array<NotificationObserver>; private _observers: Array<NotificationObserver>;
@ -121,7 +121,6 @@ class IOSApplication implements IOSApplicationDefinition {
} }
get systemAppearance(): "light" | "dark" | null { get systemAppearance(): "light" | "dark" | null {
// userInterfaceStyle is available on UITraitCollection since iOS 12. // userInterfaceStyle is available on UITraitCollection since iOS 12.
if (majorVersion <= 11) { if (majorVersion <= 11) {
return null; return null;

View File

@ -9,7 +9,7 @@ const majorVersion = ios.MajorVersion;
export class ActivityIndicator extends ActivityIndicatorBase { export class ActivityIndicator extends ActivityIndicatorBase {
nativeViewProtected: UIActivityIndicatorView; nativeViewProtected: UIActivityIndicatorView;
private _activityIndicatorViewStyle = majorVersion <= 12 ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium; private _activityIndicatorViewStyle = (majorVersion <= 12 || !UIActivityIndicatorViewStyle.Medium) ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium;
createNativeView() { createNativeView() {
const viewStyle = this._activityIndicatorViewStyle; const viewStyle = this._activityIndicatorViewStyle;

View File

@ -93,7 +93,9 @@ class UITabBarControllerImpl extends UITabBarController {
if (majorVersion >= 13) { if (majorVersion >= 13) {
const owner = this._owner.get(); const owner = this._owner.get();
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner }); owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
} }
} }

View File

@ -1012,7 +1012,9 @@ export namespace ios {
if (majorVersion >= 13) { if (majorVersion >= 13) {
const owner = this.owner.get(); const owner = this.owner.get();
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: traitCollectionColorAppearanceChangedEvent, object: owner }); owner.notify({ eventName: traitCollectionColorAppearanceChangedEvent, object: owner });
} }
} }

View File

@ -540,7 +540,9 @@ class UINavigationControllerImpl extends UINavigationController {
if (majorVersion >= 13) { if (majorVersion >= 13) {
const owner = this._owner.get(); const owner = this._owner.get();
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner }); owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
} }
} }

View File

@ -59,7 +59,7 @@ export class HtmlView extends HtmlViewBase {
null null
); );
if (majorVersion >= 13) { if (majorVersion >= 13 && UIColor.labelColor) {
this.nativeViewProtected.textColor = UIColor.labelColor; this.nativeViewProtected.textColor = UIColor.labelColor;
} }
} }

View File

@ -287,7 +287,9 @@ class UIViewControllerImpl extends UIViewController {
if (majorVersion >= 13) { if (majorVersion >= 13) {
const owner = this._owner.get(); const owner = this._owner.get();
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner }); owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
} }
} }
@ -298,7 +300,7 @@ export class Page extends PageBase {
nativeViewProtected: UIView; nativeViewProtected: UIView;
viewController: UIViewControllerImpl; viewController: UIViewControllerImpl;
private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; private _backgroundColor = (majorVersion <= 12 && !UIColor.systemBackgroundColor) ? UIColor.whiteColor : UIColor.systemBackgroundColor;
private _ios: UIViewControllerImpl; private _ios: UIViewControllerImpl;
public _presentedViewController: UIViewController; // used when our page present native viewController without going through our abstraction. public _presentedViewController: UIViewController; // used when our page present native viewController without going through our abstraction.

View File

@ -78,7 +78,9 @@ class UITabBarControllerImpl extends UITabBarController {
if (majorVersion >= 13) { if (majorVersion >= 13) {
const owner = this._owner.get(); const owner = this._owner.get();
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner }); owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
} }
} }

View File

@ -24,7 +24,7 @@ export * from "./tabs-common";
const majorVersion = iosUtils.MajorVersion; const majorVersion = iosUtils.MajorVersion;
// Equivalent to dispatch_async(dispatch_get_main_queue(...)) call // Equivalent to dispatch_async(dispatch_get_main_queue(...)) call
const invokeOnRunLoop = (function() { const invokeOnRunLoop = (function () {
const runloop = CFRunLoopGetMain(); const runloop = CFRunLoopGetMain();
return (action: () => any) => { return (action: () => any) => {
@ -100,7 +100,7 @@ class UIPageViewControllerImpl extends UIPageViewController {
tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner)); tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner));
if (majorVersion <= 12) { if (majorVersion <= 12 || !UIColor.labelColor) {
tabBar.tintColor = UIColor.blueColor; tabBar.tintColor = UIColor.blueColor;
tabBar.barTintColor = UIColor.whiteColor; tabBar.barTintColor = UIColor.whiteColor;
tabBar.setTitleColorForState(UIColor.blackColor, MDCTabBarItemState.Normal); tabBar.setTitleColorForState(UIColor.blackColor, MDCTabBarItemState.Normal);
@ -216,7 +216,9 @@ class UIPageViewControllerImpl extends UIPageViewController {
if (majorVersion >= 13) { if (majorVersion >= 13) {
const owner = this._owner.get(); const owner = this._owner.get();
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) { if (owner &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection &&
this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner }); owner.notify({ eventName: iosView.traitCollectionColorAppearanceChangedEvent, object: owner });
} }
} }

View File

@ -153,7 +153,7 @@ export class TextBase extends TextBaseCommon {
this.nativeTextViewProtected.setAttributedTitleForState(attrText, UIControlState.Normal); this.nativeTextViewProtected.setAttributedTitleForState(attrText, UIControlState.Normal);
} }
else { else {
if (majorVersion >= 13) { if (majorVersion >= 13 && UIColor.labelColor) {
this.nativeTextViewProtected.textColor = UIColor.labelColor; this.nativeTextViewProtected.textColor = UIColor.labelColor;
} }
@ -205,7 +205,7 @@ export class TextBase extends TextBaseCommon {
if (dict.size > 0 || isTextView) { if (dict.size > 0 || isTextView) {
if (style.color) { if (style.color) {
dict.set(NSForegroundColorAttributeName, style.color.ios); dict.set(NSForegroundColorAttributeName, style.color.ios);
} else if (majorVersion >= 13) { } else if (majorVersion >= 13 && UIColor.labelColor) {
dict.set(NSForegroundColorAttributeName, UIColor.labelColor); dict.set(NSForegroundColorAttributeName, UIColor.labelColor);
} }
} }

View File

@ -116,8 +116,8 @@ export class TextView extends EditableTextBase implements TextViewDefinition {
private _isShowingHint: boolean; private _isShowingHint: boolean;
public _isEditing: boolean; public _isEditing: boolean;
private _hintColor = majorVersion <= 12 ? UIColor.blackColor.colorWithAlphaComponent(0.22) : UIColor.placeholderTextColor; private _hintColor = (majorVersion <= 12 || !UIColor.placeholderTextColor) ? UIColor.blackColor.colorWithAlphaComponent(0.22) : UIColor.placeholderTextColor;
private _textColor = majorVersion <= 12 ? null : UIColor.labelColor; private _textColor = (majorVersion <= 12 || !UIColor.labelColor) ? null : UIColor.labelColor;
createNativeView() { createNativeView() {
const textView = NoScrollAnimationUITextView.new(); const textView = NoScrollAnimationUITextView.new();

View File

@ -385,7 +385,7 @@ export function test_page_backgroundColor() {
helper.navigate(factory); helper.navigate(factory);
if (isIOS) { if (isIOS) {
const backgroundColor = ios.MajorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; const backgroundColor = (ios.MajorVersion <= 12 || !UIColor.systemBackgroundColor) ? UIColor.whiteColor : UIColor.systemBackgroundColor;
TKUnit.assertEqual(page.nativeView.backgroundColor, backgroundColor, "page backgroundColor is wrong"); TKUnit.assertEqual(page.nativeView.backgroundColor, backgroundColor, "page backgroundColor is wrong");
} else { } else {
const whiteColor = new Color("white"); const whiteColor = new Color("white");