Skip to content

TextView Support For maxLines and minLines #4315

Closed

Description

@Ericky14

Does TextView have support for minLines and maxLines attributes? This would be a really useful feature for multi-line text.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Activity

  1. NickIliev commented on Jun 6, 2017

    @NickIliev
    Contributor

    Hey, @Ericky14 you can implement your logic for creating maxLines / minLines rules for your TextView.
    nativeScript allows you to work directly with the native APIs (Android and iOS) so you can extend the logic just as you would do in a native project.
    Behind TextView stands android.widget.EditText for Android and UITextView for iOS, that said we ca use some native techniques to limit the number of lines.
    e.g.

    let tv = <TextView>page.getViewById("tv");
    tv.text = "sample text";
    
    if (isAndroid) {
        let tvAndriod = tv.android;
        tvAndriod.inputType = "text";
        tvAndriod.maxLines = "3";
    } else if (isIOS) {
        tv.ios.textContainer.maximumNumberOfLines = 3;
        tv.ios.textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
    }
    
    tv.on("textChange", () => {
        if (isAndroid) {
            if (tv.android.getLayout().getLineCount() > 3) {
                tv.android.getText().delete(tv.android.getText().length() - 1, tv.android.getText().length());
            }
        }
    })
    

    Demonstration project can be found here.

    Thank you for your feature request - as a side note, I want to mention that NativeScript is open-source and everyone can become a contributor to the project. If you are interested in this option and you have a tested solution you can go through our contributing guide here.

  2. bhavincb commented on Jun 6, 2018

    @bhavincb

    hey @NickIliev ,i would like to implement this to nativescript. but i have some doubts. where can i address them?

  3. NickIliev commented on Jun 6, 2018

    @NickIliev
    Contributor

    @bhavincb this is what you need to create a PR - there is also a code convention guide included and development workflow. Create your PR with the codebase and test and the PR will be reviewed and if needed there will be a requests for changes.

    Of course, the best practice would be to discuss the possible code feature or changes here in this very same issue.

  4. bhavincb commented on Jun 6, 2018

    @bhavincb

    @NickIliev, i want to add maxLines for android we can directly implement it in TextBase because it uses android.widget.TextView. but for ios TextBase uses UITextField | UITextView | UILabel | UIButton out of which UITextField doesn't support more than one line.
    so my issue is where to write logic. is there any common approach available. or should i implement it in TextView, Label and Button separately.

  5. LeoDupont commented on Jul 10, 2018

    @LeoDupont

    @bhavincb, @NickIliev, do you have any news about this feature?

  6. bhavincb commented on Jul 10, 2018

    @bhavincb

    @LeoDupont for now you can use workaround provided by Nichlliev.

  7. codewithbjim commented on Aug 8, 2019

    @codewithbjim

    Is there any workaround for having a scrollable textview after a certain number of lines?
    I implemented @NickIliev workaround and it no longer accepts any input after reaching the maximum number of lines.

    And right now, max-height is not yet implemented which is the possible workaround for having a scrollable textview.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions