fix: UIUserInterfaceStyle is undefined for iOS <= 11 (#7931)

This commit is contained in:
Vasil Chimev
2019-10-16 16:41:47 +03:00
committed by Manol Donev
parent ce96dad398
commit 6c7139477e
6 changed files with 103 additions and 7 deletions

View File

@@ -23,5 +23,5 @@ export function testDisplayedEvent() {
}
export function testOrientation() {
TKUnit.assert(app.orientation, "Orientation not initialized.");
TKUnit.assert(app.orientation(), "Orientation not initialized.");
}

View File

@@ -46,4 +46,9 @@ export function testAndroidApplicationInitialized() {
TKUnit.assert(app.android.nativeApp, "Android nativeApp not initialized.");
TKUnit.assert(app.android.orientation, "Android orientation not initialized.");
TKUnit.assert(app.android.packageName, "Android packageName not initialized.");
TKUnit.assert(app.android.systemAppearance, "Android system appearance not initialized.");
}
export function testSystemAppearance() {
TKUnit.assert(app.systemAppearance(), "System appearance not initialized.");
}

View File

@@ -1,5 +1,6 @@
/* tslint:disable:no-unused-variable */
import * as app from "tns-core-modules/application";
import { ios } from "tns-core-modules/utils/utils";
import * as TKUnit from "../tk-unit";
export * from "./application-tests-common";
@@ -46,6 +47,21 @@ export function testIOSApplicationInitialized() {
TKUnit.assert(app.ios.delegate, "iOS delegate not initialized.");
TKUnit.assert(app.ios.nativeApp, "iOS nativeApp not initialized.");
TKUnit.assert(app.ios.orientation, "iOS orientation not initialized.");
if (ios.MajorVersion <= 11) {
TKUnit.assertNull(app.ios.systemAppearance, "iOS system appearance should be `null` on iOS <= 11.");
} else {
TKUnit.assert(app.ios.systemAppearance, "iOS system appearance not initialized.");
}
TKUnit.assert(app.ios.window, "iOS window not initialized.");
TKUnit.assert(app.ios.rootController, "iOS root controller not initialized.");
}
export function testSystemAppearance() {
if (ios.MajorVersion <= 11) {
TKUnit.assertNull(app.systemAppearance(), "System appearance should be `null` on iOS <= 11.");
} else {
TKUnit.assert(app.systemAppearance(), "System appearance not initialized.");
}
}

View File

@@ -8,6 +8,7 @@ import {
} from "tns-core-modules/application";
import {
isAndroid,
isIOS,
device
} from "tns-core-modules/platform";
import { Button } from "tns-core-modules/ui/button/button";
@@ -21,6 +22,7 @@ import {
_rootModalViews
} from "tns-core-modules/ui/core/view/view-common";
import { DeviceType } from "tns-core-modules/ui/enums/enums";
import { ios as iosUtils } from "tns-core-modules/utils/utils";
const CLASS_NAME = "class-name";
const ROOT_CSS_CLASS = "ns-root";
@@ -32,6 +34,8 @@ const TABLET_DEVICE_TYPE_CSS_CLASS = "ns-tablet";
const PORTRAIT_ORIENTATION_CSS_CLASS = "ns-portrait";
const LANDSCAPE_ORIENTATION_CSS_CLASS = "ns-landscape";
const UNKNOWN_ORIENTATION_CSS_CLASS = "ns-unknown";
const DARK_SYSTEM_APPEARANCE_CSS_CLASS = "ns-dark";
const LIGHT_SYSTEM_APPEARANCE_CSS_CLASS = "ns-light";
function _test_root_view_root_css_class(shouldSetClassName: boolean) {
const rootView = getRootView();
@@ -221,6 +225,66 @@ export function test_root_view_class_name_preserve_orientation_css_class() {
_test_root_view_orientation_css_class(true);
}
function _test_root_view_system_appearance_css_class(shouldSetClassName: boolean) {
const rootView = getRootView();
if (shouldSetClassName) {
rootView.className = CLASS_NAME;
}
const rootViewCssClasses = rootView.cssClasses;
let systemAppearance;
if (isAndroid) {
systemAppearance = android.systemAppearance;
} else {
systemAppearance = ios.systemAppearance;
}
if (isIOS && iosUtils.MajorVersion <= 12) {
TKUnit.assertFalse(rootViewCssClasses.has(
DARK_SYSTEM_APPEARANCE_CSS_CLASS),
`${DARK_SYSTEM_APPEARANCE_CSS_CLASS} CSS class is present`
);
TKUnit.assertFalse(rootViewCssClasses.has(
LIGHT_SYSTEM_APPEARANCE_CSS_CLASS),
`${LIGHT_SYSTEM_APPEARANCE_CSS_CLASS} CSS class is present`
);
} else if (systemAppearance === "dark") {
TKUnit.assertTrue(rootViewCssClasses.has(
DARK_SYSTEM_APPEARANCE_CSS_CLASS),
`${DARK_SYSTEM_APPEARANCE_CSS_CLASS} CSS class is missing`
);
TKUnit.assertFalse(rootViewCssClasses.has(
LIGHT_SYSTEM_APPEARANCE_CSS_CLASS),
`${LIGHT_SYSTEM_APPEARANCE_CSS_CLASS} CSS class is present`
);
} else if (systemAppearance === "light") {
TKUnit.assertTrue(rootViewCssClasses.has(
LIGHT_SYSTEM_APPEARANCE_CSS_CLASS),
`${LIGHT_SYSTEM_APPEARANCE_CSS_CLASS} CSS class is missing`
);
TKUnit.assertFalse(rootViewCssClasses.has(
DARK_SYSTEM_APPEARANCE_CSS_CLASS),
`${DARK_SYSTEM_APPEARANCE_CSS_CLASS} CSS class is present`
);
}
if (shouldSetClassName) {
TKUnit.assertTrue(rootViewCssClasses.has(
CLASS_NAME),
`${CLASS_NAME} CSS class is missing`
);
}
}
export function test_root_view_system_appearance_css_class() {
_test_root_view_system_appearance_css_class(false);
}
export function test_root_view_class_name_preserve_system_appearance_css_class() {
_test_root_view_system_appearance_css_class(true);
}
function _test_modal_root_view_modal_css_class(shouldSetClassName: boolean) {
let modalClosed = false;