Skip to content

[TextInput] Add auto-grow support for multiline TextInput components.#3097

Closed
dhrrgn wants to merge 9 commits into
react:masterfrom
dhrrgn:autoGrow
Closed

[TextInput] Add auto-grow support for multiline TextInput components.#3097
dhrrgn wants to merge 9 commits into
react:masterfrom
dhrrgn:autoGrow

Conversation

@dhrrgn

@dhrrgn dhrrgn commented Sep 28, 2015

Copy link
Copy Markdown
Contributor

This adds a new autoGrow property to the TextInput component, which automatically adjusts the height of the input depending on the height of the text. It respects the initial height of the input, and will never get smaller than that height.

I wasn't sure what the best property name would be. I think perhaps something like automaticallyAdjustHeight may be better (similar convention to automaticallyAdjustContentInsets on the ScrollView). I am open to suggestions here, and have no problem changing it.

Note: This is iOS only at the moment. I don't have the skill set currently to add this for Android.

Here is a GIF of it working in UIExplorer:

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Sep 28, 2015
@montogeek

Copy link
Copy Markdown

+1

@PhilippKrone

Copy link
Copy Markdown
Contributor

@dhrrgn I just applied your PR locally and it's basically working but there is quite some flickering in such a way that the textinput always becomes larger in height and then immediately smaller, although the height should not change in that situation at all. Do you have any idea why that happens?

UPDATE: This only happens if the textinput has one line (its changing its height between 20px (thats my standard) and 44,5px and back to 20px. Once the textinput has two lines, its working fine.

@dhrrgn

dhrrgn commented Sep 28, 2015

Copy link
Copy Markdown
Contributor Author

@PhilippKrone I actually just noticed that as well, I am looking into it. I believe it has to do with my last commit.

…xcess amount of frame updates, and caused a “flicker” issue, which caused the height to jump occasionally.
@dhrrgn

dhrrgn commented Sep 28, 2015

Copy link
Copy Markdown
Contributor Author

@PhilippKrone I have removed a portion of my last commit. It no longer handles resizing to fit the placeholder. This added a lot of overhead and other issues (which could probably be fixed TBH). Let me know how it works for you.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@dhrrgn updated the pull request.

@kinhunt

kinhunt commented Nov 14, 2015

Copy link
Copy Markdown

+1

@PhilippKrone

Copy link
Copy Markdown
Contributor

@ide Do you know who the right person for checking and importing this PR is?

@ide

ide commented Nov 18, 2015

Copy link
Copy Markdown
Contributor

cc @nicklockwood and @javache

That said multiline auto-growing text fields are hard to get right. Is this being used in products (ideally a messenger -- it's my go-to litmus test) somewhere so we can see if it's doing the right thing?

@dhrrgn

dhrrgn commented Nov 18, 2015

Copy link
Copy Markdown
Contributor Author

@ide We are using it in our app (in production). You can see it in action here: http://cl.ly/image/3x0c1u083F2S

The app is here: https://itunes.apple.com/app/id1043626975

@ide

ide commented Nov 18, 2015

Copy link
Copy Markdown
Contributor

@dhrrgn awesome -- checking it out right now!

@ide

ide commented Nov 18, 2015

Copy link
Copy Markdown
Contributor

@dhrrgn Gave your app a try and the text view is quite nicely done in my eyes.

Regarding your diff -- support for maxHeight landed in master (2244a86) and it'd be really nice to be able to use that style field instead of a separate prop -- do you think you could unify the APIs?

Also, could you verify this works with onLayout and add a little demo of that to the UIExplorer (perhaps printing the current height below the auto-sized text field as it shrinks and grows)?

@ide

ide commented Nov 18, 2015

Copy link
Copy Markdown
Contributor

cc @nicklockwood @javache you will probably want to take a look at this PR and #3209. The latter does text layout on the shadow thred which I lean towards, but is also much more complex.

@ide ide added the Platform: iOS iOS applications. label Nov 18, 2015
@nicklockwood

Copy link
Copy Markdown
Contributor

I like this, but can we do away with the "autoGrow" property and simple make auto-growing be the default behaviour if no explicit height is set? This should work well with the new minHeight and maxHeight props.

@dhrrgn

dhrrgn commented Nov 19, 2015

Copy link
Copy Markdown
Contributor Author

@nicklockwood Currently a TextInput can have no height set, but can have flex: 1 on it, which will stretch it, your proposed behaviour would conflict with the way that currently works...

I would gladly make this work with minHeight/maxHeight... as soon as I figure out how.......

@nicklockwood

Copy link
Copy Markdown
Contributor

@dhrrgn well, we could say that it has auto-growing height if neither height nor flex is set :-)

@christopherdro

Copy link
Copy Markdown
Contributor

@dhrrgn Any chance we can get this PR updated based on the comments, rebased to master and have the commits squashed down to 1?

I'm sure a lot of people, including me, would like to see this get merged in.

@eyaleizenberg

Copy link
Copy Markdown

@dhrrgn Any chance to get this merged?

P.S - Did anybody get this working on RN 0.17 ?

@dhrrgn

dhrrgn commented Jan 4, 2016

Copy link
Copy Markdown
Contributor Author

Sorry for the delay here, the holidays have been keeping me quite busy. I will be working on this over the next few days. Once everything is up to snuff, I will rebase and squash this all down to one commit.

@ahanriat

ahanriat commented Jan 4, 2016

Copy link
Copy Markdown
Contributor

@dhrrgn \o/

@ahanriat

Copy link
Copy Markdown
Contributor

@dhrrgn Any update ? :)

@nicklockwood

Copy link
Copy Markdown
Contributor

I tried merging this, but after resolving the conflicts it didn't seem to work. I'm guessing I screwed something up in the merge process, but the code in TextInput.js has diverged sufficiently to make it unclear what that might be.

I'd suggest holding off on any further work on this for the time being though. The new functionality added to RCTTextView since this was first suggested has opened up the possibility of implementing this as a pure JS solution, which I've got a working POC for. I'm just running it by the internal team for review.

@ahanriat

Copy link
Copy Markdown
Contributor

@nicklockwood thanks for the update !

@dhrrgn

dhrrgn commented Jan 21, 2016

Copy link
Copy Markdown
Contributor Author

@nicklockwood Ya, have been working on/off over the past week or so on this, as it basically requires a rewrite. However, if this can be done in pure JS, that would be a huge win.

@nicklockwood

Copy link
Copy Markdown
Contributor

Closing in favor of 481f560

@YasirSherzad

YasirSherzad commented Oct 14, 2017

Copy link
Copy Markdown

Hi, I am using 0.48 , I can see in Docs that there is autoGrow props in the TextInput for android, but its not working

<TextInput
         style={{backgroundColor: '#f0f1f1', 
               borderWidth:1, 
               borderColor:'#d0d2d3',
               paddingLeft:12,
               paddingRight:12,
               paddingTop:0,
               paddingBottom:0,
               marginBottom:12,
               fontSize: 14
            }}
         autoGrow = {true}
         multiline={true}
         placeholder='Bio'
         returnKeyType= 'next'
         underlineColorAndroid='transparent'
/>

@gabimoncha

Copy link
Copy Markdown

Hello, I am using version 0.56 and looks like autoGrow prop is not here anymore 👎 I believe this feature is a necessity and should not disappear

@yuvraj24

yuvraj24 commented Apr 7, 2020

Copy link
Copy Markdown

For auto-resizing of multiline TextInput use ,

flexGrow:1

Found this working on both iOS & Android devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Platform: iOS iOS applications.

Projects

None yet

Development

Successfully merging this pull request may close these issues.