Skip to content

feat(css-bkg-pos): Added possibility to declare background pos by single numeric value #7958

Merged
vmutafov merged 8 commits into
NativeScript:masterfrom
surdu:bkg-pos
Mar 24, 2020
Merged

feat(css-bkg-pos): Added possibility to declare background pos by single numeric value #7958
vmutafov merged 8 commits into
NativeScript:masterfrom
surdu:bkg-pos

Conversation

@surdu

@surdu surdu commented Oct 14, 2019

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

You can't declare a background-position attribute in CSS using only one numeric value:

background-position: 50%;
background-position: 50;
background-position: 0.5;

What is the new behavior?

Now you can declare background-position as above mentioned, and additionally in the following format:

background-position: <number|percent> bottom|center;

Implements #4201

@cla-bot cla-bot Bot added the cla: yes label Oct 14, 2019
@surdu surdu force-pushed the bkg-pos branch 2 times, most recently from 260d619 to 6899ff2 Compare October 22, 2019 15:33
@surdu surdu changed the title [DO NOT MERGE] feat(css-bkg-pos): Added possibility to declare background pos by single numeric value feat(css-bkg-pos): Added possibility to declare background pos by single numeric value Oct 25, 2019
@surdu

surdu commented Oct 25, 2019

Copy link
Copy Markdown
Contributor Author

I'm afraid I'm going to need a little bit of help with the tests for this PR: what I need to do is see if the drawing of the background Canvas/UIImage was done correctly, and I can't figure out how to achieve this. Other options would be to spy on some of the methods that draw the background, but that would not be possible on Android, where all the action happens on Android side in tns-core-module-widgets.

Could anybody please point me in the right direction on how to write tests for this? I tested this manually and all works great.

@vmutafov vmutafov left a comment

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.

I made some comments in the code. Generally speaking, it would be great to reuse code whenever possible and extract nested ifs into separate functions or additional classes in order to achieve better code design thus increasing readability and lowering the maintenance costs.

res.posX = spaceX;
}

if ("center".equals(vy.getString().toLowerCase(Locale.ENGLISH))) {

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.

Couldn't this logic be reused with the one below? This if introduces code duplication. Also, perhaps it's a good idea to extract pieces like vy.getString().toLowerCase(Locale.ENGLISH) into separate variables. This would increase readability, easier debugging and would not perform multiple method calls.

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'm afraid that without strong unit tests around this area, an important part of the parser could brake. I could write those unit tests, but as stated above, I would need some help with that 😞

Comment thread nativescript-core/ui/styling/background.ios.ts
@vmutafov vmutafov merged commit 1f04469 into NativeScript:master Mar 24, 2020
@surdu surdu deleted the bkg-pos branch March 25, 2020 08:18
NathanWalker pushed a commit that referenced this pull request Aug 7, 2020
…gle numeric value (#7958)

* feat(css-bkg-pos): Added possibility to declare background pos by single numeric value

* feat(css-bkg-pos): Implemented numeric bkg pos for iOS

* feat(css-bkg-pos): removed unnecessary code

Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
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