mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-14 18:12:09 +08:00
fix(core): improved handling for unsupported '!important' css rule (#10243)
This commit is contained in:

committed by
GitHub

parent
ea45758463
commit
e560cb1374
@ -1,9 +0,0 @@
|
||||
import { KeyframeAnimationInfo, KeyframeDeclaration, KeyframeInfo, UnparsedKeyframe } from '../animation/keyframe-animation';
|
||||
|
||||
export class CssAnimationParser {
|
||||
public static keyframeAnimationsFromCSSDeclarations(declarations: KeyframeDeclaration[]): KeyframeAnimationInfo[];
|
||||
|
||||
public static keyframesArrayFromCSS(keyframes: UnparsedKeyframe[]): KeyframeInfo[];
|
||||
}
|
||||
|
||||
export function parseKeyframeDeclarations(unparsedKeyframeDeclarations: KeyframeDeclaration[]): KeyframeDeclaration[];
|
@ -4,6 +4,7 @@ import { KeyframeAnimationInfo, KeyframeDeclaration, KeyframeInfo, UnparsedKeyfr
|
||||
import { timeConverter, animationTimingFunctionConverter } from '../styling/converters';
|
||||
|
||||
import { transformConverter } from '../styling/style-properties';
|
||||
import { cleanupImportantFlags } from './css-utils';
|
||||
|
||||
const ANIMATION_PROPERTY_HANDLERS = Object.freeze({
|
||||
'animation-name': (info: any, value: any) => (info.name = value),
|
||||
@ -125,6 +126,7 @@ function keyframeAnimationsFromCSSProperty(value: any, animations: KeyframeAnima
|
||||
export function parseKeyframeDeclarations(unparsedKeyframeDeclarations: KeyframeDeclaration[]): KeyframeDeclaration[] {
|
||||
const declarations = unparsedKeyframeDeclarations.reduce((declarations, { property: unparsedProperty, value: unparsedValue }) => {
|
||||
const property = CssAnimationProperty._getByCssName(unparsedProperty);
|
||||
unparsedValue = cleanupImportantFlags(unparsedValue, property?.cssLocalName);
|
||||
|
||||
if (typeof unparsedProperty === 'string' && property && property._valueConverter) {
|
||||
declarations[property.name] = property._valueConverter(<string>unparsedValue);
|
||||
|
12
packages/core/ui/styling/css-utils.ts
Normal file
12
packages/core/ui/styling/css-utils.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Trace } from '../../trace';
|
||||
|
||||
export function cleanupImportantFlags(value: string, propertyName: string) {
|
||||
const index = value?.indexOf('!important');
|
||||
if (index >= 0) {
|
||||
if (Trace.isEnabled()) {
|
||||
Trace.write(`The !important css rule is currently not supported. Property: ${propertyName}`, Trace.categories.Style, Trace.messageType.warn);
|
||||
}
|
||||
return value.substring(0, index).trim();
|
||||
}
|
||||
return value;
|
||||
}
|
@ -21,6 +21,7 @@ function ensureKeyframeAnimationModule() {
|
||||
import * as capm from './css-animation-parser';
|
||||
import { sanitizeModuleName } from '../builder/module-name-sanitizer';
|
||||
import { resolveModuleName } from '../../module-name-resolver';
|
||||
import { cleanupImportantFlags } from './css-utils';
|
||||
|
||||
let cssAnimationParserModule: typeof capm;
|
||||
function ensureCssAnimationParserModule() {
|
||||
@ -563,7 +564,6 @@ export class CssState {
|
||||
const view = this.viewRef.get();
|
||||
if (!view) {
|
||||
Trace.write(`${matchingSelectors} not set to view's property because ".viewRef" is cleared`, Trace.categories.Style, Trace.messageType.warn);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -579,7 +579,8 @@ export class CssState {
|
||||
const replacementFunc = (g) => g[1].toUpperCase();
|
||||
|
||||
for (const property in newPropertyValues) {
|
||||
const value = newPropertyValues[property];
|
||||
const value = cleanupImportantFlags(newPropertyValues[property], property);
|
||||
|
||||
const isCssExp = isCssVariableExpression(value) || isCssCalcExpression(value);
|
||||
|
||||
if (isCssExp) {
|
||||
|
Reference in New Issue
Block a user