Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of adjustsFontSizeToFit. #4026

Closed

Conversation

MattFoley
Copy link

No description provided.

@MattFoley
Copy link
Author

It had been way too long to fix it up myself, so I've reopened the PR. Here's the original. #2327

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @nicklockwood, @sahrens and @a2 to be potential reviewers.

@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 Nov 10, 2015
@MattFoley
Copy link
Author

This should be stable enough to merge now.

@MattFoley
Copy link
Author

Keeping this squashed on master led to a missed file. Corrected.

@facebook-github-bot
Copy link
Contributor

@MattFoley updated the pull request.

@MattFoley
Copy link
Author

@nicklockwood, @sahrens, @a2 Correct me if I'm wrong, but the tests failing after my last commit/squash are not due to my code changes, correct?

@brentvatne
Copy link
Collaborator

Cool :)

@nicklockwood
Copy link
Contributor

Did something go wrong with the merge/rebase?

The adjustsFontSizeToFit and minimumFontScale are defined on both RCTText and RCTShadowText, but the ones on RCTShadowText aren't used anywhere in the code, and the ones on RCTText aren't exported in RCTTextManager.

Also, you don't seem to have added the new props to Text.js or TextStylePropTypes.js

@MattFoley
Copy link
Author

I think that's just misunderstanding on my part, and the age of this PR. Let me remove them from RCTShadowText.

I was assuming that RCTTextManager just needed the two RCT_EXPORT_SHADOW_PROPERTY lines it has, is that not correct? Give me a bit and I will add them to Text.js and TextStylePropTypes.js.

@nicklockwood
Copy link
Contributor

RCT_EXPORT_SHADOW_PROPERTY exports properties on the shadow view. To export properties on the view you need RCT_EXPORT_VIEW_PROPERTY. I'm not sure how this could ever have worked in its current form.

@MattFoley
Copy link
Author

Miracle of science I suppose.

@MattFoley
Copy link
Author

Are you sure that RCT_EXPORT_VIEW_PROPERTY is correct in this instance? It's not used for RCTText at all. (I said project originally, I meant the RCTText class and related.)

@MattFoley
Copy link
Author

You know, I think I see part of what's missing. RCTText must be an odd case. From what I can tell, all properties of RCTText are exported as shadow properties, and then passed into RCTText from RCTShadowText via NSTextContainer, NSTextStorage, and NSLayoutManager. That being said, there were a few lines in RCTShadowText that have been squashed out. Updating now.

@facebook-github-bot
Copy link
Contributor

@MattFoley updated the pull request.

@nicklockwood
Copy link
Contributor

@MattFoley thanks, that makes more sense. Is there any reason that this resizing logic can't be implemented on the shadow view though? It seems like it only relies on the view frame, which is calculated on the shadow side.

The reason we have this thread architecture is because calculating text layout is fairly expensive, so we do it off the main thread. But it seems like we lose the benefit of that if we then re-calculate it on the main thread in order to do the size adjustment.

@MattFoley
Copy link
Author

That makes sense. I think I'm mainly doing it on the main thread now so that I knew the font was only modified after the frame was completely set for the view. I'm trying to move it out to the RCTextShadowView now without much luck yet.

@MattFoley
Copy link
Author

Ah, immediately after typing that I figured out what I was doing wrong. Give me a bit and I'll have this cleaned up and moved out to RCTShadowText.

@facebook-github-bot
Copy link
Contributor

@MattFoley updated the pull request.

@facebook-github-bot
Copy link
Contributor

@MattFoley updated the pull request.

@nicklockwood
Copy link
Contributor

This looks great, thanks!

@facebook-github-bot import

@MattFoley
Copy link
Author

I'm going to run some more in depth tests on this @nicklockwood with some of my own projects that are using this, just to make sure everything is solid on master. But yay! 🎉

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1504537549873434/int_phab to review.

added @platform iOS

Building UIExplorer Example, adding back in height error margin requirement, and add in RCTMeasure call.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 8, 2016
@MattFoley
Copy link
Author

Note, I had to update this PR to fix a failing test due to a previous rebase.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 9, 2016
@skevy
Copy link
Contributor

skevy commented Aug 10, 2016

@facebook-github-bot shipit

@skevy
Copy link
Contributor

skevy commented Aug 10, 2016

@MattFoley thank you SO much for sticking with this for so long. Sorry it took so long to get it merged!

