Skip to content

Conversation

dhrrgn
Copy link
Contributor

@dhrrgn dhrrgn commented Sep 28, 2015

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

+1

@PhilippKrone
Copy link
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
Copy link
Contributor Author

dhrrgn commented Sep 28, 2015

@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
Copy link
Contributor Author

dhrrgn commented Sep 28, 2015

@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
Contributor

@dhrrgn updated the pull request.

@kinhunt
Copy link

kinhunt commented Nov 14, 2015

+1

@PhilippKrone
Copy link
Contributor

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

@ide
Copy link
Contributor

ide commented Nov 18, 2015

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
Copy link
Contributor Author

dhrrgn commented Nov 18, 2015

@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
Copy link
Contributor

ide commented Nov 18, 2015

@dhrrgn awesome -- checking it out right now!

@ide
Copy link
Contributor

ide commented Nov 18, 2015

@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
Copy link
Contributor

ide commented Nov 18, 2015

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
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
Copy link
Contributor Author

dhrrgn commented Nov 19, 2015

@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
Contributor

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

@christopherdro
Copy link
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

@dhrrgn Any chance to get this merged?

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

@dhrrgn
Copy link
Contributor Author

dhrrgn commented Jan 4, 2016

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
Copy link
Contributor

ahanriat commented Jan 4, 2016

@dhrrgn \o/

@ahanriat
Copy link
Contributor

@dhrrgn Any update ? :)

@nicklockwood
Copy link
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
Contributor

@nicklockwood thanks for the update !

@dhrrgn
Copy link
Contributor Author

dhrrgn commented Jan 21, 2016

@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
Contributor

Closing in favor of 481f560

@YasirSherzad
Copy link

YasirSherzad commented Oct 14, 2017

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

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
Copy link

yuvraj24 commented Apr 7, 2020

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.