question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextView] [CSS] text-transform support?

See original GitHub issue

Hey, Given recent updates to text-decoration implementation, I was wondering if this would’ve been in scope of React Native? I know we can pretty easily do this:

<Text>{'something'.toUpperCase()}</Text>

but having universal apps in mind, basic support for upperCase and lowerCase would be nice.

<Text style={{textTransform: 'uppercase'}}>something</Text>

Depending on how Text is rendered, either basic NSString bindings below might be used or plain JS methods:

  • capitalize - NSString -capitalizedString
  • uppercase - NSString -uppercaseString
  • lowercase - NSString -lowercaseString

If the answer to my question is Yes - I am happy to add in this in a PR.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:98
  • Comments:94 (10 by maintainers)

github_iconTop GitHub Comments

154reactions
mikefranciscommented, Sep 17, 2015

Just stumbled upon this thread from Google; I’d say that adding textTransform support is necessary to separate your concerns. As others have pointed out, you can do this in JS, however what’s the point in having a class full of styles and then having to use JS to force caps.

Say a couple of months down the line you don’t wish to use caps any more then you’ve got to trawl through your app removing all the references to it. Having this as a style would alleviate that problem.

96reactions
jonlongcommented, Dec 8, 2016

@brentvatne Just dropping in to echo @mikefrancis’s comments, which are right on the money in my experience.

Here’s a quick example from a project I’m working on. This is the same screen with two different design options — labels rendered in title case, or labels rendered in small caps.

texttransform

There’s two things that make a textTransform property attractive to me in this case. The first is that I think there’s a semantic difference between setting the actual content of <Text> to CITY rather than City. If preserving that semantic state is important, then I think this becomes a matter of style.

The second is to @mikefrancis’s points around separation of concerns and maintainability. If it’s a matter of style, then it makes sense to manage it with CSS.

Here’s a sample of the JSX for both of those views:

Title Case:

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label') }>Address Line 1</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label') }>Address Line 2</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label') }>City</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label') }>State</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label') }>Zipcode</Text>
</View>

And the same code modified for small caps:

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label.upper') }>{'Address Line 1'.toUpperCase()}</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label.upper') }>{'Address Line 2'.toUpperCase()}</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label.upper') }>{'City'.toUpperCase()}</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label.upper') }>{'State'.toUpperCase()}</Text>
</View>

<View { ...style('field') }>
  <TextInput
    { ...style('input') }
  />
  <Text { ...style('label.upper') }>{'Zipcode'.toUpperCase()}</Text>
</View>

In the second version, a simple design change requires a lot of updates to the template content itself. Even going the “Find and Replace” route would be pretty tricky.

I also find that in many scenarios, small caps tend to look better with a little bit of letterSpacing applied. In that case, I’d also end up modifying my styles too.

IMO, it’s a lot of overhead for a common use case, and something that could go from all this to a single line in a stylesheet with textTransform support.

Read more comments on GitHub >

github_iconTop Results From Across the Web

text-transform - CSS: Cascading Style Sheets - MDN Web Docs
The text-transform CSS property specifies how to capitalize an element's text. It can be used to make text appear in all-uppercase or ...
Read more >
How to set <Text> text to upper case in react native
Android textTransform support has been added in 0.59 version. It accepts one of these options: none; uppercase; lowercase; capitalize. The actual iOS commit, ......
Read more >
TextStyle should support Text Transformation (ex. all caps) for ...
Most UI Designer see text transformations like all caps as part of the styling but Compose does not. Currently TextStyle doesn't provide any...
Read more >
Text Style Props
Specifies font weight. The values 'normal' and 'bold' are supported for most fonts. Not all fonts have a variant for each of the...
Read more >
UI & Styling | NativeScript
NativeScript supports percentage values for width , height and margin . ... CSS property text-transform ) - Sets the text transform individually for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found