@ghost ghost added GH Review: accepted Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: review-needed labels Aug 10, 2016
@ghost
Copy link

ghost commented Aug 10, 2016

Thanks for importing.If you are an FB employee go to Phabricator to review internal test results.

@ghost ghost added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 10, 2016
@marcshilling
Copy link

@skevy @MattFoley 👏👏👏👏

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 10, 2016
@ghost ghost closed this in c6b6f53 Aug 10, 2016
@MattFoley
Copy link
Author

@skevy Thanks!!!!!!!!!!!!!!!!!!!!!!!!

ps. @brentvatne it happened. 🎉

@collinglass
Copy link

👏👏👏

cmcewen pushed a commit to cmcewen/react-native that referenced this pull request Aug 15, 2016
Summary: Closes facebook#4026

Differential Revision: D2678492

Pulled By: nicklockwood

fbshipit-source-id: 0467814f810fee997ac50960ffb1daa74d52acba
mpretty-cyro pushed a commit to HomePass/react-native that referenced this pull request Aug 25, 2016
Summary: Closes facebook#4026

Differential Revision: D2678492

Pulled By: nicklockwood

fbshipit-source-id: 0467814f810fee997ac50960ffb1daa74d52acba
rozele pushed a commit to microsoft/react-native-windows that referenced this pull request Aug 25, 2016
Summary: Closes facebook/react-native#4026

Differential Revision: D2678492

Pulled By: nicklockwood

fbshipit-source-id: 0467814f810fee997ac50960ffb1daa74d52acba
@chandlervdw
Copy link

@MattFoley so, is this available in react-native@0.32 or no? Thanks so much for this!

@MattFoley
Copy link
Author

It's in .33rc I think, you're welcome!

Sent from my iPhone

On Sep 2, 2016, at 7:58 AM, Chandler Van De Water notifications@github.com wrote:

@MattFoley so, is this available in react-native@0.32 or no? Thanks so much for this!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

@pyankoff
Copy link

Text gets truncated a little bit (maybe because of large font?). Easily solved by adding style={{marginVertical: 6}} tho.

@jasan-s
Copy link

jasan-s commented Jun 14, 2017

can adjustsFontSizeToFit work with TextInput? On the user input

@garrettmac
Copy link

You can add adjustsFontSizeToFit={true} (currently undocumented) to you Text Component to auto adjust the size inside a parent node.

  <Text adjustsFontSizeToFit={true} numberOfLines={1}>Hiiiz</Text>

You can also add the following in your Text Component:

<Text style={{textAlignVertical: "center",textAlign: "center",}}>Hiiiz</Text>

Or you can add the following into the parent of the Text component:

<View style={{flex:1,justifyContent: "center",alignItems: "center"}}>
     <Text>Hiiiz</Text>
</View>

or both

 <View style={{flex:1,justifyContent: "center",alignItems: "center"}}>
     <Text style={{textAlignVertical: "center",textAlign: "center",}}>Hiiiz</Text>
</View>

or all three

 <View style={{flex:1,justifyContent: "center",alignItems: "center"}}>
     <Text adjustsFontSizeToFit={true} 
           numberOfLines={1} 
           style={{textAlignVertical: "center",textAlign: "center",}}>Hiiiz</Text>
</View>

before
screen shot 2017-07-19 at 9 48 05 am

after

screen shot 2017-07-19 at 9 47 34 am

It all depends on what you're doing. You can also checkout my full blog post on the topic

https://medium.com/@vygaio/how-to-auto-adjust-text-font-size-to-fit-into-a-nodes-width-in-react-native-9f7d1d68305b

@mkozhukharenko
Copy link

it does not work for Android in react 47.1 and does not work perfectly for IOS

@AfiyaA
Copy link

AfiyaA commented Nov 20, 2017

Does this work for Android? It works for me for IOS but need Android support as well.

@skv-headless
Copy link
Contributor

I should be doable for android https://react-native.canny.io/feature-requests/p/textandroid-autosizing-support. But I failed to implement it maybe someone more experienced with react-native can do it.

@cmacdonnacha
Copy link

Would be great to get this on Android too!

@yurykorzun
Copy link
Contributor

We desperately need this on Android

@cmacdonnacha
Copy link

I see this is closed, was it merged in?

This pull request was closed.
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. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.