Skip to content

Commit 8fa3c1d

Browse files
authored
fix: support css variables in dynamic style (#68)
1 parent ff71723 commit 8fa3c1d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/angular/src/lib/view-util.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NamespaceFilter } from './property-filter';
55

66
import { NativeScriptDebug } from './trace';
77
import { NgLayoutBase } from './views/view-types';
8+
import { isCssVariable } from '@nativescript/core/ui/core/properties';
89

910
const ELEMENT_NODE_TYPE = 1;
1011
const XML_ATTRIBUTES = Object.freeze(['style', 'rows', 'columns', 'fontAttributes']);
@@ -497,10 +498,21 @@ export class ViewUtil {
497498
}
498499

499500
public setStyle(view: View, styleName: string, value: any) {
500-
view.style[styleName] = value;
501+
if (isCssVariable(styleName)) {
502+
view.style.setUnscopedCssVariable(styleName, value);
503+
view._onCssStateChange();
504+
} else {
505+
view.style[styleName] = value;
506+
}
501507
}
502508

503509
public removeStyle(view: View, styleName: string) {
504-
view.style[styleName] = unsetValue;
510+
if (isCssVariable(styleName)) {
511+
// TODO: expose this on core
512+
(view.style as any).unscopedCssVariables.delete(styleName);
513+
view._onCssStateChange();
514+
} else {
515+
view.style[styleName] = unsetValue;
516+
}
505517
}
506518
}

0 commit comments

Comments
 (0)