Skip to content

Feature request: css line-height #1664

Closed

Description

@lawrencetaur

I'd like the css line-height property implemented in {N}.

Why:

The current line height seems to be 100% and in a lot of websites i use, the line-height for text is 1.5 to 1.8.

I think this is how you do it on
Android
http://stackoverflow.com/questions/6863974/android-textview-padding-between-lines

and iOS
http://stackoverflow.com/questions/5494498/how-to-control-the-line-spacing-in-uilabel

That seems a bit complicated. So why there are many css properties in {N} i feel 'line-height' would be a great addition

Example:
This is how my app looks in Ionic
screenshot_20160228-174944

and in Nativescript
screenshot_20160228-174930

Activity

  1. vjoao commented on Feb 28, 2016

    @vjoao
    Contributor

    If you can't wait for this to be implemented I suggest you to do it by calling the native APIs (setLineSpacing on Android or follow this thread for iOS)

  2. burkeholland commented on Feb 29, 2016

    @burkeholland

    👍

  3. AntonioCuevaUrraco commented on May 13, 2016

    @AntonioCuevaUrraco

    For people that end up here before it is implemented, this is the manual way to do it.

    function labelLineHeight(nsLabel) {
    
        if(isIOS){
            var label= nsLabel.ios;
            var attributedString;
    
            if(label.atributedText){
                attributedString = label.atributedText;
            }
            else{
                attributedString=NSMutableAttributedString.alloc().initWithString(label.text);
            }
            var paragraphStyle = NSMutableParagraphStyle.alloc().init();
            paragraphStyle.lineSpacing = 5;
            var range= NSMakeRange(0, label.text.length);
            attributedString.addAttributeValueRange(NSParagraphStyleAttributeName, paragraphStyle, range);
            label.attributedText = attributedString;
        }
        if(isAndroid){
            var label = nsLabel.android;
            //Default spacing is 20% of text size
            //setLineSpacing(add,multiplyby);
            label.setLineSpacing(12, 1);
        }   
    }
  4. mikebranstein commented on Aug 16, 2016

    @mikebranstein

    @AntonioCuevaUrraco I'm using this approach on several static pages, and it works well.

    I occasionally run into an issue with labels that are data bound in iOS (I haven't tried on Android yet). It seems like I need to re-apply the paragraph style each time the text changes in the label. I don't know enough about iOS under the hood to be able to confirm this - does it sound right?

  5. AntonioCuevaUrraco commented on Aug 17, 2016

    @AntonioCuevaUrraco

    @mbektchiev NativeScript has their own label.ios.atributedText on the core modules to set the properties that are supported on the css. I am not 100% sure but I think you have to re-apply on text changed because the ns core is overriding the atributedText that you just changed with the "original" one.

  6. lukeramsden commented on May 9, 2017

    @lukeramsden

    This issue is a year old now and still not implemented. The code-behind workaround is good, but if your text is centered, then on iOS when you enter the view you can see it centered with the normal line-height, then left-aligned with the new line-height, then center-aligned with the new line-height - which really weird to the user.

    Any ETA for this?

  7. Acanguven commented on May 11, 2017

    @Acanguven

    I am looking for this too. It is a really useful feature.

  8. NickIliev commented on Jun 19, 2017

    @NickIliev
    Contributor

    +1 from t.1114872

  9. simonox commented on Jun 20, 2017

    @simonox

    +1

  10. Pinny3 commented on Jun 20, 2017

    @Pinny3

    Come on, this is one of a basic functionality that I expect from a framework which is based on CSS. So, when can I expect this?

    +1

  11. bitworking commented on Jun 29, 2017

    @bitworking

    Oh yes please. It's so hacky to change the line-height in "native" code. The other problem is that the UI is not refreshed after the change and the text is cutted because the container element doesn't change the height.

  12. 3 remaining items

  13. added
    ready for testTSC needs to test this and confirm against live production apps and automated test suites
    on Jul 13, 2017
  14. added this to the 3.1.1 milestone on Jul 13, 2017
  15. added and removed
    ready for testTSC needs to test this and confirm against live production apps and automated test suites
    on Aug 1, 2017
  16. removed their assignment
    on Aug 1, 2017
  17. mikebranstein commented on Aug 1, 2017

    @mikebranstein

    @EddyVerbruggen and other {N} team, thanks for the updates! We appreciate you all!

  18. added a commit that references this issue on Sep 27, 2017
  19. lock commented on Aug 28, 2019

    @lock

    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.

  20. locked and limited conversation to collaborators on Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions