Skip to content

feat(css): add attribute scoped css without global refresh #7907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 8, 2019

Conversation

joshcomley
Copy link
Contributor

@joshcomley joshcomley commented Oct 5, 2019

As per the problem I reported here:
NativeScript/theme#179

When using component scoped CSS there is no need to trigger a full global refresh of the styles.

This change does not affect performance or function of using encapsulation: ViewEncapsulation.None on a component.

This PR goes hand in hand with a modification to nativescript-angular to employ the below changes (PR coming up right after this).

PR Checklist

What is the current behavior?

What is the new behavior?

Fixes/Implements/Closes #[Issue Number].

@joshcomley
Copy link
Contributor Author

I am happy to resubmit this PR following the above guidelines (I am not entirely sure how to compose the PR title, for example), but would somebody be able to review the code to ensure it's a valid PR otherwise? Many thanks

Copy link
Contributor

@charsleysa charsleysa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure that the code passes the tslint check.

You can run this locally by running npm run tslint

const rootView = getRootView();
if (rootView) {
rootView._onCssStateChange();
if(!scoped) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space between if and (

@charsleysa
Copy link
Contributor

For PR title, follow this guideline: https://github.com/NativeScript/NativeScript/blob/master/CONTRIBUTING.md#commit-messages

You could would end up with something like feat(css): add scoped css without global refresh

@@ -177,11 +177,13 @@ export function run(entry?: NavigationEntry | string) {
_start(entry);
}

export function addCss(cssText: string): void {
export function addCss(cssText: string, scoped?: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function addCss(cssText: string, scoped?: boolean): void {
export function addCss(cssText: string, attributeScoped?: boolean): void {

This implementation is needed only when the css is global, but scoped by attributes (like in Angular and Vue). To differentiate this from the {N} Core implementation with style scope objects I think it's a better naming.

@@ -371,11 +371,13 @@ export function run(entry?: string | NavigationEntry) {
_start(entry);
}

export function addCss(cssText: string): void {
export function addCss(cssText: string, scoped?: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function addCss(cssText: string, scoped?: boolean): void {
export function addCss(cssText: string, attributeScoped?: boolean): void {

@@ -177,11 +177,13 @@ export function run(entry?: NavigationEntry | string) {
_start(entry);
}

export function addCss(cssText: string): void {
export function addCss(cssText: string, scoped?: boolean): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add this new parameter to the d.t.s too explaining it can be used when you add global css that is scoped by attribute for example.

@joshcomley joshcomley changed the title Support for adding scoped CSS without triggering global refresh feat(css): add attribute scoped css without global refresh Oct 8, 2019
@joshcomley
Copy link
Contributor Author

Hi there,

Thanks for the suggestions, I've implemented these and updated the PR.

@MartoYankov
Copy link
Contributor

test --ignore

@MartoYankov
Copy link
Contributor

test --ignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants