Skip to content

Css gradients - #5534

Merged
SvetoslavTsenov merged 18 commits into
NativeScript:masterfrom
vultix:css-gradients
May 3, 2018
Merged

SvetoslavTsenov merged 18 commits into
NativeScript:masterfrom
vultix:css-gradients

Conversation

@vultix

@vultix vultix commented Mar 13, 2018 •

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

No support for css gradients.

What is the new behavior?

Css properties background and background-gradient now support the CSS linear-gradient spec.
I.E.:

background: linear-gradient(to top, red, green, blue);
background: linear-gradient(20deg, red, green, blue);
background: linear-gradient(to bottom left, red 10%, green 40%, blue 90%);
background-image: /* Same as above */

Fixes #539

Note: this PR is dependent upon PR #116 on the tns-core-modules-widgets project. The changes will be breaking on android without this PR.

@ns-bot

ns-bot commented Mar 13, 2018

Copy link
Copy Markdown

Can one of the admins verify this patch?

2 similar comments
@ns-bot

ns-bot commented Mar 13, 2018

Copy link
Copy Markdown

Can one of the admins verify this patch?

@ns-bot

ns-bot commented Mar 13, 2018

Copy link
Copy Markdown

Can one of the admins verify this patch?

@pana-cc pana-cc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks great,
Just one thing, can you extend the background-image type, rather than introducing a new property. I think the CSS spec the linear-gradient radial-gradient etc. are part of the possible values for a background-image.

Otherwise looks great.
Thank you for your contribution, this was one of the things I really wanted to see implemented in {N}.

public background: string;
public backgroundColor: Color;
public backgroundImage: string;
public backgroundGradient: string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In the CSS spec the gradients (linear and radial) are set on the background image:
https://developer.mozilla.org/en-US/docs/Web/CSS/background-image
There is no background-gradient property.

return true;
}
}
export const backgroundGradientProperty = new CssProperty<Style, LinearGradient>({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, I think this should be extending the type of the background-image instead of introducing a new property.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've just committed this fix, could you give it another look?

@pana-cc pana-cc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good! :)
I wonder if the background-image should remain string or be promoted to string | LinearGradient, but either way I am ok with it.

@vakrilov

vakrilov commented Mar 15, 2018 •

Copy link
Copy Markdown
Contributor

Thanks @vultix - this is an awesome feature.

We are going to run our internal CI tests over this PR and do a code review in the following days so expect updates!

}
}


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is а tslint error caused by this line:
ERROR: tns-core-modules/ui/styling/linear-gradient.ts[61, 1]: Consecutive blank lines are forbidden

@vakrilov

Copy link
Copy Markdown
Contributor

test

@manoldonev

Copy link
Copy Markdown
Contributor

test branch_functional_tests#css-gradients-tests branch_widgets#vultix/css-gradients

1 similar comment
@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

test branch_functional_tests#css-gradients-tests branch_widgets#vultix/css-gradients

@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

Hey @vultix, thank you for your contribution and especially additional tests cases included in uitests app.
We have run some checks on our CI and it appears that there are some failures. I will give a short description of the problems we have encountered.

Android related issues:
Our tests are triggered mainly on api 19 and api 23

  1. Unit tests :
    === ALL TESTS COMPLETE ===I/JS ( 4364): 1486 OK, 45 failedI/JS ( 4364): DURATION: 116354.30 msI/JS ( 4364): === END OF TESTS ===E/JS ( 4364): Test: STYLE-PROPERTIES.test_setting_backgroundImage_property_from_CSS_is_applied_to_Style FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: STYLE-PROPERTIES.test_setting_backgroundImage_gradient_property_from_CSS_is_applied_to_Style FAILED: Setting property backgroundImage with CSS name background-image Actual: <[object Object]>(object). Expected: <linear-gradient(to top, red, blue)>(string)E/JS ( 4364): Test: VIEW.testBackgroundImage FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: VIEW.test_background_image_doesnt_throw FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: STYLE.test_css_dataURI_is_applied_to_backgroundImageSource FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: STYLE.test_css_is_applied_to_normal_properties FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: STYLE.test_css_is_applied_to_special_properties FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: STYLE.test_applies_css_changes_to_application_rules_before_page_load FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: STYLE.test_applies_css_changes_to_application_rules_after_page_load FAILED: Cannot read property 'match' of undefinedE/JS ( 4364): Test: STYLE.test_applies_css_changes_to_application_rules_after_page_load_new_views FAILED: Cannot read property 'match' of undefinedE/JS ( 4364)

2.UI tests agains uitest app. (background-shorthand example, background and etc) Most of the exception that we get there is "match of undefined in refreshBorderDrawable". This is the stack trace:
_ ### stackTrace: An uncaught Exception occurred on "main" thread.
03-27 09:24:51.186 5308 5308 I JS : com.tns.NativeScriptException:
03-27 09:24:51.186 5308 5308 I JS : Calling js method onCreateView failed
03-27 09:24:51.186 5308 5308 I JS :
03-27 09:24:51.186 5308 5308 I JS : TypeError: Cannot read property 'match' of undefined
03-27 09:24:51.186 5308 5308 I JS : File: "file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/styling/background.js, line: 118, column: 32
03-27 09:24:51.186 5308 5308 I JS :
03-27 09:24:51.186 5308 5308 I JS : StackTrace:
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'refreshBorderDrawable', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/styling/background.js', line: 118, column: 33
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'onBackgroundOrBorderPropertyChanged', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/styling/background.js', line: 55, column: 17
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'View._redrawNativeBackground', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 588, column: 29
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'View.(anonymous function)', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 568, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'applyAllNativeSetters', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js', line: 978, column: 37
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'initNativeView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/properties/properties.js', line: 905, column: 9
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.onResumeNativeUpdates', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 627, column: 22
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase._resumeNativeUpdates', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 272, column: 18
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.onLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 231, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'View.onLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 193, column: 35
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 311, column: 90
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.callFunctionWithSuper', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 304, column: 9
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.callLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 311, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.loadView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 439, column: 18
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 233, column: 19
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'LayoutBaseCommon.eachChildView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/layouts/layout-base-common.js', line: 125, column: 26
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewCommon.eachChild', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 857, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.onLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 232, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'View.onLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 193, column: 35
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 311, column: 90
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.callFunctionWithSuper', file:'file:///data/data/org.nativescript.apps/files/app/tns_modul
03-27 09:24:51.186 5308 5308 I JS : es/tns-core-modules/ui/core/view-base/view-base.js', line: 304, column: 9
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.callLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 311, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.loadView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 439, column: 18
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 233, column: 19
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ContentView.eachChildView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/content-view/content-view.js', line: 70, column: 13
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'PageBase.eachChildView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/page/page-common.js', line: 120, column: 40
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewCommon.eachChild', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view/view-common.js', line: 857, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.onLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 232, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'View.onLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view/view.js', line: 193, column: 35
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'Page.onLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/page/page.js', line: 43, column: 35
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 311, column: 90
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.callFunctionWithSuper', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 304, column: 9
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.callLoaded', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 311, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase.loadView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 439, column: 18
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase._addViewCore', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 434, column: 18
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'ViewBase._addView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/core/view-base/view-base.js', line: 420, column: 14
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'FragmentCallbacksImplementation.onCreateView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 576, column: 24
03-27 09:24:51.186 5308 5308 I JS : Frame: function:'FragmentClass.onCreateView', file:'file:///data/data/org.nativescript.apps/files/app/tns_modules/tns-core-modules/ui/frame/fragment.js', line: 27, column: 38

IOS related issues:
Tested on simulators iOS 11.2

  1. Unit tests:
    === ALL TESTS COMPLETE ===1540 OK, 1 failedDURATION: 48690.60 ms=== END OF TESTS ===2018-03-27 12:00:50.678250+0300 0x132881 Default 0x0 55651 tests: (NativeScript) CONSOLE ERROR file:///app/tns_modules/tns-core-modules/trace/trace.js:165:30: "Test: STYLE-PROPERTIES.test_setting_backgroundImage_gradient_property_from_CSS_is_applied_to_Style FAILED: Setting property backgroundImage with CSS name background-image Actual: <[object Object]>(object). Expected: <linear-gradient(to top, red, blue)>(string)"2018-03-27 12:00:50.678364+0300 0x132881 Default 0x0 55651 tests: (NativeScript) CONSOLE INFO file:///app/tns_modules/tns-core-modules/trace/trace.js:159:29: Test: Tests EOF!

