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.

textAlignVertical: center not working

See original GitHub issue

Bug

I am trying to vertically align the text inside a Text component. I tried pretty much everything ( textAlignVertical: 'center', alignItems:'center', alignSelf: 'center',), but it still doesn’t work. Screenshot 2019-10-12 18 19 54

Environment info

React native info output:

System:
    OS: macOS 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Memory: 225.43 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.4.0 - /usr/local/bin/node
    Yarn: 1.16.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5900203
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.2 => 0.61.2
  npmGlobalPackages:
    react-native-cli: 2.0.1

Library version: 0.61.2

Steps To Reproduce

  1. create the componet
  2. set its style
  3. text inside doesn’t get vertically aligned

Describe what you expected to happen:

  1. text inside to be vertically aligned

Reproducible sample code

// code. pretty much most basic way of doing it
<Text style={styles.Initials}>HO</Text>

// css
Initials: {
        height: 64,
        width: 64,
        borderRadius: 32,
        color: 'white',
        fontWeight: '600',
        fontSize: 18,
        textAlign: 'center',
        textAlignVertical: 'center',
        alignItems:'center',
        alignSelf: 'center',
        backgroundColor: colors.colorPrimary,
        overflow: 'hidden'
    }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
thundertrickcommented, Jan 13, 2021

I fix it with following style:

{
    height: 30,
    textAlignVertical: 'center',
    ...Platform.select({
        ios: {
            lineHeight: 30 // as same as height
        },
        android: {}
    })
}

Hope it helps

5reactions
retyuicommented, Oct 20, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

"textAlignVertical" is not a valid style property - Stack Overflow
The textAlignVertical style is an Android-only property. If you are developing on iOS, try using the flexbox alignment property alignItems: ...
Read more >
textalignvertical not working in ios react native - Code Grepper
textalignvertical not working in ios react native ; 1. { ; 2. height: 30, ; 3. textAlignVertical: 'center', ; 4 ...Platform.select({ ; 5....
Read more >
Text Style Props - React Native
With some fonts, this padding can make text look slightly misaligned when centered vertically. For best results also set textAlignVertical to ...
Read more >
Bootstrap 4 Vertical Center - Medium
Getting elements to center align vertically has always been a challenge in CSS, ... Align” utilities would seem an obvious choice, but these...
Read more >
align attribute - BFO
"left", "right", "center", "justify" or "justify-all" · no · td, All block elements · justify · text-align vertical-align width ...
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