nativescript-theme-core
Advanced tools
Comparing version 2.0.8 to 2.0.9
@@ -0,1 +1,21 @@ | ||
<a name="2.0.9 beta"></a> | ||
## [2.0.9 beta](https://github.com/NativeScript/theme/compare/v2.0.8...v2.0.9) (2019-08-29) | ||
### Features | ||
* Add small API for setMode. Usage: | ||
```javascript | ||
import Theme from "nativescript-theme-core"; | ||
Theme.setMode(Theme.Dark); // Or Theme.Light | ||
``` | ||
It would set light or dark mode even before the app is initialized. | ||
### Fixes | ||
* Simplify ClassList, use Set | ||
* Fix dark mode for TabView, BottomNavigation and Tabs if they are root views | ||
<a name="2.0.8 beta"></a> | ||
@@ -2,0 +22,0 @@ ## [2.0.8 beta](https://github.com/NativeScript/theme/compare/v2.0.7...v2.0.8) (2019-08-28) |
77
index.js
@@ -1,21 +0,20 @@ | ||
import { on, displayedEvent, orientationChangedEvent, getRootView } from "tns-core-modules/application"; | ||
import * as app from "tns-core-modules/application"; | ||
import { device, isAndroid, screen } from "tns-core-modules/platform"; | ||
import * as viewCommon from "tns-core-modules/ui/core/view/view-common"; | ||
import { Frame } from "tns-core-modules/ui/frame"; | ||
import * as frame from "tns-core-modules/ui/frame"; | ||
const display = screen.mainScreen; | ||
const whiteSpaceRegExp = /\s+/; | ||
let started = false; | ||
const display = screen.mainScreen; | ||
export class ClassList { | ||
constructor(className) { | ||
this.list = (className || "").split(/\s+/); | ||
this.list = new Set(); | ||
(className || "").split(whiteSpaceRegExp).forEach((v) => v && this.list.add(v)); | ||
} | ||
add(...classes) { | ||
classes.forEach((value) => { | ||
if (this.list.indexOf(value) === -1) { | ||
this.list.push(value); | ||
} | ||
}); | ||
classes.forEach((v) => this.list.add(v)); | ||
@@ -26,10 +25,4 @@ return this; | ||
remove(...classes) { | ||
classes.forEach((value) => { | ||
const index = this.list.indexOf(value); | ||
classes.forEach((v) => this.list.delete(v)); | ||
if (index !== -1) { | ||
delete this.list[index]; | ||
} | ||
}); | ||
return this; | ||
@@ -39,7 +32,41 @@ } | ||
get() { | ||
return this.list.join(" "); | ||
return Array.from(this.list).join(" "); | ||
} | ||
} | ||
function updateRootClasses(orientation, root = getRootView(), classes = []) { | ||
export default class Theme { | ||
static setMode(mode = Theme.Light, root = app.getRootView()) { | ||
Theme.currentMode = mode; | ||
Theme.rootView = root; | ||
if (!root) { | ||
return; | ||
} | ||
const classList = new ClassList(Theme.rootView.className); | ||
classList | ||
.remove(Theme.Light, Theme.Dark) | ||
.add(Theme.currentMode); | ||
Theme.rootView.className = classList.get(); | ||
} | ||
static getMode() { | ||
return Theme.currentMode; | ||
} | ||
} | ||
Theme.Light = "ns-light"; | ||
Theme.Dark = "ns-dark"; | ||
Theme.currentMode = Theme.Light; | ||
// Where the magic happens | ||
const oldSetupAsRootView = viewCommon.ViewCommon.prototype._setupAsRootView; | ||
viewCommon.ViewCommon.prototype._setupAsRootView = function() { | ||
oldSetupAsRootView.call(this, ...arguments); | ||
Theme.setMode(Theme.currentMode); | ||
}; | ||
function updateRootClasses(orientation, root = app.getRootView(), classes = []) { | ||
const classList = new ClassList(root.className); | ||
@@ -58,3 +85,3 @@ | ||
if (viewCommon._rootModalViews.length) { | ||
const classList = new ClassList(getRootView().className); | ||
const classList = new ClassList(app.getRootView().className); | ||
@@ -74,4 +101,4 @@ viewCommon._rootModalViews.forEach((view) => updateRootClasses(orientation, view, classList.list.concat("ns-modal"))); | ||
if (desc.value instanceof Frame) { | ||
const classList = new ClassList(getRootView().className); | ||
if (desc.value instanceof frame.Frame) { | ||
const classList = new ClassList(app.getRootView().className); | ||
@@ -89,4 +116,4 @@ updateRootClasses(getOrientation(), desc.value, classList.list.concat("ns-modal")); | ||
on(displayedEvent, () => { | ||
const root = getRootView(); | ||
app.on(app.displayedEvent, () => { | ||
const root = app.getRootView(); | ||
const classList = new ClassList(root.className); | ||
@@ -100,5 +127,5 @@ | ||
handleOrientation({ newValue: getOrientation() }); | ||
on(orientationChangedEvent, handleOrientation); | ||
app.on(app.orientationChangedEvent, handleOrientation); | ||
started = true; | ||
} | ||
}); |
{ | ||
"name": "nativescript-theme-core", | ||
"version": "2.0.8", | ||
"version": "2.0.9", | ||
"description": "Telerik NativeScript Core Theme", | ||
@@ -14,6 +14,6 @@ "author": "Telerik <support@telerik.com>", | ||
"platforms": { | ||
"android": "6.0.2", | ||
"ios": "6.0.2" | ||
"android": "next", | ||
"ios": "next" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
212
390300