mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(style-scope): Resolve css sheets from tns_modules
If the css sheet is not in the app directory, try to find it in the tns_modules folder.
This commit is contained in:
1
tns-core-modules/ui/styling/style-scope.d.ts
vendored
1
tns-core-modules/ui/styling/style-scope.d.ts
vendored
@@ -32,5 +32,6 @@ declare module "ui/styling/style-scope" {
|
||||
public getAnimations(ruleset: RuleSet): KeyframeAnimationInfo[];
|
||||
}
|
||||
|
||||
export function resolveFileNameFromUrl(url: string, appDirectory: string, fileExists: (string) => boolean): string;
|
||||
export function applyInlineSyle(view: view.View, style: string): void;
|
||||
}
|
||||
|
||||
@@ -149,13 +149,11 @@ export class StyleScope {
|
||||
if (utils.isFileOrResourcePath(url)) {
|
||||
ensureFS();
|
||||
|
||||
let fileName = types.isString(url) ? url.trim() : "";
|
||||
if (fileName.indexOf("~/") === 0) {
|
||||
fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
|
||||
}
|
||||
let appDirectory = fs.knownFolders.currentApp().path;
|
||||
let fileName = resolveFileNameFromUrl(url, appDirectory, fs.File.exists);
|
||||
|
||||
if (fs.File.exists(fileName)) {
|
||||
let file = fs.File.fromPath(fileName);
|
||||
if (fileName !== null) {
|
||||
let file: fileSystemModule.File = fs.File.fromPath(fileName);
|
||||
let text = file.readTextSync();
|
||||
if (text) {
|
||||
selectors = selectors.concat(StyleScope.createSelectorsFromCss(text, fileName, keyframes));
|
||||
@@ -197,7 +195,7 @@ export class StyleScope {
|
||||
}
|
||||
|
||||
public applySelectors(view: view.View): void {
|
||||
this.ensureSelectors();
|
||||
this.ensureSelectors();
|
||||
|
||||
let state = this._selectors.query(view);
|
||||
|
||||
@@ -245,6 +243,26 @@ export class StyleScope {
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveFileNameFromUrl(url: string, appDirectory: string, fileExists: (string) => boolean): string {
|
||||
let fileName: string = types.isString(url) ? url.trim() : "";
|
||||
|
||||
if (fileName.indexOf("~/") === 0) {
|
||||
fileName = fileName.replace("~/", "");
|
||||
}
|
||||
|
||||
let local = fs.path.join(appDirectory, fileName);
|
||||
if (fileExists(local)) {
|
||||
return local;
|
||||
}
|
||||
|
||||
let external = fs.path.join(appDirectory, "tns_modules", fileName);
|
||||
if (fileExists(external)) {
|
||||
return external;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function applyInlineSyle(view: view.View, style: string) {
|
||||
try {
|
||||
let syntaxTree = cssParser.parse("local { " + style + " }", undefined);
|
||||
|
||||
Reference in New Issue
Block a user