Skip to content

Commit bfea96f

Browse files
vchimevmanoldonev
authored andcommitted
fix-next(css-classes): increase application CSS selector version at runtime (#7992)
1 parent 07abee7 commit bfea96f

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

nativescript-core/application/application-common.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ function removeCssClass(rootView: View, cssClass: string) {
142142
rootView.cssClasses.delete(cssClass);
143143
}
144144

145+
function increaseStyleScopeApplicationCssSelectorVersion(rootView: View) {
146+
const styleScope = rootView._styleScope || ((<any>rootView).currentPage && (<any>rootView).currentPage._styleScope);
147+
148+
if (styleScope) {
149+
styleScope._increaseApplicationCssSelectorVersion();
150+
}
151+
}
152+
145153
export function orientationChanged(rootView: View, newOrientation: "portrait" | "landscape" | "unknown"): void {
146154
if (!rootView) {
147155
return;
@@ -151,6 +159,7 @@ export function orientationChanged(rootView: View, newOrientation: "portrait" |
151159
if (!rootView.cssClasses.has(newOrientationCssClass)) {
152160
ORIENTATION_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
153161
applyCssClass(rootView, newOrientationCssClass);
162+
increaseStyleScopeApplicationCssSelectorVersion(rootView);
154163
rootView._onCssStateChange();
155164
}
156165
}
@@ -164,6 +173,7 @@ export function systemAppearanceChanged(rootView: View, newSystemAppearance: "da
164173
if (!rootView.cssClasses.has(newSystemAppearanceCssClass)) {
165174
SYSTEM_APPEARANCE_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
166175
applyCssClass(rootView, newSystemAppearanceCssClass);
176+
increaseStyleScopeApplicationCssSelectorVersion(rootView);
167177
rootView._onCssStateChange();
168178
}
169179
}

nativescript-core/ui/styling/style-scope.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export class StyleScope {
3636
public static createSelectorsFromImports(tree: SyntaxTree, keyframes: Object): RuleSet[];
3737
public ensureSelectors(): number;
3838

39+
/**
40+
* Increase the application CSS selector version.
41+
*/
42+
public _increaseApplicationCssSelectorVersion(): void;
3943
public isApplicationCssSelectorsLatestVersionApplied(): boolean;
4044
public isLocalCssSelectorsLatestVersionApplied(): boolean;
4145

nativescript-core/ui/styling/style-scope.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@ export class StyleScope {
760760
return this._getSelectorsVersion();
761761
}
762762

763+
public _increaseApplicationCssSelectorVersion(): void {
764+
applicationCssSelectorVersion++;
765+
}
766+
763767
public isApplicationCssSelectorsLatestVersionApplied(): boolean {
764768
return this._applicationCssSelectorsAppliedVersion === applicationCssSelectorVersion;
765769
}

0 commit comments

Comments
 (0)