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.

alignItems: 'baseline' doesn't work

See original GitHub issue

Is this a bug report?

Yes.

Have you read the Contributing Guidelines?

Yes.

Environment

  1. react-native -v: 0.48.1
  2. node -v: v7.9.0
  3. npm -v: 5.4.1
  4. yarn --version: N/A

Then, specify:

  • Target Platform: iOS, Android

  • Development Operating System: macOS Sierra 10.12.5

  • Build tools: react-native run-ios react-native run-android

Steps to Reproduce

  1. Create a wrapper view with the styles: {flexDirection: 'row', alignItems:'baseline'}
  2. Within the wrapper view, create multiple text nodes with different fontSizes

Expected Behavior

The text nodes would be aligned along the baseline.

Actual Behavior

The text nodes are not aligned along the baseline. The alignment is indistinguishable from alignItems: 'flex-end' screen shot 2017-09-07 at 2 26 37 pm

Reproducible Demo

https://snack.expo.io/HkoJ_QkcZ

(T16975579)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
joechryslercommented, Oct 3, 2017

There is a workaround to this. If you wrap sibling <Text> nodes in a <Text> everything lines up nicely regardless of the parent <View>’s alignItems setting. https://snack.expo.io/BkR46Ub2b

10reactions
MrSeaWavecommented, Oct 26, 2018

@shergin on Android this bug still exists…, u can see it https://github.com/facebook/react-native/issues/21918#issue-373366382

react-native init AwesomeProject
cd AwesomeProject
react-native run-android

Environment

node v8.12.0
npm 6.4.1
react-native-cli: 2.0.1
react-native: 0.57.3

my package.json is

{
  "name": "TemReactNative",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.0-alpha.8af6728",
    "react-native": "0.57.3"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.48.1",
    "react-test-renderer": "16.6.0-alpha.8af6728"
  },
  "jest": {
    "preset": "react-native"
  }
}

the Code is

import React, { PureComponent } from 'react';
import { Text, View, StyleSheet } from 'react-native';

export default class TestTextBaseline extends PureComponent {
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.textContainer}>
          <Text style={{ fontSize: 65, backgroundColor: '#ff9c6e' }}>1</Text>
          <Text style={{ fontSize: 55, backgroundColor: '#ff9c6e' }}>1</Text>
          <Text style={{ fontSize: 45, backgroundColor: '#ff9c6e' }}>1</Text>
          <Text style={{ fontSize: 35, backgroundColor: '#ff9c6e' }}>1</Text>
          <Text style={{ fontSize: 25, backgroundColor: '#ff9c6e' }}>1</Text>
        </View>
      </View>
    );
  }
}

export const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  },
  textContainer: {
    justifyContent: 'center',
    flexDirection: 'row',
    alignItems: 'baseline'
  }
});

ios is correct

image

But android is wrong image

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS display:flex align-items:baseline not working in Firefox
my children elements align properly in Chrome and Safari but in Firefox they are aligned at the bottom and don't seems to have...
Read more >
align-items: baseline not working with nested flex containers.
Issues in Layout that do not fit into any other Layout component or which span multiple Layout components. Bugs related to the top...
Read more >
What's the deal with align-items: baseline? - Maxwell Antonucci
My site has shown that having varying text or elements around a baseline can create lots of empty space.
Read more >
align-items - CSS-Tricks
The align-items property is related to CSS layout. It effects how elements are aligned both in Flexbox and Grid layouts.
Read more >
align-items - CSS Reference
Learn how align-items works in CSS. ... align-items: baseline;. The flexbox items are aligned at the baseline of the cross axis.
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