Sunday, May 12, 2019

React Native Create Custom Oval Shape View

This tutorial explains how to create custom oval shape view in react native application. Design & implementation of oval 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 Oval Shape View


React Native Create Custom Oval Shape View Example

Lets follow the below steps to Create Custom Oval 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}> Oval Shape </Text>
        <View style={styles.OvalShapeView} />
      </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"
  },   
  OvalShapeView: {    
    marginTop: 20,
    width: 150,
    height: 150,
    backgroundColor: '#FF9800',
    borderRadius: 120,
    transform: [{ scaleX: 2 }],
 },

});

Complete Source Code for App.js 

Lets see the complete source code that helps to Create Custom oval 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}> Oval Shape </Text>
        <View style={styles.OvalShapeView} />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#e5e5e5",
  },
  headerText: {
    fontSize: 20,
    textAlign: "center",
    margin: 10,
    fontWeight: "bold"
  },   
  OvalShapeView: {    
    marginTop: 20,
    width: 150,
    height: 150,
    backgroundColor: '#FF9800',
    borderRadius: 120,
    transform: [{ scaleX: 2 }],
 },

});

Screenshot : 

React Native Create Custom Oval Shape View

This is all about React Native Create Custom oval 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