Skip to content

Commit d36205d

Browse files
committed
fix(dark-mode): window and page background color
1 parent 077605c commit d36205d

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

tns-core-modules/application/application.ios.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const ROOT_VIEW_CSS_CLASSES = [
3232
`${CSS_CLASS_PREFIX}${IOS_PLATFORM}`
3333
];
3434
const getVisibleViewController = ios.getVisibleViewController;
35+
const majorVersion = ios.MajorVersion;
3536

3637
// NOTE: UIResponder with implementation of window - related to https://github.com/NativeScript/ios-runtime/issues/430
3738
// TODO: Refactor the UIResponder to use Typescript extends when this issue is resolved:
@@ -44,8 +45,8 @@ const Responder = (<any>UIResponder).extend({
4445
// NOOP
4546
}
4647
}, {
47-
protocols: [UIApplicationDelegate]
48-
}
48+
protocols: [UIApplicationDelegate]
49+
}
4950
);
5051

5152
class NotificationObserver extends NSObject {
@@ -163,11 +164,19 @@ class IOSApplication implements IOSApplicationDefinition {
163164
}
164165

165166
this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds);
167+
168+
// TODO: add CompatibilityColor.backgroundColor;
169+
let backgroundColor;
170+
if (majorVersion <= 12) {
171+
backgroundColor = UIColor.whiteColor;
172+
} else {
173+
backgroundColor = UIColor.systemBackgroundColor;
174+
}
175+
166176
// TODO: Expose Window module so that it can we styled from XML & CSS
167-
this._window.backgroundColor = UIColor.whiteColor;
177+
this._window.backgroundColor = backgroundColor;
168178

169179
this.notifyAppStarted(notification);
170-
171180
}
172181

173182
public notifyAppStarted(notification?: NSNotification) {

tns-core-modules/ui/page/page.ios.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class UIViewControllerImpl extends UIViewController {
148148
const isReplace = navigationContext.navigationType === NavigationType.replace;
149149

150150
frame.setCurrent(newEntry, navigationContext.navigationType);
151-
151+
152152
if (isReplace) {
153153
let controller = newEntry.resolvedPage.ios;
154154
if (controller) {
@@ -282,7 +282,6 @@ class UIViewControllerImpl extends UIViewController {
282282
}
283283
}
284284

285-
const whiteColor = new Color("white").ios;
286285
export class Page extends PageBase {
287286
nativeViewProtected: UIView;
288287
viewController: UIViewControllerImpl;
@@ -294,7 +293,17 @@ export class Page extends PageBase {
294293
super();
295294
const controller = UIViewControllerImpl.initWithOwner(new WeakRef(this));
296295
this.viewController = this._ios = controller;
297-
controller.view.backgroundColor = whiteColor;
296+
297+
// Make transitions look good
298+
let backgroundColor;
299+
if (majorVersion <= 12) {
300+
backgroundColor = UIColor.whiteColor;
301+
} else {
302+
backgroundColor = UIColor.systemBackgroundColor;
303+
}
304+
305+
// TODO: add CompatibilityColor.backgroundColor;
306+
controller.view.backgroundColor = backgroundColor;
298307
}
299308

300309
createNativeView() {

0 commit comments

Comments
 (0)