8
8
} from "tns-core-modules/application" ;
9
9
import {
10
10
isAndroid ,
11
+ isIOS ,
11
12
device
12
13
} from "tns-core-modules/platform" ;
13
14
import { Button } from "tns-core-modules/ui/button/button" ;
@@ -21,6 +22,7 @@ import {
21
22
_rootModalViews
22
23
} from "tns-core-modules/ui/core/view/view-common" ;
23
24
import { DeviceType } from "tns-core-modules/ui/enums/enums" ;
25
+ import { ios as iosUtils } from "tns-core-modules/utils/utils" ;
24
26
25
27
const CLASS_NAME = "class-name" ;
26
28
const ROOT_CSS_CLASS = "ns-root" ;
@@ -32,6 +34,8 @@ const TABLET_DEVICE_TYPE_CSS_CLASS = "ns-tablet";
32
34
const PORTRAIT_ORIENTATION_CSS_CLASS = "ns-portrait" ;
33
35
const LANDSCAPE_ORIENTATION_CSS_CLASS = "ns-landscape" ;
34
36
const UNKNOWN_ORIENTATION_CSS_CLASS = "ns-unknown" ;
37
+ const DARK_SYSTEM_APPEARANCE_CSS_CLASS = "ns-dark" ;
38
+ const LIGHT_SYSTEM_APPEARANCE_CSS_CLASS = "ns-light" ;
35
39
36
40
function _test_root_view_root_css_class ( shouldSetClassName : boolean ) {
37
41
const rootView = getRootView ( ) ;
@@ -221,6 +225,66 @@ export function test_root_view_class_name_preserve_orientation_css_class() {
221
225
_test_root_view_orientation_css_class ( true ) ;
222
226
}
223
227
228
+ function _test_root_view_system_appearance_css_class ( shouldSetClassName : boolean ) {
229
+ const rootView = getRootView ( ) ;
230
+ if ( shouldSetClassName ) {
231
+ rootView . className = CLASS_NAME ;
232
+ }
233
+
234
+ const rootViewCssClasses = rootView . cssClasses ;
235
+ let systemAppearance ;
236
+
237
+ if ( isAndroid ) {
238
+ systemAppearance = android . systemAppearance ;
239
+ } else {
240
+ systemAppearance = ios . systemAppearance ;
241
+ }
242
+
243
+ if ( isIOS && iosUtils . MajorVersion <= 12 ) {
244
+ TKUnit . assertFalse ( rootViewCssClasses . has (
245
+ DARK_SYSTEM_APPEARANCE_CSS_CLASS ) ,
246
+ `${ DARK_SYSTEM_APPEARANCE_CSS_CLASS } CSS class is present`
247
+ ) ;
248
+ TKUnit . assertFalse ( rootViewCssClasses . has (
249
+ LIGHT_SYSTEM_APPEARANCE_CSS_CLASS ) ,
250
+ `${ LIGHT_SYSTEM_APPEARANCE_CSS_CLASS } CSS class is present`
251
+ ) ;
252
+ } else if ( systemAppearance === "dark" ) {
253
+ TKUnit . assertTrue ( rootViewCssClasses . has (
254
+ DARK_SYSTEM_APPEARANCE_CSS_CLASS ) ,
255
+ `${ DARK_SYSTEM_APPEARANCE_CSS_CLASS } CSS class is missing`
256
+ ) ;
257
+ TKUnit . assertFalse ( rootViewCssClasses . has (
258
+ LIGHT_SYSTEM_APPEARANCE_CSS_CLASS ) ,
259
+ `${ LIGHT_SYSTEM_APPEARANCE_CSS_CLASS } CSS class is present`
260
+ ) ;
261
+ } else if ( systemAppearance === "light" ) {
262
+ TKUnit . assertTrue ( rootViewCssClasses . has (
263
+ LIGHT_SYSTEM_APPEARANCE_CSS_CLASS ) ,
264
+ `${ LIGHT_SYSTEM_APPEARANCE_CSS_CLASS } CSS class is missing`
265
+ ) ;
266
+ TKUnit . assertFalse ( rootViewCssClasses . has (
267
+ DARK_SYSTEM_APPEARANCE_CSS_CLASS ) ,
268
+ `${ DARK_SYSTEM_APPEARANCE_CSS_CLASS } CSS class is present`
269
+ ) ;
270
+ }
271
+
272
+ if ( shouldSetClassName ) {
273
+ TKUnit . assertTrue ( rootViewCssClasses . has (
274
+ CLASS_NAME ) ,
275
+ `${ CLASS_NAME } CSS class is missing`
276
+ ) ;
277
+ }
278
+ }
279
+
280
+ export function test_root_view_system_appearance_css_class ( ) {
281
+ _test_root_view_system_appearance_css_class ( false ) ;
282
+ }
283
+
284
+ export function test_root_view_class_name_preserve_system_appearance_css_class ( ) {
285
+ _test_root_view_system_appearance_css_class ( true ) ;
286
+ }
287
+
224
288
function _test_modal_root_view_modal_css_class ( shouldSetClassName : boolean ) {
225
289
let modalClosed = false ;
226
290
0 commit comments