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

[Android] TextView doesn't support letter spacing and padding #3233

Closed
xinthink opened this issue Oct 5, 2015 · 28 comments
Closed

[Android] TextView doesn't support letter spacing and padding #3233

xinthink opened this issue Oct 5, 2015 · 28 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@xinthink
Copy link
Contributor

xinthink commented Oct 5, 2015

  1. padding of a TextView is ineffective, the dimension seems right, but the content is not placed correctly
  2. the text (not the TextView) 'inherits' the background color, so it looks like there's an overlapped layer

2015-10-05 7_53_46

it should look like this:
2015-10-05 7 49 50

  • RN v0.11.4
  • Android 5.1.1

code:

    <Text style={{
        backgroundColor: 'rgba(100,230,100,.7)',
        padding: 25,
        color: 'white',
        fontWeight: 'bold',
      }}
      >
      Hello
    </Text>
@andreicoman11
Copy link
Contributor

Issue 2. has been fixed in 3b6d029
I think @kmagiera has more context for issue 1.

@PhilippKrone
Copy link
Contributor

@kmagiera Any idea what the reason for issue 1 could be?

@kmagiera
Copy link
Contributor

Have you tried this on iOS by any chance. This is related to the fact that padding is implemented in layout algorithm by shifting children of the element by the value of padding. It means that it won't work by default on non View components. It shouldn't be that difficult to implement it, so PRs are welcome!

also cc @vjeux who may know if we support this on Text elements on iOS

@PhilippKrone
Copy link
Contributor

@kmagiera It is supported on Text elements. See https://facebook.github.io/react-native/docs/text.html#content: Text has all properties of View, which again has the Flexbox properties, which includes padding :) It is working in iOS. I'm currently porting my app to android and found this issue as well, thats why I was asking for a solution in here.

@kmagiera
Copy link
Contributor

In that case this piece is missing on android. It shouldn't be that difficult to add. One would need to update ReactTextShafiwNode to calculate padding into the result of measure, then expose setters for padding props in ReactTextManager and forward it to the view with setPadding.

We do sth similar for EditText as far as I remember.

If this is blocking you, you may try wrapping Text component in a View with padding

@richarddewit
Copy link

Any news on this?

@patoroco
Copy link
Contributor

patoroco commented Nov 5, 2015

@richarddewit we're workaround padding issue wrapping Text in a View, and applying margin to it.

Margin seems to be work for both platforms.

@satya164
Copy link
Contributor

Any updates on this?

@xinthink
Copy link
Contributor Author

Tested on RN 0.17.0, the background issue is fixed, but the padding is still ineffective.

@satya164 satya164 changed the title [Android] TextView strange padding & backgroundColor behavior [Android] TextView doesn't support padding Feb 17, 2016
@kkgelu
Copy link

kkgelu commented Mar 3, 2016

You can't image how heart-breaking it was when I first fired up my 'fine tuned' iOS version on Android...

@liamzebedee
Copy link

Anyone against adding this to the Known Issues page?

@coderbit-net
Copy link

Have same issue with padding for android platform,
no problems with iOS in the same time! Any chances to get that fixed soon?

@coderbit-net
Copy link

The only "workaround" I found is to wrap into .

@satya164 satya164 changed the title [Android] TextView doesn't support padding [Android] TextView doesn't support letter spacing and padding Mar 20, 2016
@fab1an
Copy link

fab1an commented May 21, 2016

I think the only backwards compatible way to get proper tracking/letter-spacing on Android is using a wrapper like this, which inserts spaces between letters: http://stackoverflow.com/questions/1640659/how-to-adjust-text-kerning-in-android-textview/16429758#16429758

Please don't abuse textScaleX for it ;)

@GantMan
Copy link
Contributor

GantMan commented May 30, 2016

Anyone know if this is gonna happen? Padding sure would be nice.

@rburgst
Copy link

rburgst commented Jun 14, 2016

I would like to split this issue, since padding and letter spacing don't really have anything to do with each other. Padding should be easily fixable regardless of the letter spacing issue (which is much harder to fix).

@fab1an
Copy link

fab1an commented Jun 14, 2016

Actually letter-spacing could be trivially implemented with a component that splits the text by letters, creates a TextView for every letter and uses scaleX on the spaces only.

@rburgst
Copy link

rburgst commented Jun 14, 2016

Good luck implementing proper word wrapping with such an approach. At any rate, the solution for spacing will be probably quite different from the padding solution/fix.

@fab1an
Copy link

fab1an commented Jun 14, 2016

From a design point-of-view letter spacing ('tracking') is mainly used to make A L L C A P S headlines more readable.

@dbuarque
Copy link

+1

@mquandalle
Copy link
Contributor

I think point 1. was fixed in c3f2bba.

@maraujop
Copy link

For those interested there is a new PR that fixes letter spacing in Android #9420 /cc @rburgst

@irfanayaz89
Copy link

@patoroco @A1ex5andr @kmagiera Can any of you guys explain how to get letter spacing by wrapping text inside a view? a code snippet would be of great help. Thanks

@theodoregold
Copy link

Here is a workaround in the meanwhile.
http://stackoverflow.com/questions/38451278/letter-spacing-on-react-native-android

@dannycochran
Copy link
Contributor

#3233 (comment) helps with letter spacing but not padding.

the workaround for putting the element inside a , and applying padding to the doesn't work if the is already nested within other elements. any chance this is something that could be fixed in Android? @andreicoman11

@jerolimov
Copy link
Contributor

jerolimov commented Mar 29, 2017

Checkout my PR #13199

@hramos
Copy link
Contributor

hramos commented Jul 20, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@zeh
Copy link

zeh commented Mar 5, 2018

FWIW this is now being tracked as #17398 and waiting for review.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests