How to create text border in React Native?

CssReactjsReact Native

Css Problem Overview


In React-Native, how do I add font borders to Text-components?

I've tried using border and shadow{Color, Radius, Opacity, Offset}, but haven't gotten that to work. Any suggestions?

Css Solutions


Solution 1 - Css

The official docs have this information for you. You can find it on this site: Text Component. There it shows which props you can use to change the behaviour and style of the component. As you can see there are some specific Text styles but also the styles you can apply on a View Component. And if you follow that link it shows you the border styles. So, what you're looking for is maybe:

borderColor string
borderTopColor string
borderRightColor string
borderBottomColor string
borderLeftColor string
borderRadius number
borderTopLeftRadius number
borderTopRightRadius number
borderBottomLeftRadius number
borderBottomRightRadius number
borderStyle enum('solid', 'dotted', 'dashed')
borderWidth number
borderTopWidth number
borderRightWidth number
borderBottomWidth number
borderLeftWidth number

Solution 2 - Css

you can emulator border as two attributes :

textShadowColor color
textShadowOffset {width: number, height: number}

Ex:

textshadow:{
    fontSize:100,
    color:'#FFFFFF',
    fontFamily:'Times New Roman',
    paddingLeft:30,
    paddingRight:30,
    textShadowColor:'#585858',
    textShadowOffset:{width: 5, height: 5},
    textShadowRadius:10,
  },

Solution 3 - Css

You need to set borderColor and borderWidth.

Solution 4 - Css

Is currently not working for android. Try wrapping it within a view like this one:

<View
  style={{
    borderWidth: 1,
    borderColor: "thistle",
    borderRadius: 50,
  }}>
</View>

Solution 5 - Css

If you are looking for something similar to how CSS -webkit-text-stroke works, why not try react-native-svg?

import Svg, { Text } from "react-native-svg";

<Svg height="50%" width="50%" viewBox="0 0 100 100">
  <Text
    stroke="black"
    strokeWidth="1"
    fill="white"
    color="#ffffff"
    fontSize="45"
  >
    Yay!
  </Text>
</Svg>

Solution 6 - Css

As noted by KChen, you need to add both borderColor and borderWidth. Just updating this answer for later versions of ReactNative (note the usage of 'styles.bigblue').

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, ScrollView, Image, Text } from 'react-native';

export default class HelloWorldWithBorder extends Component {
        render() {
                return (
                                <ScrollView>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                <Text style={styles.bigblue}>HelloWorld WithBorder</Text>
                                </ScrollView>
                       );
        }
}


const styles = StyleSheet.create({
        bigblue: {
                color: 'blue',
                fontWeight: 'bold',
                fontSize: 20,
                borderColor: 'black',
                borderWidth: 1
        }
});

enter image description here

This was using a combination of the tutorial from Styles and ScrollView

Solution 7 - Css

I needed to add a bottom border to Text component like this:

enter image description here

I did the following:

the border is a <View/> inside another one with flexDirection : 'row'

here is my code:

<View style={styles.titleContainer}>
   <Text style={styles.title}>Horaire de prière</Text>
   <View style={styles.borderContainer}>
     <View style={styles.border} />
   </View>
</View>

and the style:

titleContainer: {
    flex: 0.2,
    alignItems:'center',
    justifyContent:'center'
    
  },
  title: {
    fontSize: 18,
    marginBottom:2,  
  },
  borderContainer:{
    flexDirection:'row',
    alignItems:'center',
    justifyContent:'center',
    
  },
  border:{
    flex:0.28,
    borderBottomWidth: 1,
    borderBottomColor: '#428947',

  },

you can modify border size with flex.

Solution 8 - Css

You need to at least set the borderWidth, it must be set to an integer. The default border color is black, you can change the color with borderColor

Solution 9 - Css

 paddingTop: 10,
 borderWidth: 1,
 borderColor: 'red'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhenkimonView Question on Stackoverflow
Solution 1 - CsswebweltenView Answer on Stackoverflow
Solution 2 - CssTrần Hồng ĐiệpView Answer on Stackoverflow
Solution 3 - CssKChenView Answer on Stackoverflow
Solution 4 - CsschinloongView Answer on Stackoverflow
Solution 5 - CsscodebreakerView Answer on Stackoverflow
Solution 6 - CssScott SkilesView Answer on Stackoverflow
Solution 7 - CssB. MohammadView Answer on Stackoverflow
Solution 8 - CssDustin SandersView Answer on Stackoverflow
Solution 9 - CssGURU PRASADView Answer on Stackoverflow