@@ -17,7 +17,12 @@ export * from "./application-common";
17
17
18
18
// TODO: Remove this and get it from global to decouple builder for angular
19
19
import { createViewFromEntry } from "../ui/builder" ;
20
- import { CLASS_PREFIX , getRootViewCssClasses , pushToRootViewCssClasses } from "../css/system-classes" ;
20
+ import {
21
+ CLASS_PREFIX ,
22
+ getRootViewCssClasses ,
23
+ pushToRootViewCssClasses ,
24
+ resetRootViewCssClasses
25
+ } from "../css/system-classes" ;
21
26
import { ios as iosView , View } from "../ui/core/view" ;
22
27
import { Frame , NavigationEntry } from "../ui/frame" ;
23
28
import { device } from "../platform/platform" ;
@@ -311,14 +316,13 @@ function createRootView(v?: View) {
311
316
}
312
317
}
313
318
319
+ resetRootViewCssClasses ( ) ;
320
+
314
321
const deviceType = device . deviceType . toLowerCase ( ) ;
315
322
pushToRootViewCssClasses ( `${ CLASS_PREFIX } ${ IOS_PLATFORM } ` ) ;
316
323
pushToRootViewCssClasses ( `${ CLASS_PREFIX } ${ deviceType } ` ) ;
317
324
pushToRootViewCssClasses ( `${ CLASS_PREFIX } ${ iosApp . orientation } ` ) ;
318
325
319
- const rootViewCssClasses = getRootViewCssClasses ( ) ;
320
- rootViewCssClasses . forEach ( c => rootView . cssClasses . add ( c ) ) ;
321
-
322
326
return rootView ;
323
327
}
324
328
@@ -388,18 +392,36 @@ export function getNativeApplication(): UIApplication {
388
392
return iosApp . nativeApp ;
389
393
}
390
394
391
- function getViewController ( view : View ) : UIViewController {
392
- let viewController : UIViewController = view . viewController || view . ios ;
393
- if ( viewController instanceof UIViewController ) {
394
- return viewController ;
395
- } else {
395
+ function getUserInterfaceStyleValue ( userInterfaceStyle : number ) : "dark" | "light" | "unspecified" {
396
+ switch ( userInterfaceStyle ) {
397
+ case UIUserInterfaceStyle . Unspecified :
398
+ case UIUserInterfaceStyle . Light :
399
+ return "light" ;
400
+ case UIUserInterfaceStyle . Dark :
401
+ return "dark" ;
402
+ }
403
+ }
404
+
405
+ // TODO: Rename to getRootViewController
406
+ function getViewController ( rootView : View ) : UIViewController {
407
+ let viewController : UIViewController = rootView . viewController || rootView . ios ;
408
+
409
+ if ( ! ( viewController instanceof UIViewController ) ) {
396
410
// We set UILayoutViewController dynamically to the root view if it doesn't have a view controller
397
411
// At the moment the root view doesn't have its native view created. We set it in the setViewControllerView func
398
- viewController = iosView . UILayoutViewController . initWithOwner ( new WeakRef ( view ) ) as UIViewController ;
399
- view . viewController = viewController ;
400
-
401
- return viewController ;
412
+ viewController = iosView . UILayoutViewController . initWithOwner ( new WeakRef ( rootView ) ) as UIViewController ;
413
+ rootView . viewController = viewController ;
402
414
}
415
+
416
+ const userInterfaceStyle = viewController . traitCollection . userInterfaceStyle ;
417
+ const userInterfaceStyleValue = getUserInterfaceStyleValue ( userInterfaceStyle ) ;
418
+
419
+ pushToRootViewCssClasses ( `${ CLASS_PREFIX } ${ userInterfaceStyleValue } ` ) ;
420
+
421
+ const rootViewCssClasses = getRootViewCssClasses ( ) ;
422
+ rootViewCssClasses . forEach ( c => rootView . cssClasses . add ( c ) ) ;
423
+
424
+ return viewController ;
403
425
}
404
426
405
427
function setViewControllerView ( view : View ) : void {
0 commit comments