Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native <Text> omits the last character

Whenever I put a string of more than 5 characters inside a element, the last one is not rendered. Here's my code and the outputted string.

const Header = () => {
    const { textStyles, viewStyles } = styles;

    return (
        <View style={viewStyles}>
            <Text style={textStyles}>Albums</Text>        
        </View>
    );
};

const styles = {
    viewStyles: {
        backgroundColor: '#F8F8F8',
        alignItems: 'center',
        justifyContent: 'center',
        height: 60,
        paddingTop: 15,
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        elevation: 2
    },
    textStyles: {
        fontSize: 20
    },
};

Outputted string: Album

If I change the string inside the Text element to something like 'Albums!', the output will be Albums. It always show n-1 characters.

like image 567
Nacho Perassi Avatar asked Jan 24 '18 18:01

Nacho Perassi


2 Answers

I tested your code buddy Its working fine

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

const Header = () => {
  const { textStyles, viewStyles } = styles;

  return (
      <View style={viewStyles}>
          <Text style={textStyles}>Albums!!!!</Text>
      </View>
  );
};
export default class App extends React.Component {

  render() {
    return (
      <View>
        <Header></Header>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  viewStyles: {
        backgroundColor: '#F8F8F8',
        alignItems: 'center',
        justifyContent: 'center',
        height: 60,
        paddingTop: 15,
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        elevation: 2
    },
    textStyles: {
        fontSize: 20
    },
});

Here is the output

enter image description here

like image 189
Purushotham Kumar Avatar answered Sep 30 '22 13:09

Purushotham Kumar


I experienced the same issue on my OnePlus 6. I fixed it by using textAlign: "center" instead of using alignItems: "center".

I propose changing your styles to:

const styles = {
    viewStyles: {
        backgroundColor: '#F8F8F8',
        justifyContent: 'center',
        height: 60,
        paddingTop: 15,
        shadowColor: '#000',
        shadowOffset: { width: 0, height: 2 },
        elevation: 2
    },
    textStyles: {
        fontSize: 20,
        textAlign: "center"
    },
};
like image 30
Simon Avatar answered Sep 30 '22 12:09

Simon