Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border Radius not rounding corners in react native

I just started learning react native and am trying to write some practice programs, but for some reason I haven't been able to round the corners of a text element. I've been using borderRadius but that isn't working. Here is the entire code:

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

export default function App() {

function myButtonPressed(){
  Alert.alert("Logout")
}
  return (
    <View style={styles.container}>
      <Text style={styles.text}> Login </Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  text: {
    fontSize: 30,
    backgroundColor: "#BB2cd9",
    paddingVertical: 12,
    paddingHorizontal: 40,
    color: '#ffffff',
    borderRadius: 10

  }
});

Am I missing something that I need to import?

like image 569
tHatpart Avatar asked Jul 15 '26 02:07

tHatpart


2 Answers

You can use borderRadius: number with overflow: 'hidden', in any react UIComponent. i.e. <Text>,<View>,<Button> etc. style like:

render() {
return <View style = {{ height:100, width:100, backgroundColor: 'green', borderRadius: 10, overflow: 'hidden'}} ></View>
}  

Node: Takecare about overflow: 'hidden'

like image 80
Ravi Raja Jangid Avatar answered Jul 17 '26 18:07

Ravi Raja Jangid


Please apply borderRadiu sto the view component, Do checkout the code and working solution :

working solution

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';

// You can import from local files
import AssetExample from './components/AssetExample';

// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.paragraph}>
          Change code
        </Text>

      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
   marginTop:100,
   marginLeft:50,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
    height:50,
    width:200,
    borderRadius:20
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
    borderRadius:20
  },
});
like image 39
Gaurav Roy Avatar answered Jul 17 '26 19:07

Gaurav Roy