10 February 2020

Triangle shape example in react native

  • Create Components folder under src folder
  • Add TriangleShapeViewEXP1.js file and add below Code
import React from "react";
import { StyleSheetView } from "react-native";

const TriangleShapeViewEXP1 = () => {
  return (
    <View style={styles.container}>
      <View style={styles.TriangleShapeCSS} />
    </View>
  );
};
export default TriangleShapeViewEXP1;
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    margin: 10
  },
  TriangleShapeCSS: {
    width: 0,
    height: 0,
    borderLeftWidth: 60,
    borderRightWidth: 60,
    borderBottomWidth: 120,
    borderStyle: "solid",
    backgroundColor: "transparent",
    borderLeftColor: "transparent",
    borderRightColor: "transparent",
    borderBottomColor: "#FF0000"
  }
});
  • Open App.js file and update code as below


import React from 'react';
import { View,StyleSheet } from 'react-native';
import TriangleShapeViewEXP1 from './src/Component/TriangleShapeViewEXP1'

 const  App=()=> {
  return (
    <View style={styles.container}>
      <TriangleShapeViewEXP1/>
    </View>
  );
}
export default App;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    paddingTop:80
  },
});
Output:

No comments:

Post a Comment