Monday, April 29, 2019

React Native Create Custom Square Shape View

This tutorial explains how to create custom rectangle and square shape view in react native application. Geometric Shape Square. The square is a geometric shape that belongs to the quadrilateral family because it has 4 sides. The 4 sides are the same length and are parallel to each other. Design & implementation of square shape is very easy and here we are going to use css stylesheet design for this. Lets follow the below steps and build more understanding.

React Native Create Custom Square Shape View

React Native Square Shape With Example :

Lets follow the below steps to Create Custom Square Shape design in React Native.

Step 1: Create a new react native project, if you don’t know how to create a new project in react native just follow this tutorial.

Step 2: Open App.js File in your favorite code editor and erase all code and follow this tutorial.

Step 3: Through react , react-native  packages import all required components.
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';

Step 4 : Implement render method inside the App class and wrapped the below layout design inside the root View component.
export default class App extends Component {

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.headerText}> Square Shape </Text>
        <View style={styles.SquareShape} />
      </View>
      );
  }
}

Step 5 : Apply the below style sheet design.
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#e5e5e5",
  },
  headerText: {
    fontSize: 20,
    textAlign: "center",
    margin: 10,
    fontWeight: "bold"
  },
  SquareShape: { 
    width: 120,
    height: 120,
    backgroundColor: '#FF9800' 
  },

});

Complete Source Code for App.js 

Lets see the complete source code that helps to Create Custom Square Shape design in react native application.

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


export default class App extends Component {

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.headerText}> Square Shape </Text>
        <View style={styles.SquareShape} />
      </View>
      );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#e5e5e5",
  },
  headerText: {
    fontSize: 20,
    textAlign: "center",
    margin: 10,
    fontWeight: "bold"
  },
  SquareShape: { 
    width: 120,
    height: 120,
    backgroundColor: '#FF9800' 
  },

});

Screenshot : 

React Native Create Custom Square Shape View
This is all about React Native Create Custom Square Shape design layout example. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.

No comments:

Post a Comment