Please let me know if you need some additional information.

@vultix

vultix commented Mar 27, 2018

Copy link
Copy Markdown
Contributor Author

@SvetoslavTsenov My apologies for those problems. I have been unable to run the test app on android due to a strange error.

That aside, I have found the problem causing "match of undefined in refreshBorderDrawable" and have pushed that fix in.

@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

That's ok! I will rerun tests.

@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

test branch_functional_tests#css-gradients-tests branch_widgets#vultix/css-gradients

@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

Hey @vultix, great job! All tests on our CI has passed successfully. I will try to cover few scenarios more and confirm new images that we are going to use for verification as soon as possible.

@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

test branch_functional_tests#css-gradients-tests branch_widgets#vultix/css-gradients

@ADjenkov

Copy link
Copy Markdown
Contributor

@vultix I've created a PR to your fork with:

  • New test app for backgroundImage with various linear gradients
  • Minor change in equals method to enable setting new gradient.

@ADjenkov
ADjenkov self-requested a review April 25, 2018 13:46
 chore(linear-gradient): fix equality comparer
@ADjenkov

ADjenkov commented May 2, 2018

Copy link
Copy Markdown
Contributor

@vultix could you rebase to master branch since there are some very minor changes?
Thanks!

@ghost ghost assigned ADjenkov May 3, 2018
@ADjenkov

ADjenkov commented May 3, 2018

Copy link
Copy Markdown
Contributor

test branch_functional_tests#css-gradients-tests branch_widgets#vultix/css-gradients

@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

test branch_widgets#vultix/css-gradients

@SvetoslavTsenov

Copy link
Copy Markdown
Contributor

Merging this PR, since the failures are related to the newly added UI test.

@SvetoslavTsenov
SvetoslavTsenov merged commit 5a83a1c into NativeScript:master May 3, 2018
@ghost ghost removed the in progress label May 3, 2018
@sitefinitysteve

Copy link
Copy Markdown
Contributor

Thanks for this one team!

ADjenkov added a commit that referenced this pull request May 3, 2018
@ADjenkov ADjenkov mentioned this pull request May 3, 2018
@jlooper

jlooper commented May 23, 2018

Copy link
Copy Markdown

This is awesome!! I'd be happy to send you a swag package in honor of this great PR! @vultix please email me with your t-shirt size if you'd like! jen.looper @ progress.com

contrib

@william-levi

Copy link
Copy Markdown

so, how to use this ? sorry for the noob question

@datanotion

Copy link
Copy Markdown

I'm getting an error similar to what was mentioned above: #5534 (comment)

"imageUri.match is not a function"

StackTrace: 
Frame: function:'refreshBorderDrawable', file:'file:///data/data/com.app.myapp/files/app/tns_modules/tns-core-modules/ui/styling/background.js', line: 99, column: 34

I just added a line of code from the examples to a panel:

background: linear-gradient(to top, red, green, blue);

I'll open an official ticket once I search around for a solution more.

@yamchi

yamchi commented Jun 1, 2018

Copy link
Copy Markdown

@datanotion yeah i also did that
background: linear-gradient(to top, red, green, blue);
but it's not working

@JillevdW

Copy link
Copy Markdown

For everyone looking for documentation on how to use the gradients, the link in the 4.1 release post is broken, this link works: https://docs.nativescript.org/cookbook/ui/styling#gradients

@tenluap

tenluap commented Jun 12, 2018

Copy link
Copy Markdown

css gradient not working ,
on nv(nativescript-vue)

@abhayastudios

Copy link
Copy Markdown
Contributor

@vultix Wow thanks a lot for this! I was wondering how difficult would it be to have the gradients work on the action bar as well?

@lock

lock Bot commented Aug 26, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked and limited conversation to collaborators Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More support for CSS gradients